NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Execution-Calibrated Backtracking for LLM Code Repair

When a language model repairs a program by editing it, running the tests, and editing again, each round depends on the one before. A bad edit early on, such as a fix that silently breaks another function, contaminates every later attempt. Success then decays roughly as the product of per-step success rates, so long repair loops fail even when each step is usually right. Systems that can undo, by rolling back to an earlier version of the code and trying something else, recover much of this loss. They immediately run into a question nobody has answered well: when should the agent abandon its current line of repair and go back? Backtrack too eagerly and search cost explodes. Tree search on repository repair has pushed one model's benchmark bill from about \$41 to about \$576. Backtrack too reluctantly and the agent grinds on a doomed branch, which is the familiar plateau after two or three self-debugging rounds.

Classical heuristic search already has a precise language for this dilemma. In A, a best-first search that always expands the candidate with the lowest estimated total cost, the agent "backtracks" whenever an older candidate looks cheaper than the current one. How often that happens depends on the heuristic, the estimate of remaining cost. A heuristic that never overestimates (an admissible one) guarantees the best answer but forces wide, shallow exploration. An inflated one searches deeply and cheaply but gives up optimality. This note proposes to treat the model's estimate of "how many more repair rounds until the tests pass" as an A heuristic. We would calibrate it against real execution outcomes, separately for each kind of execution state the program is in (syntax error, runtime crash, failing assertion, or all tests passing but behavior drifting). The result is a single knob that trades search cost against repair quality with a stated probabilistic guarantee, and a backtracking rule that knows when the model's optimism can be trusted.

Core Claim

The model's remaining-effort estimates are wrong in different ways in different execution states. Syntax errors produce explicit compiler messages, so estimates made there are probably accurate. Estimates made after a semantically wrong but exception-free edit are probably badly optimistic. This asymmetry is noted as an open problem in the long-horizon agent literature. A single global inflation weight on the heuristic therefore cannot sit on the best cost–success frontier. Our claim is that subtracting a per-state-class overestimation margin, learned from logged repair trajectories, yields a best-first repair search that satisfies two conditions. Under a matched budget of test executions and tokens, it dominates both greedy refinement with rollback and a globally tuned weighted A* on the same raw scores. It also makes the backtrack/persevere decision interpretable: the agent returns to an older checkpoint exactly when that checkpoint's calibrated estimate beats the current one.

The mechanism fits in two lines. Let $\hat h(n)$ be the model's predicted number of remaining repair rounds from code state $n$, $c(n)$ the execution-state class of $n$, and $q_\delta(c)$ the $(1-\delta)$ quantile of the overestimation $\hat h - h^*$ among logged training states of class $c$, where $h^*$ is the true remaining rounds. The calibrated heuristic and search priority are

$$h_\delta(n) = \max\big(0,\ \hat h(n) - q_\delta(c(n))\big), \qquad f_w(n) = g(n) + w\, h_\delta(n),$$

where $g(n)$ is the number of edit rounds already taken to reach $n$ and $w \ge 1$ is the user's efficiency knob. If $h_\delta$ is admissible at each node on an optimal repair path, weighted A* returns a repair path no longer than $w$ times optimal. With per-node failure probability $\delta$, a union bound over the optimal path's length $L$ makes this hold with probability at least $1 - L\delta$.

This is a direct transplant of Towards Finding Optimal Solutions with Non-Admissible Heuristics. That paper made an overestimating heuristic admissible by modeling its worst-case overestimation envelope as a function of true distance, and cut 8-puzzle node expansions fivefold while preserving optimality. We condition the envelope on observable execution state instead of on the unknown true distance, which is what makes it usable online. The method borrows from Learning from Multiple Heuristics, which biased a learned heuristic toward admissibility with an asymmetric loss and got 16-fold fewer 15-puzzle expansions at within 4% of optimal. We use the same asymmetric-loss idea as a second way to fit $\hat h$, and compare it against post-hoc quantile correction.

We are honest about the guarantee's scope. $g$ counts edit rounds, a proxy for patch minimality and regression risk rather than for correctness. $h^*$ is estimated from the shallowest passing descendant found in dense offline search, which upper-bounds the truth and makes $q_\delta$ conservative. The practical payoff we expect is fewer expansions per solved problem, not the bound itself.

Research Program

A search node is a checkpoint of the code: a git commit for multi-file tasks, a file snapshot for single-function tasks. Each node carries an execution fingerprint made of the vector of pass/fail outcomes per test, the error class, and a hash of the top traceback frame. This makes the search state-aware in the sense used by StateFlow, which isolated error handling into explicit states and beat ReAct by 13% on InterCode SQL at 5x lower cost. Two checkpoints with identical fingerprints are merged. This directly addresses the circular revisiting that SWE-Search reports when its flexible backtracking meets noisy value estimates. Rollback is cheap at program level, which sidesteps the snapshot overhead of container-level rollback in Repo2Run.

A node's pass vector can lose tests relative to its parent. This is the regression, or "new error trap", that MEIC guards against by reverting to the best version. We do not revert automatically. Instead we tag the node with its own state class, so the calibration learns how optimistic the model tends to be after a regression. The context passed to the model at expansion time contains only the current checkpoint's diff from the original, its fingerprint, and a one-line summary per ancestor. It does not contain the full log. This follows the context-trimming lesson of Smurfs, which cut tokens by 60.9% on StableToolBench with rule-based rollback.

Calibration data comes from dense offline search on training splits: many sampled edits per node, run to a fixed depth, which gives an empirical $h^*$ at every visited node. We fit $\hat h$ two ways, by prompting for an integer estimate and by a small regression head on the policy's hidden state trained with asymmetric loss. We then compute $q_\delta(c)$ per class. The work has three analyses. First, we measure how the overestimation distribution differs across the state classes; this is the premise, and it can be checked before any search runs. Second, we trace empirical cost–success frontiers as $w$ sweeps. Third, we audit coverage, meaning how often $h_\delta$ actually overestimates on held-out problems and on a shifted benchmark.

Baselines

The naive reference point is a single greedy generation followed by linear self-debugging with compiler and test feedback for as many rounds as the budget allows. That is the setting where CodeTransOcean reports ChatGPT's debugging success rate rising only from 48.57% (DSR@0) to 52.57% (DSR@3), and where LiveCodeBench reports GPT-4-Turbo self-repair moving from 24.5% to 36.9%. The closest simple state-aware baseline is MEIC-style greedy refinement with rollback-to-best, which is hill-climbing that reverts any edit that lowers the test-pass count. MEIC reports a 78% functional fix rate on its 178 RTLLM errors with GPT-4. We reimplement it for Python and also run our method on RTLLM for a direct comparison.

The strongest sampling baseline is best-of-N independent sampling with a self-debug tail, allocated the same number of test executions. The strongest search baseline is SWE-Search-style Monte Carlo tree search, meaning search driven by repeated simulated rollouts, with a numerical value model. On SWE-bench Lite it reports a 23% mean relative improvement over its base agent at GPT-4o cost rising from ~\$41 to ~\$576. We run it with the same value prompts that produce $\hat h$, so any difference comes from the search rule and not the scorer. For competitive programming we report PlanSearch's 77.0% pass@200 with Claude 3.5 Sonnet on LiveCodeBench, and its 55.6% for repeated sampling, as external context only. It searches over plans without execution feedback and uses a different budget. No reported result was found on Lacuna for weighted A* over code-repair states.

The ablation that isolates our key ingredient is weighted A* on the raw, uncalibrated $\hat h$, with the single weight $w$ tuned on the same development set used for calibration and the same tuning budget. A second ablation calibrates with one global margin instead of per-class margins. All methods share the model (an open 7B coder as in TGPR plus one API model), the test harness, the fingerprint deduplication, and budgets of 10, 30, and 100 test executions per problem.

Beating the field means one of two things. Our frontier could lie strictly above the tuned-global-$w$ curve at two or more budgets, with non-overlapping bootstrap intervals over problems. Or we could match the tree-search baseline's solve rate with at most a third of its test executions.

Why not just…?

Why not just use greedy refinement with rollback-to-best, as MEIC does? This baseline is a genuine threat on short tasks. When the first edit usually lands near a fix, rollback-to-best already prevents most compounding. Its weakness is that it only ever returns to the single best checkpoint and has no way to judge that an older, worse-scoring checkpoint was a more promising fork. The per-step product argument in Instruction Agent predicts that this weakness grows with repair depth. We therefore stratify results by the number of rounds the offline oracle needed. If our method only ties on shallow problems and wins on deep ones, the claim survives in narrowed form. If it ties everywhere, the extra machinery is not justified.

Why not just sample N independent repairs and keep one that passes? PlanSearch shows that independent samples cluster around the same flawed idea. Their 55.6% versus 77.0% gap on LiveCodeBench is about conceptual diversity rather than backtracking, though. Best-of-N can therefore still be strong when the fix is short. Matching test executions exactly, and reporting how many distinct fingerprints each method visits, will show whether search earns its keep through diversity of reached states or merely spends budget differently.

Why not just tune one inflation weight on a dev set? This is the most serious alternative, because it captures most of the admissibility–efficiency tradeoff with no calibration machinery. Our method is only worth building if the model's miscalibration really differs by execution state. The first experiment tests that premise directly, before any search: we compare the overestimation distributions across state classes. If they coincide, we drop per-class calibration and report the global-weight result as the finding.

Why not amortize search into the weights, as TGPR does? From Search to Policy reaches 41.2 on LiveCodeBench with Qwen-7B and runs 12x faster than test-time search. It has no checkpoint to return to at inference, however, and it needs reference solutions for its reward. The two are complementary, so we run our search on top of a TGPR-style policy when one is available. If the amortized policy's frontier leaves no room above it, that is a clean negative result.

Proposed Experiments

The primary testbed is LiveCodeBench in the self-repair setting, using problems after the model's training cutoff, with HumanEval+ and MBPP+ as easier controls. CodeTransOcean's debugging-success-rate protocol supplies a translation-repair setting whose plateau is documented. RTLLM gives a head-to-head with MEIC. SWE-bench Lite is the scale-up, where checkpoints are commits and budgets are denominated in dollars against SWE-Search's reported ~\$576. Metrics are solve rate at fixed test-execution and token budgets, expansions per solved problem, repair-path length relative to the shortest passing path found offline, regressions introduced into the final patch, and the empirical overestimation rate of $h_\delta$ against its nominal $\delta$.

The decisive checks come in order. First, per-class overestimation distributions must differ measurably; otherwise per-class calibration is abandoned. Second, the per-class frontier must dominate the tuned global-weight frontier on held-out problems. Third, coverage must stay near nominal when calibration is fit on MBPP-style tasks and applied to LiveCodeBench. This is the out-of-distribution failure that Davis et al. warn about when sampling is incomplete, and we expect it to degrade. We will report by how much and whether a small in-domain recalibration set restores it. Finally, the gain should concentrate on problems needing deep repair, which is the signature of the compounding-error mechanism we claim to be addressing.