TL;DR
When training language models to debug code using reinforcement learning, a failed unit test usually acts as a dead end: it tells the model that it failed, not how to fix it. This paper introduces repair witnesses, a method that pairs every failed attempt with the closest-matching working solution the model has previously generated itself. Without needing a human teacher or external reference code, this turns wasted test runs into targeted supervision, vastly outpacing standard RL methods in both accuracy and compute time.
What Problem Does This Paper Address?
Imagine trying to learn archery blindfolded, where a coach only yells "hit" or "miss." If you miss ten times in a row, you have no idea which way to adjust your aim.
This is the exact bottleneck in reinforcement learning (RL) for code repair. A policy (the LLM) proposes a batch of bug fixes, and a verifier runs unit tests—our unit of cost—returning a binary pass or fail. Popular algorithms like Group Relative Policy Optimization (GRPO) calculate how much better one attempt is compared to the group average. On hard coding problems, however, every proposal in a batch often fails. When every attempt gets a zero, the relative advantage is zero, the gradient vanishes, and the model learns nothing from those expensive test runs. On HumanEval+ repair, 78% to 98% of GRPO updates suffer from these all-zero advantages. Existing workarounds either throw away failures, burn extra compute asking for execution traces, or force the model to imitate a rigid, human-written reference solution that looks nothing like the model's own coding style.
Methods
The authors' core insight is that a model failing on a specific bug can often write passing code for that same function on other tries (or from scratch). By saving these passing implementations into a verified bank, we can give failed attempts a concrete target to move toward.
Here is how the Repair Witnesses pipeline works:
- Self-Bootstrapped Bank: Before or during training, the model's own passing programs for each function are collected into a bank—no teacher model or gold reference needed.
- Canonical Nearest-Neighbor Retrieval: When a repair proposal fails, the algorithm strips away comments/formatting, normalizes local variable names, and computes the token edit distance (Levenshtein distance) against the bank. It retrieves the nearest working program—the "repair witness"—which represents the minimal edit needed to make the broken code pass. Retrieval requires zero extra LLM or verifier calls.
- Witness Objectives: This single retrieval rule powers three training modes:
- Offline witnesses: Pure supervised learning on initial defects matched to bank witnesses (zero online test runs).
- Online witnesses (default): Combines standard group-centered policy gradients with cross-entropy supervision—failed rollouts learn from their nearest witness, while successful rollouts reinforce themselves.
- Success-projected witnesses: Projects both passing and failing proposals onto their nearest bank witness.
Datasets
The authors evaluate across five code-repair benchmarks, plus two unseen transfer sets:
- HumanEval+ Repair: Fixing human-written bugs from HumanEvalFix verified against strict EvalPlus test suites.
- Hanoi-Hard & Algo-8: Custom repair suites built by applying abstract-syntax-tree (AST) node mutations to Tower-of-Hanoi variants and eight classic QuixBugs algorithms, respectively.
- MBPP+ & LiveCodeBench (Cold-Start): Built entirely from the base model's own generations from specifications—failures become the bug dataset, and passes seed a growing self-bootstrapped bank.
- Unseen Transfer: 69 HumanEvalFix and 10 QuixBugs functions completely held out from training and banks.
Key Insights and Ideas
- Proximity in tokens is proximity in probability: Why does the nearest fix teach faster than a random valid solution? The authors show that closer edits have much lower negative log-likelihood under the policy. Asking a model to make a tiny tweak to its own logic is a much gentler, more natural gradient step than forcing it to memorize a two-line human rewrite.
- The model's own code beats gold references: Self-bootstrapped banks actually outperform curated banks containing official EvalPlus reference solutions. External references can be stylistically alien to the base model; the model learns faster from fixes written in its own "voice."
- Genuine generalization, not bank memorization: Because online witnesses keep the model's novel passing rollouts as their own targets, the trained policies write correct solutions absent from the bank more often than GRPO succeeds in total. Furthermore, the debugging skill transfers cleanly to unseen functions.
- Small models punch way above their weight: Turning failed calls into dense supervision allows 1.7B and 3B parameter models to outperform GRPO-trained models up to 19$\times$ larger (14B–32B).
Key Results
Across 19 settings (10 models from 1.7B to 32B across five model families), online witnesses beat GRPO in every single comparison under equal verifier budgets:
- HumanEval+: Online witnesses repair 73.2% to 82.2% of held-out bugs (at $T=0.2$), landing 37.1 to 58.2 percentage points above GRPO while matching GRPO's final accuracy in at least 2.6$\times$ fewer verifier calls. Even offline witnesses (0 online calls) beat online GRPO by 25 to 54 points.
- Hanoi-Hard Total Budget: Including the 102 calls spent building a self-bootstrapped bank from scratch, Qwen3-14B hits 93.6% accuracy in 230 total calls. GRPO takes 1,600 calls to reach 68.3%—a level witnesses pass in 9.0$\times$ fewer calls and 6.5$\times$ less GPU time.
- Cold-Start Learning: Where GRPO, DAPO, and Dr. GRPO stall near zero, cold-start witnesses repair 52.1% (MBPP+) and 47.1% (LiveCodeBench) of bugs on self-seeded functions, compared to GRPO's 0.9% and 3.8% (widening to 78.2% vs. 7.3% at 1,200 calls on MBPP+).
Limitations and Future Work
While not placed in a dedicated limitations section, an inherent constraint is visible in the cold-start formulation: when a function's bank is empty ($B_f = \emptyset$) and the model cannot generate any passing sample from scratch, the supervised witness term vanishes for failures until at least one passing rollout is discovered (for example, initial cold-start banks only covered 39 of 103 functions on MBPP+ for Qwen3-1.7B, and 51 of 160 on LiveCodeBench). Additionally, computing likelihood-based witnesses (picking the bank member most probable under the current policy rather than via token edit distance) learns even faster by 3.1 to 8.0 AUC points, though edit distance avoids the compute overhead of running the policy over the bank. Finally, the authors note that repository-level, conversational, and multi-turn execution-feedback repair remain complementary directions to explore alongside binary-verifier witnesses.
Summary updated