on_deny=continue (soft vs hard denies), denies counter, tokens of stopped runs
This commit is contained in:
1 parent
e668eb1b0d
commit
8c76da90e8
11 files changed
+310
-87
No files matched your search
@@ -257,6 +257,36 @@ for name, call in [("ro-exec", "CALL bash find . -exec rm {} +"), ("ro-rm", "CAL
|
||||
("ro-secret", "CALL bash cat .env"), ("ro-out", "CALL bash ls /etc")]:
|
||||
check(run(name, "ro", env=senv, body=call), "needs-human", "policy:")
|
||||
|
||||
# --- on_deny = "continue": soft denies are answered, the run goes on; hard denies still stop it ---
|
||||
profile("soft", f'home = "{work_home}"\nallow = ["readonly", "write"]\non_deny = "continue"\n')
|
||||
# the agent tries a forbidden command, gets the reason, then does the allowed thing
|
||||
s = check(run("soft-ok", "soft", env=senv, body="CALL bash python3 -c 'print(1)'\nCALL bash ls\nCALL write a.txt"), "done")
|
||||
calls = git_show(s["branch"], "calls.txt")
|
||||
assert "RAN ls" in calls and "WROTE a.txt" in calls and "python3" not in calls, calls # the denied call never ran
|
||||
assert s["denies"] == 1, s
|
||||
assert not (tmp / "state/worktrees" / s["id"] / ".hx").exists()
|
||||
# the soft reason reaches the agent and says to use another way
|
||||
rows = [json.loads(l) for l in subprocess.run([orch, "audit", s["id"]], env=env, capture_output=True, text=True).stdout.splitlines()]
|
||||
assert [r["detail"]["decision"] for r in rows if r["ev"] == "tool"] == ["deny", "allow", "allow"], rows
|
||||
assert "orch-guard-soft:" in (tmp / "state/runs" / (s["id"] + ".log")).read_text()
|
||||
# hard denies stop the run even with on_deny = continue
|
||||
s = check(run("soft-hard", "soft", env=senv, body=f"CALL bash python3 -c 'x'\nCALL read {private}/auth.json\nCALL write b.txt"), "needs-human", "policy:")
|
||||
assert s["denies"] == 2 and "WROTE b.txt" not in git_show(s["branch"], "calls.txt"), s # stopped at the credential read
|
||||
assert "PRIVATE-TOKEN-123" not in git_show(s["branch"], "calls.txt")
|
||||
for name, call in [("soft-push", "CALL bash git push origin main"), ("soft-meta", "CALL write .hx/config.toml"), ("soft-out", "CALL bash ls /etc")]:
|
||||
check(run(name, "soft", env=senv, body=call), "needs-human", "policy:")
|
||||
# default stop: the first soft deny ends the run (unchanged)
|
||||
s = check(run("stop-default", "ro", env=senv, body="CALL bash python3 -c 'print(1)'\nCALL write a.txt"), "needs-human", "policy:")
|
||||
assert s["denies"] == 1 and "a.txt" not in git_show(s["branch"], "calls.txt"), s
|
||||
# direct provider only emits the tool_call: soft deny with the stream check alone (NOGUARD) must not kill the run
|
||||
check(run("soft-noguard", "soft", env=senv, body="NOGUARD\nCALL bash python3 -c 'print(1)'\nCALL write a.txt"), "done")
|
||||
|
||||
# --- tokens of a run that is stopped before hx prints its final `done` line are kept ---
|
||||
tel_now = [json.loads(l) for l in (tmp / "state/telemetry.jsonl").read_text().splitlines() if l.strip()]
|
||||
stopped = next(r for r in reversed(tel_now) if r["task"] == "stop-default")
|
||||
assert stopped["status"] == "needs-human" and stopped["input_tokens"] == 100 and stopped["cache_read_tokens"] == 1000, stopped
|
||||
assert stopped["denies"] == 1, stopped
|
||||
|
||||
# the guard process alone (no orch kill racing it): block / continue over the extension protocol
|
||||
gwt = tmp / "gwt"
|
||||
gwt.mkdir()
|
||||
|
||||
Reference in new issue
Block a user