A coding model is often run in a loop. It writes a program, runs it against some tests, reads the failures, and proposes fixes. A natural way to spend more compute is beam search over these fixes: at every round, keep the $B$ best candidate programs according to some score, expand each one into several repairs, and repeat. Machine translation learned long ago that widening a beam can make outputs worse. The search becomes better at finding sequences the scoring function likes and worse at finding sequences that are actually good. On WMT'14 English–German, BLEU falls from 26.11 at beam width 5 to 21.38 at width 250 (Cohen and Beck).
We propose that the same curse appears, in a sharper form, when beams range over whole program edits instead of tokens. The scorer is no longer model likelihood. It is a proxy made of visible tests and, increasingly, an LLM judge, meaning a language model prompted to grade code. Wider and deeper refinement search should push up the proxy score while pass rates on hidden tests stall or fall and code quality erodes. Each part of the proxy has its own blind spot: tests reward special-casing, and judges reward tidy formatting. Our remedy is to keep a candidate only if two selectors with different blind spots, execution and a judge, both rank it highly. This adapts the rank constraint that stabilized wide beams in translation.
Core Claim
Our first claim is that in execution-guided refinement search, hidden-test accuracy is non-monotone in beam width $B$ and depth $D$. The gap between visible and hidden pass rates of the selected program should grow with search breadth. A simple reason: if each candidate's proxy score equals its true quality plus independent noise of spread $\sigma$, then the selected program's inflation over its true quality grows roughly like $\sigma\sqrt{2\ln(BK)}$, where $K$ is the number of children per parent. That expression is the expected maximum of $BK$ Gaussian draws.
Our second claim is that the inflation is driven by candidates whose gains are visible to only one selector. Two signals catch such candidates. The first is a jump in visible-test passes that the judge does not corroborate, the code-level analogue of Cohen and Beck's "early mistake, late compensation" discrepancies. The second is a jump in judge score that execution does not corroborate. Requiring agreement suppresses both kinds. It is effective when the two selectors' errors are weakly correlated, and we will measure that correlation directly.
Concretely, at each search step let $r_T(c)$ be candidate $c$'s rank among its siblings by visible-test pass rate and $r_J(c)$ its rank by a pointwise rubric judge. We keep $c$ only if
$$\max\big(r_T(c),\, r_J(c)\big) \le N,$$
where $N$ is the agreement cutoff. Survivors are then ordered by visible-test score with the judge breaking ties. The beam is filled from survivors only, and it may stay partly empty rather than admit a candidate that only one selector likes.
Relation to Prior Work
Three lines of work motivate the gap.
Cohen and Beck explain beam degradation through early large departures from the greedy choice. They fix it with a discrepancy-gap constraint and a candidate-rank constraint, which keep BLEU at 26.29 at width 250. We borrow the rank constraint. We change what it ranks, using program edits instead of tokens and two external selectors instead of one likelihood.
Investigating Test Overfitting on SWE-bench shows that single-trace refinement against generated tests raises overfitting to hidden tests, from 21.8% to 25.5% for Claude-3.7 Sonnet and from 33.0% to 35.9% for GPT-4o. It also shows that hiding test contents does not help. SlopCodeBench shows structural erosion in 77% of agent trajectories, which quality-aware prompting does not stop. Both studies use a linear loop. Neither asks how search breadth multiplies these effects, and that is our measurement.
Other work constrains the design. The JETTS benchmark finds three relevant failures: judges guiding step-level beam search are beaten by a 7B process reward model, judge critiques yield an effective improvement ratio of at most 1.0, and weak judges paired with strong generators are actively harmful. This rules out using the judge as the sole scorer or as a source of repair instructions. In our design it acts only as a veto inside a rank constraint, and it is never weaker than the generator. JETTS also shows that pairwise judging costs $O(N^2)$ comparisons, so we use pointwise rubric scores.
SWE-Search does help with an LLM value agent inside tree search: a 23% mean relative improvement, and patch-selection accuracy rising from 73% to 84% with a debate-based discriminator. It does so at roughly 14 times the cost ($41 to $576). We treat it as the strongest competitor and run it under a matched budget.
Refining Over Resampling argues for spending compute on depth rather than breadth, though only in math. TGPR moves tree search into training, and its authors explicitly call for judge-based rewards. Our breadth-by-depth sweep tests in code where each of these claims holds.
Research Program
The work has three stages.
The first stage measures the curse. We build a refinement beam search in which a generator proposes $K$ repairs per parent. Each repair is conditioned on execution feedback from visible tests. We sweep beam width from 1 to 64 and depth from 1 to 8. For every selected program we record five quantities: visible pass rate, hidden pass rate, the visible-minus-hidden gap, edit size relative to the parent, and the erosion and verbosity metrics from SlopCodeBench. We also label the mechanism behind each overfit case: hard-coded outputs, special-casing of tested inputs, assertion-specific branches, or deleted functionality. The aim is to see whether failures concentrate in large single-step edits, as the discrepancy account predicts.
The second stage diagnoses the selectors. For every expanded candidate we compute the rank correlation between test-based and judge-based scores, and the correlation of each with hidden-test outcomes. The agreement constraint should help only to the extent that the two selectors' errors are not shared. Measuring that overlap tells us when the method should work and when it should not.
The third stage is the remedy. We apply the agreement-rank constraint across the same sweep. Like Cohen and Beck's thresholds, the cutoff $N$ needs tuning, so we tune it once on a development split and then freeze it.
The generator is an open 7B coder model, with a 70B model as a scale check. The judge is the same model or a larger one, so we avoid the weak-to-strong failure JETTS documents. It scores with a fixed checklist rubric covering spec fidelity, absence of input special-casing, structural simplicity, and duplication. As a secondary condition we add the static efficiency judge from Rethinking Code Refinement, which reaches 72.49% Python accuracy at 1.3B parameters. This guards against the roughly 30% of machine edits that silently slow code down.
Baselines
The do-nothing reference is greedy single-shot generation with no refinement. A slightly stronger naive reference is the linear execution-feedback loop: one trace, repaired against visible tests until they pass or the budget runs out. This is the setting where Ahmed et al. measured rising overfitting. Beating it means higher hidden pass rate and a smaller visible-minus-hidden gap at equal generator calls.
The second baseline is unconstrained refinement beam search scored by visible tests alone, swept over the same widths. This is the condition we predict will degrade, so it is also the main object of the first stage.
The third baseline is the held-out-test selector. Visible tests are split into a repair half shown to the generator and a selection half used only for ranking. It is the strongest cheap competitor, and it is described further below.
The fourth baseline is judge-only beam search: candidates are ranked by the rubric judge alone. This reproduces the JETTS step-level setting on refinement steps and isolates whether the judge carries any signal by itself.
The strongest existing method is budget-matched MCTS with a hybrid value agent in the style of SWE-Search. We reimplement its depth-bonus UCT rule (the formula that decides which branch of the tree to expand next) and its score-plus-explanation value agent. We cap it at the same total number of generator calls, judge calls, and sandbox executions as our method, and give it the same tuning budget of 20 development configurations. SWE-Search reports a 23% mean relative improvement over its base agent on SWE-bench Lite. No reported result was found on Lacuna for it on HumanEval+, MBPP+, or BigCodeBench.
Best-of-N resampling with test-based selection serves as the breadth-only reference. Both Refining Over Resampling and JETTS discuss this baseline, but neither reports numbers on these code benchmarks.
The key ablation replaces the agreement rule with a single-selector rank constraint using visible tests alone, at the same $N$. This separates "pruning helps" from "agreement helps." A second ablation swaps the rubric judge for a random but equally strict veto. It checks that the gains do not come merely from shrinking the beam.
Beating the field requires two things. Hidden pass rate must be flat or rising in $B$ where baseline two falls. And at the largest budget, the method must exceed both the held-out-test selector and budget-matched MCTS on hidden pass rate, with lower erosion, with the difference significant across three seeds.
Why not just…?
Why not just hold out some visible tests for selection? This is the real threat. Against hard-coding of specific tested inputs, a held-out split may work as well as our method. It has two weaknesses in this setting. It shrinks an already small test pool: BigCodeBench averages 5.6 tests per task, according to BigCodeBench. And it cannot see erosion or verbosity, which pass any number of tests. Baseline three settles the question directly. If held-out selection matches us on hidden pass rate and erosion, the judge contributes nothing, and we will report that. We also test the obvious hybrid, an agreement rule between the two test halves, so that the comparison isolates the judge's contribution.
Why not just keep the beam narrow? If degradation starts at small widths, the simplest fix is to stop widening. Narrow beams, however, give up the exploration that SWE-Search and TGPR found necessary to escape repetitive repair loops. The width sweep shows whether there is any width at which unconstrained search beats a narrow beam. If there is none, the practical recommendation becomes "use $B\le 4$," and the remedy matters only if it makes larger budgets pay off.
Why not just calibrate the generator, as in translation? Wu et al. train likelihoods to correlate with an external quality score, so that beam width 5 suffices. Two things differ here. In our search the scorer is an external proxy, not the generator's own likelihood, so calibrating the generator does not stop the search from overfitting that proxy. And that work never tested wide beams. Calibration is complementary, and we leave it to follow-up work.
Why not just use a strong judge's critiques to guide the fixes? JETTS reports effective improvement ratios of at most 1.0 for critique-driven refinement, so we do not expect critiques to help. Our design deliberately uses the judge only as a ranking veto. The judge-only baseline checks whether even that weaker role is useful.
Proposed Experiments
The main testbed is HumanEval+ and MBPP+. Each has a natural split: the original tests serve as visible feedback, and the extended tests serve as hidden ground truth. BigCodeBench-Complete and BigCodeBench-Instruct test library-heavy tasks with few tests per task; for reference, BigCodeBench reports 61.1% and 51.1% calibrated pass@1 for GPT-4o single-shot. LiveCodeBench guards against contamination; TGPR reports 41.2% greedy pass@1 for its trained 7B model, which we cite only as context. For repository-scale overfitting we use SWE-bench Verified with generated tests as the visible signal and golden tests as hidden, following the protocol and reference rates of Ahmed et al.. For erosion we use the 196 checkpoints of SlopCodeBench, where the best agents pass about 14.8% of checkpoints end to end.
Metrics are hidden pass@1 of the final selected program, the visible-minus-hidden gap, the overfitting rate, SlopCodeBench erosion and verbosity, and total compute in generator calls, judge calls, and executions.
Three checks would decide the question. First, does unconstrained beam search on visible tests show falling hidden pass rate beyond some width, with the gap growing roughly in line with the $\sqrt{\ln(BK)}$ prediction? If not, the curse does not transfer to refinement, and that negative result is itself worth publishing. Second, does the agreement constraint flatten the curve while the single-selector ablation and the random veto do not? Third, does the measured error correlation between tests and judge predict, task by task, where agreement helps? That would show the mechanism is selector independence and not mere pruning.
References
- Empirical Analysis of Beam Search Performance Degradation in Neural Sequence Models
- Investigating Test Overfitting on SWE-bench
- SlopCodeBench: Measuring Code Erosion Under Iterative Specification Refinement
- Evaluating Judges as Evaluators: The JETTS Benchmark of LLM-as-Judges as Test-Time Scaling Evaluators
- SWE-Search: Enhancing Software Agents with Monte Carlo Tree Search and Iterative Refinement
- Refining Over Resampling: Test-Time Self-Correction for LLM Reasoning
- From Search to Policy: Thompson Sampling Trees for Robust LLM Code Refinement
- Rethinking Code Refinement: Learning to Judge Code Efficiency
- BigCodeBench: Benchmarking Code Generation with Diverse Function Calls and Complex Instructions
- Calibrating Translation Decoding with Quality Estimation on LLMs