Done, But Still Working: Anytime Evaluation of When Coding Agents Should Stop

Zerui Yang, Quan Xue, Miaomiao Dong, Chaorui Zhang, Xuanyu Zheng, Xiyuan Wang, Haolin Ruan, Xueyan Niu, Guangcheng Song, Weixi Zhang, Wei Han, Bo BaiarXiv 2026 · arXiv

TL;DR

Coding agents often continue working long after they've found a correct solution, wasting significant inference budget on redundant tests and "cleanup" steps. This paper introduces anytime evaluation—a method to score every intermediate step of an agent's run—revealing that simple stopping rules can slash inference costs by up to 57% while maintaining most of the patch quality.

What Problem Does This Paper Address?

When an AI coding agent (like those used in the SWE-bench benchmark) tackles a software issue, it follows a loop: search the repo, edit files, and run tests. A common observation is that these agents often keep working even after their own tests pass. They might run more edge-case tests, perform "cleanup," or further revise the code.

This raises a critical efficiency question: Does this extra work actually improve the final patch?

Standard benchmarks only evaluate the final output of a run. This creates a blind spot—we don't know if the agent had a correct solution 50 steps ago and then just spent the next hour (and hundreds of dollars in tokens) doing nothing useful or, worse, breaking the fix. The authors aim to quantify this "overthinking" and find ways to stop agents as soon as they are "done."

Methods

The authors propose a framework called Anytime Evaluation. Instead of just looking at the end result, they "open the hood" of the agent's trajectory:

  1. Record and Replay: They record every command an agent issues during a run.
  2. Intermediate Scoring: They replay these trajectories in an executable sandbox, extracting the code patch after every single command.
  3. Hidden Testing: Every unique intermediate patch is evaluated against "hidden tests" (the ground-truth tests from the benchmark that the agent never sees).
  4. Cost-to-Step Alignment: They calculate the exact cumulative token cost incurred up to each command.

By doing this, they can simulate different stopping rules offline. For example, they compare "running to the end" against a "First Pass" rule (stop as soon as the agent's own tests pass) and a "Twice Passed" rule (stop only if the same patch passes tests twice in a row).

Finally, they explore Stop Distillation: fine-tuning the models (using LoRA) to learn these stopping behaviors natively, so the agent can decide to submit and exit on its own.

Figure 2: Anytime evaluation turns recorded commands into a patch-and-cost record. We recover intermediate patch states, score distinct patches with hidden tests offline, and align their scores with cumulative costs. The illustrative ledger contains four observations of two patches: repeated states reuse a score while cost continues to accumulate. Hidden-test results never enter the agent’s input; interventions that change its behavior require new runs.

Datasets

The study primarily uses SWE-bench Verified, a subset of the popular software engineering benchmark where tasks are human-verified to be solvable.

  • Core Tasks: Focused on the Django and SymPy repositories.
  • Extended Evaluation: To ensure diversity, the authors built custom environments for 7 additional repositories: pytest, Sphinx, xarray, pylint, requests, seaborn, and Flask.
  • Models: They evaluated eight open-weights models, primarily from the Qwen family (e.g., Qwen3.6-27B, Qwen3.8-27B) but also including DeepSeek-V4-Flash, Gemma-4, and GLM-4.

Key Insights and Ideas

  • The "Hindsight" Saving is Massive: For some model-scaffold combinations, up to 57% of the total cost is spent after the agent has already generated a patch that passes the hidden tests.
  • Stopping is a Quality-Cost Trade-off: While stopping early saves money, it isn't free. Some agents use the extra time to fix subtle bugs that their initial tests missed. However, for other models like DeepSeek-V4-Flash, stopping early actually improves quality because the agent's later "cleanup" steps frequently break the working fix.
  • The "Twice Passed" Sweet Spot: Requiring an agent to pass its tests twice on the same patch before stopping acts as a powerful filter against "flaky" or lucky passes, recovering 68–77% of the potential hindsight savings in many cases.
  • Agents Don't Know They're Done: Simply asking an agent "Are you done?" at the first passing test rarely works. The models often ignore the prompt or confidently say "no" even when they've already solved the problem. Native fine-tuning (distillation) is much more effective at teaching them to stop.
Stopping saves cost, but its effect on patch quality depends on the agent.

Key Results

  • Cost Reduction: The "Twice Passed" rule saved 22.8% in inference costs in a preregistered replication, with a minor drop in "resolution" (benchmark score) of about 1.0 percentage point.
  • Distillation Success: Fine-tuning Qwen3.6-27B to imitate the stopping rule resulted in a 30% cost saving on unseen tasks.
  • Evaluation Efficiency: The authors showed that their "paired" anytime evaluation is significantly more statistically powerful than standard benchmark runs. Detecting a 2-point change in performance would require ~1,200 standard online runs but only 56 offline anytime evaluations.

Limitations and Future Work

  • Quality Uncertainty: While the cost savings are robust, the authors could not statistically prove "non-inferiority"—meaning there is still a risk that stopping early slightly degrades the quality of the patches compared to letting the agent finish.
  • Model Scope: The study focused on open-weights models. Frontier models (like GPT-4o or Claude 3.5 Sonnet) or "reasoning" models (like OpenAI's o1) might exhibit different overthinking behaviors.
  • Test Reliability: A passing "self-test" is a noisy signal; hidden tests still failed in roughly 30% of the cases where the agent's own tests passed.
  • Future Directions: The authors suggest developing better "learned monitors" that can more accurately predict patch correctness without relying on the agent's own (often incomplete) test suite.

Summary updated

Abstract

Coding agents often continue working after their own tests pass. Does this additional work improve the patch, and how much could be saved by stopping earlier? We study these questions through anytime evaluation: replaying recorded runs, scoring intermediate patches with hidden tests, and measuring the cost incurred at each step. For policies that only stop a run or select an earlier patch, this allows paired comparisons without generating new trajectories, provided replay preserves the relevant states. Across about 6,000 runs of eight open models in two scaffolds on SWE-bench Verified, we find substantial differences in the value of continued work. The hindsight saving available at passing self-tests ranges from under 1% to 57%, depending on the model and scaffold. A rule that stops after the same patch passes twice saves 23% in a preregistered replication, but the preregistered quality test does not establish non-inferiority. We explain these differences by measuring how often a rule fires, how often the patch changes afterwards, and whether those changes repair or break it. Fine-tuning agents to imitate the rule saves 30% over six seeds, while quality preservation remains uncertain. Our results help identify both the opportunities and the risks of early stopping.
BibTeX
@misc{yang2026done,
  author = {Zerui Yang and Quan Xue and Miaomiao Dong and Chaorui Zhang and Xuanyu Zheng and Xiyuan Wang and Haolin Ruan and Xueyan Niu and Guangcheng Song and Weixi Zhang and Wei Han and Bo Bai},
  title = {{Done, But Still Working: Anytime Evaluation of When Coding Agents Should Stop}},
  year = {2026},
  eprint = {2611.22901},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.22901},
}
Figure