O2: gate retry with failure log, needs-human (closes #3)
This commit is contained in:
1 parent
fb434c670c
commit
5f27fa69eb
4 files changed
+127
-41
No files matched your search
+18
-2
@@ -25,6 +25,9 @@ for i in range(int(body.split("TURNS=")[1].split()[0]) if "TURNS=" in body else
|
||||
e({"type": "turn_start"})
|
||||
e({"type": "stream", "event": {"type": "done", "usage": {"input_tokens": 100, "output_tokens": 50}}})
|
||||
if "WRITE" in body: open("out.txt", "w").write("x")
|
||||
if "--session" in sys.argv:
|
||||
open("retry-prompt.txt", "w").write(body)
|
||||
if "RETRYFIX" in os.environ.get("MODE", "RETRYFIX"): open("out.txt", "w").write("x")
|
||||
e({"type": "done", "error": "boom" if "FAIL" in body else None, "usage": {"input_tokens": 100, "output_tokens": 50}, "session": "/s.jsonl"})
|
||||
''')
|
||||
|
||||
@@ -55,11 +58,24 @@ def check(p, st, reason=None):
|
||||
return s
|
||||
|
||||
|
||||
profile("p", 'gate = "test -f out.txt"\n')
|
||||
profile("p", 'gate = "test -f out.txt || { echo MARKER-GATE-OUT; exit 3; }"\n')
|
||||
s = check(run("ok", body="WRITE"), "done")
|
||||
assert s["gate_exit"] == 0 and s["input_tokens"] == 100 and s["session"] == "/s.jsonl", s
|
||||
assert "out.txt" in subprocess.run(["git", "ls-tree", "--name-only", s["branch"]], cwd=repo, capture_output=True, text=True).stdout
|
||||
check(run("nowrite", body="x"), "failed", "gate-failed")
|
||||
s = check(run("nowrite", body="NEVERFIX", env={"MODE": "NEVER"}), "needs-human", "gate-failed")
|
||||
assert s["attempts"] == 3 and s["gate_exit"] != 0, s # 1 + 2 retries
|
||||
assert "MARKER-GATE-OUT" in (tmp / "state/runs" / (s["id"] + ".gate.log")).read_text()
|
||||
profile("r", 'gate = "test -f out.txt || { echo MARKER-GATE-OUT; exit 3; }"\nmax_retries = 1\n')
|
||||
s = check(run("fixes", "r", body="x"), "done")
|
||||
assert s["attempts"] == 2 and s["gate_exit"] == 0 and s["reason"] is None, s
|
||||
sent = subprocess.run(["git", "show", s["branch"] + ":retry-prompt.txt"], cwd=repo, capture_output=True, text=True).stdout
|
||||
assert "MARKER-GATE-OUT" in sent and "exit 3" in sent, sent # failure log reached hx on the resumed session
|
||||
profile("z", 'gate = "false"\nmax_retries = 0\n')
|
||||
s = check(run("noretry", "z", body="x"), "needs-human")
|
||||
assert s["attempts"] == 1, s
|
||||
profile("b", 'gate = "false"\nmax_retries = 2\n[budget]\nmax_turns = 2\n')
|
||||
s = check(run("budget-across", "b", body="x"), "failed", "budget:turns") # budget spans attempts
|
||||
assert (s["attempts"], s["turns"]) == (3, 3), s # 1 turn per attempt; 3rd turn exceeds 2
|
||||
check(run("hxerr", body="FAIL WRITE"), "failed", "hx-failed: boom")
|
||||
check(run("nojson", body="NOJSON"), "failed", "hx-failed")
|
||||
|
||||
|
||||
Reference in new issue
Block a user