Agent Harnesses Explained
← /learn · 08

Failure and recovery

Tools fail: retries with back-off, errors fed back to the model, and loop detection, with the success rate against the retry budget from seeded runs.

Check yourself ↓ three questions and what to remember, at the end

Loading the animation…

Concept

Tools fail. A network call times out, a test runner crashes, a file is locked. A harness decides what happens next, at three levels:

  1. Retry the same call, after a wait that grows each time (exponential back-off: here 500 ms, then 1 s, then 2 s), up to a retry budget. The model never sees a failure that a retry fixed.
  2. When the budget is spent, feed the error back to the model as the tool's result, and let it decide. The scripted model here does what models often do: it tries the same call again.
  3. Detect loops: three identical calls in a row are not progress. The harness either stops the run or nudges the model with a message telling it to try something else.

Seed 0, with no retries, shows the failure: the shell fails twice in a row, the model asks for the same pytest a third time, and loop detection stops the run after 5.04 s, with the bug unfixed. One retry is not enough for this seed either. With two, the retries absorb every failure and the run finishes in 13.5 s after 3 retries: slower than a lucky run, because waiting is the price of a retry.

Now set the budget to 0 and choose nudge. The run "finishes": the nudge moves the model on, it edits the file, the last test run fails again, and the model reports that all the tests pass. The run's status is done; the tests never passed. A harness that counts "the model said it was done" as success will report this run as a success. Counting only runs whose last test run passed tells the truth, and that is what the chart below does.

Success against the retry budget (100 seeded runs per bar)
  • finished
  • finished with the tests passing

On a loop: stop the run

RetriesFinished / with passing testsMean time
0 retries
79%
79%
7.55 s
1 retry
97%
97%
8.35 s
2 retries
100%
100%
8.6 s
3 retries
100%
100%
8.71 s
4 retries
100%
100%
8.81 s

On a loop: nudge the model

RetriesFinished / with passing testsMean time
0 retries
100%
90%
8.34 s
1 retry
100%
100%
8.5 s
2 retries
100%
100%
8.6 s
3 retries
100%
100%
8.71 s
4 retries
100%
100%
8.81 s

Right-hand column: the mean simulated run time. Every run is the scripted fix-the-test task with the shell failing 30% of attempts; the failure rate and the timings are illustrative.

Over 100 seeded runs per budget, with the shell failing 30% of attempts: with no retries, 79% of runs finish; one retry lifts that to 97%, and two to 100%. With nudges instead of stops, 100% of the no-retry runs finish, but only 90% with their tests passing. Past two retries, a bigger budget buys nothing here and costs time: the mean run takes 8.6 s with two retries and 8.81 s with four.

Maths

If each attempt fails independently with probability pp, a call with a budget of rr retries fails only when all r+1r+1 attempts do:

Pcall=1−p r+1,P_{\text{call}} = 1 - p^{\,r+1},

so with pp = 0.3, one call succeeds with probability 0.7, 0.91 and 0.973 for 0, 1 and 2 retries. A run is a chain of calls: here the model repeats a failed test run, and loop detection allows two identical calls in a row, so a test step is lost only when two calls in a row fail, with probability q2q^2 where q=p r+1q = p^{\,r+1}. The task has two test steps:

Prun=(1−q2)2,P_{\text{run}} = (1 - q^2)^2 ,

which predicts 83%, 98% and 100%; the 100 seeded runs measured 79%, 97% and 100%, within sampling error (about ±4 points at 100 runs). The price is time: the waits before retry kk are bfkb f^{k}, so a call that uses its whole budget waits Twait=b (fr−1)/(f−1)T_{\text{wait}} = b\,(f^{r}-1)/(f-1), here 1.5 s for two retries and 7.5 s for four, on top of the failed attempts themselves.

Code

The retry loop, cut from the vendored engine (harness.ts):

if (this.fault(name)) {
  if (attempt < rec.retries) {
    const backoff = rec.backoff_ms * rec.backoff_factor ** attempt;
    attempt += 1;

The success test the chart uses (sweeps.ts): finished, and the last test run passed.

return events[events.length - 1]!.status === "done" && lastOk;

Recovery in the public harnesses

HarnessRecovery and limits (from their docs, accessed 2026-10-07)
SWE-agentmax_requeries (default 3): "Maximum number of times to requery the model after an error, such as a formatting error, a blocked action, or a bash syntax error" (agent configuration)
mini-SWE-agenta cost limit ($3 by default) and a step limit (0, unlimited, by default) (the mini command)
Aiderafter an edit it lints (and, with --auto-test, tests), and "aider will try and fix any errors if the command returns a non-zero exit code" (linting and testing)

Check yourself

Commit to an answer before you reveal it: a wrong guess you can explain teaches more than a right one you skimmed. Every number in the answers comes from the same tested model as the chapter’s.

Q1Each attempt fails with probability 0.3. With a budget of 2 retries, what is the chance one call succeeds? (to three decimals)
Reveal the answer

Answer: 0.973 (counted right within 1%)

It fails only if all three attempts fail: 1−0.331 - 0.3^3. Each retry multiplies the failure probability by pp again.

The retry maths →

Commit to a number, then reveal.

Q2With no retries and nudges instead of stops, every run 'finishes'. What share of the 100 runs end with their tests passing?
Reveal the answer

Answer: 90% (counted right within 10%)

Fewer than finish: the nudge moves the model on, and some runs end with a failing test and a claim that all is well. Count only runs whose last test passed, not runs the model said were done.

The seeded sweep →

Commit to a number, then reveal.

Q3Back-off starts at 500 ms and doubles. How long does a call that uses a budget of 4 retries wait in all, in seconds?
Reveal the answer

Answer: 7.5 s (counted right within 10%)

b(fr−1)/(f−1)b(f^r - 1)/(f - 1) = 500 ms × (16 − 1): the waits double each time, so the last one is as long as all the others together. Past two retries, a bigger budget bought this task nothing.

The retry maths →

Commit to a number, then reveal.