Retrying an agent after failure can complete more tasks while increasing the cost per completion. We study a static policy that stops at verified success or an attempt cap and otherwise resets the original prompt and workspace without passing feedback to the next request. Under stationary task success probabilities, independent attempts conditional on the task, and a common attempt cost, easier tasks tend to succeed earlier. When task success probabilities differ, the unresolved mix shifts toward harder tasks. Specializing classical survivor selection, we show that cost per completion is at least as high as in one-shot serving and that marginal cost per additional completion is nondecreasing wherever the completion increments are positive. These are different quantities: one averages spending over all completions, while the other prices the completions added by another attempt. We then arrange each task's existing benchmark runs in different orders, stop each sequence at verified success or the attempt cap, and average the resulting completion and spending at each supported cap. For one OpenHands configuration, replay estimates completion of 59.7 percent with one attempt and 70.0 percent with four, while cost per completion rises from about USD 0.70 to USD 1.32. The recorded trade-off describes fixed configurations on the available tasks. Choosing a cap requires comparing the additional spending with the application's value for the additional completions.
Figures & tables
Figure 1. Static retries and their measurement. (a) Success stops the service; failure permits another attempt on the same task through cap K . (b) The equal-weight easy/hard mixture and the homogeneous population have the same one-shot success rate. Displayed mixtures and ratios use stationary success probabilities, conditional independence, and constant attempt cost. (c) Averaging stopped orders of recorded outcome-cost pairs gives completion Q , stopped spend B , cost per completion E , and the ratio R to one-shot serving. Three panels show the stop-on-success retry rule, the changing unresolved task mix in a heterogeneous example alongside a homogeneous control, and the calculation from repeated recorded runs.
Quantity
One attempt
Up to four attempts
Completion
59.7%
70.0%
Cost per completion
$0.70
$1.32
Table 1. Recorded-run replay for one OpenHands configuration on 500 tasks.
Quantity
Question answered
Q(K)
What share of incoming tasks completes within the cap?
B(K)
How much does the stopped service spend per incoming task?
E(K)
How much does it spend per completion?
R(K)
How does cost per completion compare with one-shot serving?
Mr
What does attempt r cost per completion that it adds?
Table 2. Retry quantities and the questions they answer.
Figure 2. OpenHands, n=500 incoming tasks. Left: completion Q(K) (%) and stopped spend B(K) (recorded USD/task); segments join adjacent discrete caps. Right: marginal cost Mr (USD/additional completion). Point estimates; no uncertainty intervals. The completion axis is focused. M1=E(1) is the one-shot cost per completion. Marginal costs are calculated from unrounded estimates. The first panel marks completion and stopped spending at each of the four OpenHands retry caps. The second marks the corresponding marginal cost per additional completion at each attempt.
Panel
Tasks
Configs.
Cost ratio ( R4 )
95% interval
Primary
500
12
1.7731
[1.7096, 1.8476]
τ2
164
4
1.2365
[1.1500, 1.3309]
OpenHands
500
1
1.9036
[1.7860, 2.0232]
Table 3. Cost per completion at four attempts relative to one.
Figure 3. All 12 primary configurations, n=500 incoming tasks each. Completion Q(K) (%) versus stopped spend B(K) (attempts/task). Segments join adjacent discrete caps K=1,…,10 . Point estimates; no uncertainty intervals. Twelve configuration-specific panels show completion and mean stopped unit-cost attempts at every supported cap in the primary panel.
Appendix figures & tables3 assets
Supplementary material from the paper’s appendix.
Appendix
Figure 4. All four τ2 configurations, n=164 incoming tasks each. Completion Q(K) (%) versus stopped spend B(K) (recorded USD/task). Segments join adjacent discrete caps K=1,…,4 . Point estimates; no uncertainty intervals. Completion axes are focused. Four configuration-specific panels show completion and mean stopped monetary spend at every supported cap in the tau-squared benchmark panel.
Target
Contrast in logR4 [95% CI]
c01
0.0065 [0.0027, 0.0107]
c02
0.0095 [0.0050, 0.0148]
c03
0.0043 [-0.0005, 0.0100]
c04
-0.0004 [-0.0061, 0.0055]
τ2D
0.0054 [0.0024, 0.0086]
τ2 diff.
0.0046 [0.0006, 0.0088]
Appendix
Table 4. Log-ratio contrasts under cost replacements and plug-in replay.
Design
Target
Coverage
MC 95%
Simultaneous F13
Shared tie
percentile
60/64
[0.8476, 0.9827]
[0.7988, 0.9918]
Shared tie
BCa
61/64
[0.8691, 0.9902]
[0.8222, 0.9962]
Independent sham
percentile
63/64
[0.9160, 0.9996]
[0.8746, 1.0000]
Independent sham
BCa
63/64
[0.9160, 0.9996]
[0.8746, 1.0000]
High homogeneous
percentile
61/64
[0.8691, 0.9902]
[0.8222, 0.9962]
High homogeneous
BCa
54/64
[0.7314, 0.9224]
[0.6755, 0.9469]
Appendix
Table 5. Synthetic interval coverage and delivery diagnostics.
When an LLM agent fails a multi-step tool-augmented task and retries, the failed attempt typically remains in its context window -- contaminating the next attempt and elevating the per-step error rate beyond the base level. This context-contaminated restart phenomenon is widely observed in practice yet entirely lacks formal treatment. We introduce the Context-Contaminated Restart Model (CCRM): a chain of T tool-call steps, each failing with base rate epsilon_0; after any failed attempt, the subsequent attempt operates in contaminated context with elevated error rate epsilon_1 > epsilon_0. Under this model we derive five main results. (R1) An exact closed-form formula for P(succeed in at most K attempts). (R2) A cascade-overhead theorem giving the additional attempts Delta K incurred by contamination versus the clean-restart baseline. (R3) An optimal budget-allocation theorem identifying the pipeline depth T* that maximises success probability for a fixed total budget B=KT; we prove the closed form T* = sqrt(B * log(1/(1-epsilon_1)) / log(1/(1-epsilon_0))), with K*=B/T*. (R4) An information-theoretic lower bound via Le Cam's method showing K_CCRM is tight up to O(1). (R5) A clean-restart dominance theorem quantifying the exact benefit of context-clearing before retry. We validate CCRM on real SWE-bench Verified data: the IID model overestimates pass@3 by 17.4 percentage points (98.6% vs. 81.2%), while CCRM fits with error less than 0.001, implying a cascade ratio of epsilon_1/epsilon_0 = 7.1. Monte Carlo experiments confirm all theoretical predictions.
Zhanfu Yang
Department of Computer Science, Rutgers University, Piscataway, NJ 08854, USA
Self-repair - returning a failed program to the model together with its test output and asking for a correction - is a standard component of code agents, and is almost always evaluated against a baseline that does not retry at all. We argue that this comparison confounds the value of the feedback with the value of the extra attempt. Using a placebo-controlled design on MBPP+ at three model scales (1.5B, 3B, 7B), we compare four matched-budget retry conditions: blind resampling, a content-free failure notice, genuine execution feedback, and feedback augmented with verbal self-reflection. Blind resampling is the strongest condition below 7B, and remains statistically tied with the best condition at 7B, while consuming 2.5-5.5x fewer tokens; conditioning on the model's own failed attempt costs 6.1 points at 1.5B (p=0.006), and the informational content of execution feedback adds nothing measurable over the placebo. We attribute this to anchoring: when shown its previous attempt, a model reproduces a near-identical program in 33-68% of retries, against 2-14% under blind resampling. Two further experiments delimit the effect. Retrieved solutions to other tasks change nothing (bounded to +/-3.5 points), which localizes the harm to self-conditioning rather than context length; and reflection, the only condition that measurably weakens the anchor, remains dominated on cost. Replication rules out two competing explanations: the penalty is unchanged at full precision, and it reproduces on an independent model family. Across six configurations spanning two families and two precisions, its magnitude is predicted by baseline quality alone (r=0.96) - the cost of anchoring is the cost of committing to a bad first attempt.
Tool-using AI agents are increasingly deployed across enterprise software systems, yet widely used benchmarks primarily evaluate nominal task completion, conflating baseline planning competence with operational fault recovery. We introduce UndoBench, a benchmark spanning 36 base workflows and 36 fault scenarios across 8 enterprise domains, decoupling task competence from recovery capability via counterfactual paired trials under identical seeds alongside wire-level effect-history and environment-state oracles. On 12 held-out TEST workflows across two open-weight models, two frameworks, and three recovery paradigms (5,760 executions / 2,880 paired trials) in the frozen lost-acknowledgment study, nominal competence reached 83.54% while conditional recovery success rate (CRSR) fell to 46.72%, with naive retry producing duplicate external effects in 53.33% of trials. Extensions to commercial API models reproduced this competence-recovery separation. Evaluations across complementary execution boundaries show that recovery is phase-dependent: before mutation, methods perform similarly without duplicate effects among capable trials; during partial mutation, naive retry, per-call idempotency, and zero-privilege journaling collapse on the evaluated composite workflows; after commit but before acknowledgment, verification and server-side idempotency substantially improve safety. These findings demonstrate that evaluating nominal completion alone masks critical, phase-dependent recovery vulnerabilities in autonomous agents.