graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
eval(tier2): expected_exit + stderr_contains; the fatal path gets its first case
justrach83dd7845beb6
diff --git a/docs/tier2-eval-design.md b/docs/tier2-eval-design.mdindex 4178636d..84d47b4a 100644--- a/docs/tier2-eval-design.md+++ b/docs/tier2-eval-design.md@@ -132,7 +132,15 @@ for rel, content in case.get("workspace_seed", {}).items():dest.write_text(content, encoding="utf-8")```-2. **expected_exit + stderr_contains** (merges `exit_code_is`, `stderr_contains_and_exit_code`, `exit_code_and_stderr_asserts`, `expected_exit` — some form was proposed by all five dimensions, the strongest convergence signal in the batch). Unlocks the entire exhaustedFatal (#368) path — today any deliberate nonzero exit is auto-failed by the mandatory check, so the fatal path is untestable — plus the `[workflow] phase N/M … SKIPPED (when …)` console lines and CLI-refusal locks. Sketch — new `evaluate()` arm plus a change to the mandatory block in `main()`:+2. **expected_exit + stderr_contains** — **LANDED** (merges `exit_code_is`, `stderr_contains_and_exit_code`, `exit_code_and_stderr_asserts`, `expected_exit` — some form was proposed by all five dimensions, the strongest convergence signal in the batch). Unlocks the entire exhaustedFatal (#368) path — before it, any deliberate nonzero exit was auto-failed by the mandatory check, so the fatal path was untestable — plus the `[workflow] phase N/M … SKIPPED (when …)` console lines and CLI-refusal locks. Shipped exactly as sketched, and `budget-exhausted-past-the-landing-dies-fatal` came with it (suite 38 → 39), proven red on the pre-extension runner (`unknown assertion 'stderr_contains'` ×4 + `graff exited 1`) and green after.++ Three facts the case had to be built around, all worth keeping:++ - **exhaustedFatal is one-shot only.** `run_budget.exhaustedFatal` is called from exactly one place — `session_run.runOneshotPrompt`'s error switch. In the runner's usual stdin/`--json` shape the same `error.RunBudgetExhausted` lands in `mainloop`'s `else` arm, which emits `{"type":"error","message":"RunBudgetExhausted"}` and exits **0**. So a fatal-path case must put `-p <prompt>` in its `args`; its `prompt` field then only feeds the stdin one-shot ignores.+ - **The #390 landing reserve does not make root-level exhaustion unreachable.** The reserve buys the run one tools-free final call with the `[budget landing]` note; it cannot stop a model from answering that call with a tool call anyway, and executing that tool demands a call the pool refuses. No subagent/depth>0 structure is needed — a script that keeps calling tools past the cap is enough (`--max-model-calls 2`, exit **1**).+ - **The exhausted row has no post-mortem surface yet.** With `GRAFF_FLEET=on` and a workflow call, exhaustedFatal's `flushPending(0, max, 0, true, "")` really does file `kind:"orch_outcome" … "score":0,"exhausted":true,"landed":false` (verified by hand against a kept workspace). It is written *as the process dies*, after any scripted bash step could observe it, and `execute()` discards the tempdir — so the case exercises that half without asserting it. It becomes assertable when extension #3 (`trajectory_row`) lands.++ Sketch as shipped — new `evaluate()` arm plus a change to the mandatory block in `main()`:```pythonelif kind == "stderr_contains":if spec not in run.stderr:diff --git a/evals/harness_behavior.jsonl b/evals/harness_behavior.jsonlindex 217fa61c..a6308a74 100644--- a/evals/harness_behavior.jsonl+++ b/evals/harness_behavior.jsonl@@ -36,3 +36,4 @@{"id": "orch-explicit-and-foreign-stratum-never-fold", "why": "#290 fold side, both firewalls at once: seeded R2 rows that would win the cell outright are marked source:\"explicit\" (user intent) or carry stratum gpt-5.6-sol (different model), so neither may fold into the (bugfix, unlimited, lmstudio) ask - the decision must stay bootstrap R0. Relabeling the explicit rows bootstrap flips it to a learned R2 fleet (verified), so each firewall is individually load-bearing. A scripted seed-presence probe keeps this case loudly RED until the workspace_seed runner extension exists - without it an empty archive declines identically and the case would otherwise pass while guarding nothing; once the seed lands it locks both firewalls.", "args": [], "env": {"GRAFF_FLEET": "on"}, "workspace_seed": {".graff/trajectories/seed.jsonl": "{\"kind\": \"orch_outcome\", \"task_class\": \"bugfix\", \"budget_band\": \"unlimited\", \"stratum\": \"lmstudio\", \"arm\": \"R0\", \"source\": \"bootstrap\", \"score\": 0.0, \"calls_used\": 6, \"exhausted\": false, \"landed\": false, \"variant_free\": true}\n{\"kind\": \"orch_outcome\", \"task_class\": \"bugfix\", \"budget_band\": \"unlimited\", \"stratum\": \"lmstudio\", \"arm\": \"R0\", \"source\": \"bootstrap\", \"score\": 0.0, \"calls_used\": 7, \"exhausted\": false, \"landed\": false, \"variant_free\": true}\n{\"kind\": \"orch_outcome\", \"task_class\": \"bugfix\", \"budget_band\": \"unlimited\", \"stratum\": \"lmstudio\", \"arm\": \"R0\", \"source\": \"bootstrap\", \"score\": 0.0, \"calls_used\": 8, \"exhausted\": false, \"landed\": false, \"variant_free\": true}\n{\"kind\": \"orch_outcome\", \"task_class\": \"bugfix\", \"budget_band\": \"unlimited\", \"stratum\": \"lmstudio\", \"arm\": \"R2\", \"source\": \"explicit\", \"score\": 1.0, \"calls_used\": 12, \"exhausted\": false, \"landed\": true, \"variant_free\": true}\n{\"kind\": \"orch_outcome\", \"task_class\": \"bugfix\", \"budget_band\": \"unlimited\", \"stratum\": \"lmstudio\", \"arm\": \"R2\", \"source\": \"explicit\", \"score\": 1.0, \"calls_used\": 13, \"exhausted\": false, \"landed\": true, \"variant_free\": true}\n{\"kind\": \"orch_outcome\", \"task_class\": \"bugfix\", \"budget_band\": \"unlimited\", \"stratum\": \"lmstudio\", \"arm\": \"R2\", \"source\": \"explicit\", \"score\": 1.0, \"calls_used\": 14, \"exhausted\": false, \"landed\": true, \"variant_free\": true}\n{\"kind\": \"orch_outcome\", \"task_class\": \"bugfix\", \"budget_band\": \"unlimited\", \"stratum\": \"gpt-5.6-sol\", \"arm\": \"R2\", \"source\": \"bootstrap\", \"score\": 1.0, \"calls_used\": 12, \"exhausted\": false, \"landed\": true, \"variant_free\": true}\n{\"kind\": \"orch_outcome\", \"task_class\": \"bugfix\", \"budget_band\": \"unlimited\", \"stratum\": \"gpt-5.6-sol\", \"arm\": \"R2\", \"source\": \"bootstrap\", \"score\": 1.0, \"calls_used\": 13, \"exhausted\": false, \"landed\": true, \"variant_free\": true}\n{\"kind\": \"orch_outcome\", \"task_class\": \"bugfix\", \"budget_band\": \"unlimited\", \"stratum\": \"gpt-5.6-sol\", \"arm\": \"R2\", \"source\": \"bootstrap\", \"score\": 1.0, \"calls_used\": 14, \"exhausted\": false, \"landed\": true, \"variant_free\": true}\n"}, "timeout_s": 90, "prompt": "fix the crash in payments.py", "script": [{"tool": "workflow", "arguments": {"phases": [{"title": "find the defect", "tasks": [{"description": "find", "prompt": "read payments.py and locate the crash"}]}, {"title": "implement the fix", "tasks": [{"description": "fix", "prompt": "fix the crash in payments.py"}]}]}}, {"tool": "bash", "arguments": {"command": "test -s .graff/trajectories/seed.jsonl && echo seed-present"}}, {"tool": "bash", "arguments": {"command": "grep -h '\"kind\":\"orch\"' .graff/trajectories/*.jsonl | grep '\"task_class\":\"bugfix\"' | grep '\"source\":\"bootstrap\"' | grep -q '\"arm\":\"R0\"' && echo firewalled-rows-did-not-fold"}}, {"text": "user intent and foreign strata stayed out of the cell"}], "assert": [{"event": {"type": "tool_result", "name": "workflow", "is_error": false}}, {"request_contains": {"index": 1, "text": "(escalation R0):"}}, {"event": {"type": "tool_result", "name": "bash", "text": "seed-present\n"}}, {"event": {"type": "tool_result", "name": "bash", "text": "firewalled-rows-did-not-fold\n"}}, {"final_text_contains": "stayed out of the cell"}]}{"id": "citation-free-report-not-rejected", "why": "The false-positive axis of anchorCheck: a report-slot worker that honestly cites nothing must pass in one call - no anchor rejection, no burnt phase retry. The scan once counted the harness's own appended inspect link (.graff/subagents/<id>.md) as a fabricated citation, auto-rejecting every citation-free report; this locks the fix (report_anchors.scan skips .graff/ paths).", "args": [], "prompt": "investigate whether any throttle wiring exists in this project", "script": [{"tool": "workflow", "arguments": {"phases": [{"title": "sweep the project for throttle wiring", "tasks": [{"description": "scout", "prompt": "search for throttle wiring and report what exists"}]}]}}, {"text": "No throttle wiring exists anywhere in this project; there is nothing to cite."}, {"text": "confirmed: no throttle wiring exists"}], "timeout_s": 90, "assert": [{"event": {"type": "tool_result", "name": "workflow", "is_error": false}}, {"events_at_most": {"match": {"type": "agent_usage"}, "count": 1}}, {"request_lacks": {"index": 2, "text": "Anchor every finding to real code"}}, {"request_contains": {"index": -1, "text": "1/1 ok, 0 retried"}}, {"final_text_contains": "confirmed: no throttle wiring exists"}]}{"id": "orch-landed-turn-files-outcome-row", "why": "The landed-turn funnel: before it, flushPending fired only from the eval funnel and exhaustedFatal, so the learned rung policy never saw an ordinary success - blind to exactly the outcome it optimizes (a rung that lands within budget). A no-eval turn that admits a workflow decision must file its kind:\"orch_outcome\" row when the turn lands, so the next boot's fold has evidence from everyday runs, not just scored ones and deaths.", "env": {"GRAFF_FLEET": "on"}, "prompt": "fix the bug in stats.py", "script": [{"tool": "workflow", "arguments": {"phases": [{"title": "find the defect", "tasks": [{"description": "find", "prompt": "read stats.py and locate the defect"}]}, {"title": "implement the fix", "tasks": [{"description": "fix", "prompt": "fix the defect in stats.py"}]}]}}, {"text": "declined solo - fixed it myself"}, {"tool": "bash", "arguments": {"command": "grep -h '\"kind\":\"orch_outcome\"' .graff/trajectories/*.jsonl | grep '\"arm\":\"R0\"' | grep -q '\"source\":\"bootstrap\"' && echo outcome-row-filed"}}, {"text": "the learning layer recorded the landing"}], "second_prompt": "did the learning layer record that?", "assert": [{"event": {"type": "tool_result", "name": "workflow", "is_error": false}}, {"request_contains": {"index": 1, "text": "(escalation R0):"}}, {"event": {"type": "tool_result", "name": "bash", "text": "outcome-row-filed\n"}}, {"final_text_contains": "recorded the landing"}]}+{"id": "budget-exhausted-past-the-landing-dies-fatal", "why": "#368 exhaustedFatal, the harness's own last words - and the FIRST case that can exist at all, since the runner auto-failed every nonzero exit until expected_exit landed. The #390 landing reserve buys the run ONE tools-free final call; it cannot stop a model that answers that call with a tool call anyway, and executing that tool demands a call the pool cannot admit. A one-shot (-p) run must then die LOUDLY: exit 1 with the harness naming what ran out, that the work is PARTIAL and was NOT rolled back, and where the trace is - never the bare 'turn failed: RunBudgetExhausted' that #368 replaced, and never a silent exit 0. The asserts pin the whole ordering: request 1 carries the full toolset, request 2 IS the landing call (note present, tools gone), and only PAST it does the run die. NOTE (-p): one-shot sets root.out = null, so the --json event stream is empty and no event/final_text assert is expressible here; the same exhaustion inside the stdin/mainloop shape is non-fatal by design (an error event, exit 0), which is why this case must be one-shot. GRAFF_FLEET=on plus the workflow call makes the run carry a real orchestration decision, so exhaustedFatal's other half fires too - it files the score-0 exhausted:true orch_outcome row before dying (verified by hand in the workspace: kind:\"orch_outcome\" ... \"exhausted\":true,\"landed\":false). That row is NOT asserted: it is written as the process dies, after every scripted bash step could run, and the runner keeps no post-mortem surface - it becomes assertable when the trajectory_row extension lands.", "args": ["--max-model-calls", "2", "-p", "fix the failing checks in parser.py"], "env": {"GRAFF_FLEET": "on"}, "expected_exit": 1, "timeout_s": 90, "prompt": "fix the failing checks in parser.py", "script": [{"tool": "workflow", "arguments": {"phases": [{"title": "find the defect", "tasks": [{"description": "find", "prompt": "read parser.py and locate the failing check"}]}]}}, {"tool": "todo_read", "arguments": {}}, {"tool": "todo_read", "arguments": {}}, {"text": "never reached: the pool was dry two calls ago"}], "assert": [{"request_contains": {"index": 0, "text": "\"todo_write\""}}, {"request_lacks": {"index": 0, "text": "[budget landing]"}}, {"request_contains": {"index": -1, "text": "[budget landing]"}}, {"request_lacks": {"index": -1, "text": "\"todo_write\""}}, {"stderr_contains": "model-call budget exhausted"}, {"stderr_contains": "(--max-model-calls 2)"}, {"stderr_contains": "Work done so far is PARTIAL and was NOT rolled back"}, {"stderr_contains": "raise --max-model-calls or re-run to continue"}]}diff --git a/scripts/eval-tier2.py b/scripts/eval-tier2.pyindex 31db46c2..dc363437 100644--- a/scripts/eval-tier2.py+++ b/scripts/eval-tier2.py@@ -27,6 +27,14 @@ Assertions a case can make:{"request_contains": {"index": -1, "text": "..."}} what the harness sent{"request_lacks": {"index": -1, "text": "..."}}{"final_text_contains": "..."}+ {"stderr_contains": "..."} what the harness printed to stderr++A case that deliberately DIES declares the exit code it wants with+{"expected_exit": N} (default 0). Without it the runner auto-failed every+nonzero exit, which made the harness's own fatal paths untestable - the+loudest of them being run_budget.exhaustedFatal (#368), the last line a+one-shot run prints when the model-call pool runs dry. A timeout is never+an expected exit and always fails.A case may also carry {"workspace_seed": {"relative/path": "content", ...}}:files written into the fresh workspace BEFORE graff boots, in scripted and@@ -208,6 +216,12 @@ def evaluate(case: dict[str, Any], run: Run, live: bool = False) -> list[str]:elif kind == "final_text_contains":if spec not in run.final_text():failures.append(f"the final answer was {run.final_text()!r}, wanted {spec!r}")+ elif kind == "stderr_contains":+ # The harness's own last words. stdout carries the event stream, so+ # anything the harness says on the way out - a fatal line, a phase+ # SKIPPED note, a CLI refusal - is only visible here.+ if spec not in run.stderr:+ failures.append(f"stderr never mentioned {spec!r}")else:failures.append(f"unknown assertion {kind!r}")return failures@@ -262,19 +276,23 @@ def main() -> None:# A harness that crashed, hung, or died instantly must FAIL the case on# its own, not merely annotate someone else's failure. Without this a# case whose assertions are all upper bounds passes against a binary- # that never ran at all.- if run.exit_code not in (0, None):- problems.append(f"graff exited {run.exit_code}")- elif run.exit_code is None:+ # that never ran at all. The default is still 0; a case that means to+ # exercise a fatal path names its code with "expected_exit", which is+ # the only way the harness's own deliberate deaths become testable.+ # A timeout is never expected - it is the absence of a decision.+ want = case.get("expected_exit", 0)+ if run.exit_code is None:problems.append("graff did not exit (timed out)")+ elif run.exit_code != want:+ problems.append(f"graff exited {run.exit_code}, wanted {want}")if problems:failed.append(case["id"])print(f" FAIL {case['id']}")print(f" guards: {case['why']}")for problem in problems:print(f" - {problem}")- if run.exit_code not in (0, None):- print(f" graff exited {run.exit_code}; stderr tail:")+ if run.exit_code not in (want, None):+ print(f" graff exited {run.exit_code} (wanted {want}); stderr tail:")print(" " + run.stderr.strip().splitlines()[-1] if run.stderr.strip() else "")else:print(f" pass {case['id']}")