Harness Engineering · ~7 min
An agent will tell you it's done. The harness's job is to not believe it — and to make "done" mean a deterministic check passed.
Models skew positive on their own work. Practitioners report agents that claim a fix for code they never changed and insist tests pass when the transcript shows failures. A checkpoint that reads the agent's self-report is not a checkpoint. Anchor "is it done?" to deterministic signals.
The fix for premature completion is a single rule the harness enforces: passing tests are the gate, not
the agent's say-so. Anthropic's long-running coding harness makes this explicit in the prompt and the loop —
a feature is not "done" until its tests pass, and the agent reads git log + a progress file before it's
allowed to move on.
git diff, build exit codes, test output — and cross-reference every claim against it. The signal must be
more reliable than the thing it's checking; compilers and tests qualify, an unconstrained model judging itself does not.
You already met the mechanism in Lesson 03. A Stop hook fires when the agent tries to end its turn —
the exact moment it wants to declare completion. Exit code 2 blocks the stop and feeds the reason
back, sending the agent back to work instead of letting it finish on red.
This is the harness saying "you don't get to call it done while the suite is red," deterministically, every time.
The same shape works as a CI gate on the PR and as a SubagentStop gate on delegated work.
One big gate at the finish line is too late. An agent that writes 500 lines before any check may have made a wrong assumption at line 10 — everything after is built on it, and unwinding the cascade is expensive.
So layer the gates: a fast per-edit check (PostToolUse lint/typecheck), a per-feature completion gate
(Stop + tests), and a CI gate on the PR. Each catches what the previous missed.
Unit too small: checking after every line suppresses exploration. Weak verifier: an LLM-judge that hallucinates rejects correct work and blesses wrong work — the gate must be stronger than the generator. Latency drag: if every iteration waits on a multi-minute matrix, agents batch fixes into huge unreviewable diffs. Keep pre-commit checks fast; move the heavy matrix to the merge gate.
Stop hook that exits 2 on red sends the agent back to work.git diff, exit codes, test output; ignore "I fixed it."Retrieval practice — recall, don't peek
Question 1A reliable completion gate anchors "done" to…
Question 2A Stop hook that exits 2 when tests fail will…
Question 3Verifying at each step beats verifying at the end because…
Question 4For a verification gate to work, the verifier must be…
Question 5 · spaced recall from Lesson 05On OverEager-Bench, the biggest driver of overeager actions was…
Stop-hook gate wired to your test command, or how to
layer a fast PostToolUse typecheck under a slower CI matrix? Next in Part 3: Long-Running Agents
— keeping state and recovering across sessions that outlive a context window.