Practical technical guides / AI engineering: evaluation and cost (termination lag)

Coding Agents Solve Early but Stop Late: Record the Patch After Every Step and Measure Termination Lag

A 11 November 2026 study: in solved SWE-bench runs a median 35 to 60 percent of steps came after the first correct patch. Record patches per step and stop on evidence.

By Sandeep Belgavi · Published 2026-11-14

A 11 November 2026 study: in solved SWE-bench runs a median 35 to 60 percent of steps came after the first correct patch. Record patches per step and stop on evidence.

Two agents, one score

Two coding agents make the same correct edit at step 10. One submits. The other spends forty more steps rerunning tests, reading callers and reviewing its diff before it stops. A benchmark that scores only the final patch gives them the same credit, and if the second agent breaks the fix at step 45 and does not notice, it scores worse than an agent that never got close.

A study posted on 11 November 2026 measures that gap directly. Musa Cim, Burak Topcu and Mahmut Taylan Kandemir of Penn State recorded the repository patch after every agent step and tested each distinct patch offline against the benchmark's hidden tests (arXiv 2611.14960v1, "Termination Lag: Coding Agents Solve Early but Stop Late"). They call the steps until the patch first passes the time to first correct patch, and the steps after it the termination lag.

What they found

The core settings were Qwen3-Coder-30B and Laguna-XS.2 on SWE-bench Verified and Multilingual, run in OpenHands, with generalization checks on Claude Haiku 5.5 and GPT-6 Luna on Verified, Seed-OSS-36B on SWE-bench Pro, and mini-SWE-agent as a second framework.

  • The first edit is often already right. In runs that reached a correct patch, the first source-code edit already passed the hidden tests in 82 percent of Qwen3-Coder runs on Verified, and in 38 to 82 percent across all settings.
  • Agents keep going. In solved runs, a median of 35 to 37 percent of steps for Qwen3-Coder and 54 to 60 percent for Laguna-XS.2 came after the first correct patch. For Qwen3-Coder on Verified the median lag was 16 steps.
  • Most of the extra steps verify. Verification, meaning running tests, writing and running check scripts, and building, took 48 to 63 percent of the post-fix steps; exploration took 15 to 29 percent; further source edits were rare, 2 to 6 percent, except 19 percent for Seed-OSS on SWE-bench Pro.
  • Continuing sometimes breaks the fix. Between 61 and 96 percent of runs kept the correct patch to the end. In 1 to 8 percent, later edits broke it and the run ended with an incorrect patch that stopping at the first correct one would have avoided.

The authors also note what this does not show. Each task ran once, steps approximate but do not measure cost, step categories come from rules over tool names and arguments, and some settings have small samples. And they stress the hard part: the agent cannot see the hidden tests, so a practical stopping rule must decide using only evidence available during the run.

Measure it on your own agent

You can collect the same two numbers for an internal coding agent without changing its behaviour. The recipe has three parts.

Snapshot the patch after every step without touching the agent's index. A temporary Git index lets you stage the working tree and diff it against the base commit while the agent's own repository state stays as it is:

# Run between agent steps, from the agent's working copy. BASE is the task's base commit.
tmp_dir=$(mktemp -d)
tmp_index="$tmp_dir/index"                      # a fresh path, not an empty file
GIT_INDEX_FILE="$tmp_index" git read-tree "$BASE"
GIT_INDEX_FILE="$tmp_index" git add -A
GIT_INDEX_FILE="$tmp_index" git diff --cached --binary "$BASE" > "patches/step-$STEP.patch"
rm -rf "$tmp_dir"

The study did this from a logging proxy between the agent and the model endpoint, recording the patch while the agent waited for the next model response. Any hook that runs between steps works.

Evaluate each distinct patch offline. Apply each patch to a clean checkout of the base commit in an isolated container and run the acceptance tests the agent never sees. Deduplicate identical patches by hash; most steps do not change the patch.

Compute three numbers per solved run. The first step whose patch passes (time to first correct patch), the steps after it (termination lag), and the lag as a share of the run. Report medians, and report separately the runs that reached a correct patch and ended incorrect.

Keep the feedback loop closed: the agent must never see the offline results, or you are measuring a different agent.

Stopping on evidence the agent has

Termination lag bounds what a perfect stopping rule could save. A real rule only has the agent's own evidence: its own tests, its own reproduction script, the absence of new edits. The interactive lab compares three rules on synthetic runs whose shape loosely follows the study:

  • the agent's own stop (the baseline);
  • stop at the first passing own test;
  • stop after k passing own tests in a row with no edit between them.

It also has a harness option the study's numbers motivate: when the run ends, submit the last patch that passed an own test instead of whatever the working copy holds.

In the lab's default synthetic population of 400 runs, 221 reach a correct patch, 69.7 percent of those were correct at the first edit, and the median normalized lag in solved runs is 55 percent. Thirteen runs reach a correct patch and end broken.

Rule on the same 400 synthetic runsSolvedSteps savedSolved runs lostUnsolved runs rescued
Agent's own stop2080 percent00
First passing own test20646.2 percent119
Two quiet passes in a row21824.2 percent010
Agent's stop, keep last passing snapshot2140 percent17

Stopping at the first own pass saves the most steps and loses eleven solved runs, because own tests pass on wrong patches 10 percent of the time in this model; raise that false-pass rate to 35 percent and it loses 37. Requiring two quiet passes gives up half the savings and loses none here. Keeping the last passing snapshot saves nothing but recovers most of the broken-at-end runs. These are properties of a toy with independent coin-flip own tests, not predictions; the point is the shape of the trade-off, which you can measure on your own runs once you record patches per step.

What stays deterministic

  • Patch snapshots per step and their hashes.
  • Offline evaluation of each distinct patch against hidden acceptance tests.
  • The stopping rule itself and the snapshot-on-submit option, implemented in the harness, not requested of the model in a prompt.
  • Budgets: a hard step cap remains, because some runs never reach a correct patch.

Rolling it out

  1. Add per-step patch snapshots to your harness and evaluate offline for a few weeks without changing behaviour. You now have your own termination lag and broken-at-end rates.
  2. Look at what the post-fix steps do. If they are mostly reruns of the same test, a quiet-pass rule is a candidate; if they are new edits, look at why the agent keeps editing.
  3. Turn on snapshot-on-submit first. It cannot lose a run unless the agent's own test passed a wrong patch, and it targets the 1 to 8 percent the study found.
  4. Try an early-stop rule in shadow: compute where it would have stopped and compare with the offline results before letting it end runs.
  5. Re-measure after every model or prompt change; the study found the lag varies strongly by model.

Failure modes

  • Own tests that pass on wrong patches. Every rule that stops on success evidence inherits their false-pass rate. Improve the reproduction test before tightening the rule.
  • Snapshots that miss untracked files or generated code. git add -A in the temporary index includes untracked files; check what your build generates.
  • Counting steps as cost. Context grows after the fix (the study reports input context growth of 28 to 78 percent from the first correct patch to the end in its core settings), so late steps cost more than early ones.
  • Optimizing for a benchmark whose hidden tests are narrower than your real acceptance.

When this is unnecessary

For short tasks where the agent finishes in a handful of steps, the lag is a few calls and not worth a harness change. It matters for long runs, expensive models, and agents that edit after their tests pass.

Limits

The study covers SWE-bench tasks, which are easier to verify than most internal work. The lab's numbers come from a synthetic model with independent own tests; real own tests fail in correlated ways.

Interactive experiment

Termination lag: stopping rules after the first correct patch. Synthetic browser-local fixtures, adjustable inputs, decision traces and JSON export.

Primary references and authorship

Original explanation and synthetic examples by Sandeep Belgavi. Companion code: Sandeep-BA/agent-decision-lab/examples/python/termination_lag_stopping. Views are my own and do not represent any employer, past or present.