When a language model writes code, the usual fix for wrong answers is to run the code, show the model the errors, and let it try again, sometimes with extra "reviewer" agents arguing over the patch. Each extra round costs tokens and carries risk. Refinement tends to stall after two or three rounds, and aggressive review loops break code that was already correct. The decision that matters most in these systems is usually made by a hand-written rule: whether to spend another round, and on what kind of round. This proposal trains a small controller model to make that call after every round. It picks one of four moves. It can stop. It can ask the coder for a cheap self-repair using the error trace. It can escalate to an expensive structured review by two critic agents. Or it can throw the attempt away and resample from scratch.
The controller learns from a reward that needs no reference solution and is not sparse. The reward is the change, from one round to the next, in the fraction of the training tests the program passes, plus a penalty for tests that used to pass and now fail, minus the tokens spent. The obvious competitor is the rule "stop as soon as the visible tests pass, otherwise repair." That rule is strong. So the whole proposal is organized around one question: does a learned per-round controller beat it in the specific situations where the rule must be wrong? There are two such situations. In the first, the visible tests pass but hidden ones fail. In the second, the visible tests fail but further repair cannot fix the program.
Core Claim
The claim has two parts. First, the value of one more refinement round can be predicted from what is visible at test time. That includes the execution traces on the public tests, the history of recent edits (diff sizes, and whether the same failure keeps recurring), and the coder's token-level confidence. Second, a controller trained on per-round changes in test pass rate turns that prediction into a better trade between accuracy and tokens than either fixed refinement schedules or rules based only on confidence or only on the public tests.
The new element is not a multi-agent topology, a dense reward for the coder, or difficulty gating as such. All three exist. The new element is training the stop-or-escalate policy itself with an execution-grounded, round-level reward that needs no reference solution. The coder model and the reviewer agents stay frozen.
Two choices make this reward well behaved. Write $p_t$ for the fraction of a problem's training tests passing after round $t$. Write $g_t$ for the fraction that passed after round $t-1$ but fail after round $t$. Write $c_t$ for the tokens spent in round $t$. The per-round reward is
$$ r_t = (p_t - p_{t-1}) - \lambda\, g_t - \mu\, c_t , $$
where $\lambda$ sets how much extra a regression costs and $\mu$ prices tokens.
The pass-rate term telescopes: summed over an episode it equals $p_T - p_0$. It is therefore a potential-based shaping of the terminal outcome. It spreads credit across rounds without changing which policy is optimal. The regression term is the one deliberate bias. It pushes against the "scope creep" that structured review produces.
Where This Sits in Prior Work
Three systems already gate extra computation on difficulty, and they motivate this proposal.
AgentConductor trains a 3B orchestrator with reinforcement learning to emit a graph of agent roles. It regenerates that graph once after a sandbox failure, and it reports 58.8% pass@1 on APPS with up to 68% fewer tokens. Its second turn is triggered by a binary pass/fail signal, and it plans a topology rather than deciding round by round whether to continue.
MAgICoRe routes easy problems to voting and hard ones to a solver, reviewer, and refiner pipeline. It shows that refining every problem costs 5.2% on MATH. Its gate relies on neural outcome and process reward models, and it was never grounded in code execution.
LASE escalates from a leader agent to supporter agents when token log-probabilities signal ambiguity. It names miscalibrated overconfidence as its main failure. In code this is the expected case, since confident code crashes all the time.
Our controller differs from all three. It sees execution traces. It decides at every round. It is trained on a reward computed from test outcomes, not from a learned verifier or from model confidence.
Two papers supply the reward ingredients, and we reuse them. TGPR shows that partial test pass rates are a usable dense signal for training a code-refining policy. It pairs them with CodeBLEU against a reference solution and acknowledges that this produces false negatives on valid alternative solutions. SoRFT has the same reference dependence through its localization-overlap reward. We keep the pass-rate part, drop the reference-similarity part, and apply the signal to a different learner: the controller, not the coder.
Several results constrain the design. Yan et al. find that refinement plateaus after two to three iterations and that later rounds cycle through the same wrong hypotheses. This is why "restart" is an explicit action, and why recurrence of a failure is a controller input. SlopCodeBench shows that repeated edits erode code quality, and Adversarial Review reports over-editing that breaks regression tests. Both motivate the $\lambda g_t$ term.
The expensive escalation action is the Adversarial Review protocol itself. In that protocol a Reviewer and a Critic argue with line-cited evidence while the code is frozen, and only then does the coder patch. Its authors explicitly call for an adaptive version that gates the loop on difficulty, and this proposal builds it. The broader case that execution feedback is worth having comes from LiveCodeBench: GPT-4-Turbo's self-repair rose from 24.5% to 36.9% with interpreter feedback.
Research Program
The coder is a fixed open-weight code model, for example a Qwen2.5-Coder 7B. The reviewer and critic follow the Adversarial Review prompts on the same backbone. The controller is a separate 3B model, matching AgentConductor's orchestrator size.
At each round the controller reads five things: the problem statement, the current program, the public-test results with tracebacks, a compact edit history, and summary confidence features from the coder (minimum log-probability and maximum entropy over the program). From these it emits one of the four actions. Every episode has a hard cap of five rounds, which already sits past the observed plateau.
Training data comes from the APPS training split for function-level work and from SWE-Gym for repository repair. Both supply executable tests but are used without reference solutions. Each problem's tests are split into two parts. A "public" part is visible to the controller as input. A "training" part is used only to compute $r_t$. This mirrors deployment, where hidden tests exist but are never seen.
We first collect rollouts under a randomized action policy and log every round's outcome. These logs serve two purposes. They fit an initial controller offline: we regress the next-round reward for each action, then act greedily on those predictions. They also bootstrap online reinforcement learning with group-relative policy optimization over controller decisions. Because the coder is frozen, rollouts are cheap relative to training the coder. The same logs also let us compute exact counterfactual comparisons against fixed schedules.
The analysis side matters as much as the method. For every test problem we label the state after the first attempt with one of four strata. In stratum A, public and hidden tests both pass. In stratum B, public tests pass but hidden tests fail. In stratum C, public tests fail but the program is fixable within budget. In stratum D, public tests fail and the program is not fixable by repair. Fixability is determined from the exhaustive logs. The public-tests rule handles A and C correctly by construction. Any honest gain must therefore come from B and D, and we report results separately for each stratum.
Baselines
The naive reference is a single attempt with no refinement, together with a fixed two-round self-repair schedule. Two rounds is the point where prior work finds gains stop.
The rule baseline is the strongest simple competitor. It stops when all public tests pass; otherwise it self-repairs with the trace, up to the round cap. Once public tests fail twice with the same failure signature, it escalates to adversarial review. This gives the rule a hand-designed version of everything the controller can do except restart. It runs on the same coder, the same reviewers, and the same cap, with its one threshold tuned on the same validation split. Beating it means higher pass@1 at equal or lower mean tokens, with the gain concentrated in strata B and D.
The strongest existing method is Adversarial Review applied to every problem. Its paper reports 87% on LiveCodeBench, against 77% zero-shot and 82% for five-agent MARS, and 75.2% on SWE-bench Verified, at about 4.5 times the tokens of zero-shot. Those figures come from the authors' own backbone. We rerun the protocol on our backbone and treat their numbers as a reference only. Beating it means matching its pass@1 within noise at a fraction of its tokens, and showing a lower regression rate on stratum A problems.
AgentConductor is run on APPS with its released recipe where available. Its reported 58.8% pass@1 on APPS is the published reference point.
A sample-matched best-of-$k$ baseline spends the same mean tokens on independent samples and picks the first one that passes the public tests. This is the "restart only" policy taken to its limit.
Three ablations isolate the key ingredients. The first trains the identical controller on the terminal reward $p_T$ alone, which tests whether per-round credit matters. The second removes execution features so the controller sees only confidence and text, a LASE-style gate trained by reinforcement learning. The third removes the restart and escalate actions in turn.
Why not just…?
Why not just stop when the public tests pass? This is the real threat, and the experiments are designed around it. On problems in strata A and C it is close to optimal, and nothing in the literature shows how often strata B and D occur. Our first experiment is therefore the headroom measurement itself. If B and D together hold only a few percent of LiveCodeBench and APPS problems, a learned controller has little to win. In that case we would report that the simple rule suffices and shift the contribution to the repository setting. There, public tests are sparser and false passes should be more common.
Why not just gate on model confidence, as LASE does? LASE's own analysis names confident wrong answers as its failure mode. In code, low entropy and runtime failure routinely coexist. The confidence-only ablation tests this directly. If it matches the full controller, execution features add nothing and we would say so.
Why not just spend the budget on more independent samples? MAgICoRe found that targeted refinement with 15 samples beat 120-way self-consistency and best-of-$k$ on math. SWE-Gym, however, showed that sampling plus a verifier lifts SWE-bench Verified from 20.6% to 32.0% at Best@16, so sampling is far from weak. Our controller includes restart as an action, so it can learn to behave like best-of-$k$ when that is right. The token-matched sampling baseline settles whether it ever does better.
Why not just train the coder with dense rewards, as TGPR or BoostAPR do? That improves first attempts but leaves the stop-or-escalate decision to a fixed schedule. The two are complementary. As an extra check we run our controller on top of a coder already trained with pass-rate rewards, to see whether the gains survive a stronger coder.
Proposed Experiments
The primary benchmarks are LiveCodeBench, which has public and hidden tests and a contamination-free collection window, and the APPS test split. We report pass@1, mean and 90th-percentile tokens, the full accuracy-versus-token curve obtained by sweeping $\mu$, and the regression rate: the fraction of first attempts that were correct and ended incorrect. We also report action frequencies by stratum. For the strongest baseline we cite the reported numbers above and rerun everything on one backbone.
The secondary benchmark is SWE-bench Verified, with the controller trained on SWE-Gym. BoostAPR's reported 40.7% and SWE-Gym's 32.0% Best@16 serve as published references for trained single agents.
There are three decisive checks. First, before any training, the exhaustive logs give the headroom available in strata B and D. This number bounds what the controller can gain over the rule, and it decides whether the project proceeds as designed. Second, the per-round-reward controller must beat its terminal-reward twin at equal training rollouts. If it does not, the dense credit claim fails. Third, stratum A regression rates must fall below those of always-on Adversarial Review. That would confirm the regression penalty actually curbs over-editing rather than merely saving tokens.
References
- AgentConductor: Topology Evolution for Multi-Agent Competition-Level Code Generation
- MAgICoRe: Multi-Agent, Iterative, Coarse-to-Fine Refinement for Reasoning
- Efficient Multi-Agent Reasoning via Confidence-Guided Adaptive Debate
- From Search to Policy: Thompson Sampling Trees for Robust LLM Code Refinement
- SoRFT: Issue Resolving with Subtask-oriented Reinforced Fine-Tuning
- CodeTransOcean: A Comprehensive Multilingual Benchmark for Code Translation
- SlopCodeBench: Measuring Code Erosion Under Iterative Specification Refinement
- Adversarial Review: Structured Disagreement for Grounded Agentic Code Review
- LiveCodeBench: Holistic and Contamination Free Evaluation of Large Language Models for Code
- Training Software Engineering Agents and Verifiers with SWE-Gym