Improving Code Repair Benchmark Scores with Reinforcement Learning Post-Training
Code repair evaluation is a repository-level task that tests semantic understanding, tool use, long-context management, and verification loops — not just code generation. This article explains why gains cannot be attributed to a single factor like swapping a stronger partner model, and presents a systematic approach combining RL post-training, agent orchestration, and rigorous ablation experiments. It covers training data construction, trajectory sampling, reward design, curriculum-based training pipelines, multi-role agent orchestration, controlled experiment methodology, an engineering deployment checklist, and the key risks of leakage, reward hacking, and test overfitting. Readers will learn why verifiable rewards and feedback loops — not model replacement alone — drive stable score improvements.
1. Background: What Makes Code Repair Evaluation Hard
Code repair evaluation is not a single-turn code generation task. It is a repository-level problem: the model must understand the issue description, locate the defect, read the relevant files, generate a patch, run tests, and avoid introducing regressions. It simultaneously tests semantic understanding, tool use, long-context management, patch minimization, and verification loops. As a result, judging a model by a single generation run can easily over- or underestimate it — evaluation must treat “task–trajectory–verification–cost” as one integrated whole.
A common mistake is attributing score improvements simply to “swapping in a stronger partner model.” In real engineering, replacing a model can bring gains, but it also changes the reasoning style, tool-call frequency, failure modes, and cost structure at the same time. Without isolating variables, it is impossible to tell whether the gain comes from base model capability, post-training behavioral alignment, or agent orchestration and test feedback. The more rigorous approach: fix the evaluation set, tool permissions, time budget, and sandbox environment, then run ablation experiments — “swap the partner model only,” “swap the post-trained version only,” “replace both,” and “remove the orchestration module.”
2. System Overview: Gains Come from Combination
The final score can be abstracted as:
Final score ≈ base model capability × post-training behavioral alignment × tool execution feedback × agent orchestration efficiency × number of samples under cost constraints
The base model determines the capability ceiling. Post-training determines whether the model is willing to follow the behavior sequence of “read files — modify code — run tests — roll back on errors.” Tool execution feedback provides verifiable signals. Agent orchestration decomposes complex tasks across roles. Cost constraints determine whether enough sampling and retries are feasible. In our example, one post-trained version achieved nearly 3× over a weak baseline in internal comparisons, and roughly 1.5× over an un-post-trained counterpart from the same source. The most reasonable interpretation: post-training and the verification loop contributed the primary gains, and simply replacing the partner model only works reliably when orchestration and feedback mechanisms are in place.
3. RL Post-Training: From “Can Write Code” to “Can Repair Repositories”
3.1 Task and Data Construction
Training data should cover three categories: real defects, synthetic defects, and regression fixes. Real defects come from historical issues and fix records; synthetic defects expand edge-case coverage; regression fixes train the model to produce minimal patches. Data governance should focus on three things: deduplication, leakage prevention, and difficulty stratification. Deduplication prevents the model from memorizing similar patches. Leakage prevention requires the training set and evaluation set to be isolated by time, repository, and code fragment. Difficulty stratification enables curriculum learning, progressing from small single-file fixes to multi-file, cross-module repairs. Each sample should retain the issue description, relevant files, test commands, and hidden verification conditions to ensure rewards are computable.
3.2 Trajectory Sampling and Tool Use
Code repair requires multi-turn tool calls: searching for symbols, reading files, editing patches, running tests, and summarizing logs. Sampling should cap the maximum number of steps and per-task cost, and sample multiple trajectories in parallel. Trajectory quality matters more than quantity: one trajectory that passes the tests with a small patch is far more valuable than many plausible-looking but unverifiable ones. Failed trajectories should also be kept, to train the behavior of “recognize the error — roll back — retry.”
3.3 Reward Design
Rewards should prioritize verifiable signals: does it compile, do the target tests pass, do the regression tests pass, is the patch minimal, does it modify unrelated files? Process rewards can supplement locating accuracy and tool-call efficiency, but their weight should stay low to prevent the model from reward hacking to “look plausible.” Model-based review can serve as a supplement, but must be combined with rule-based verification. The core principle: final rewards should be based on executable verification, and process rewards only serve as guidance.
3.4 Training Pipeline
A typical pipeline: supervised fine-tuning for cold start to establish basic tool-call formats; then rejection sampling and preference optimization to filter high-reward trajectories; finally policy-gradient-style methods for continued optimization, with constraints to prevent policy drift. Curriculum learning increases difficulty progressively — single-file repair first, then multi-file coordination. Pseudocode:
for task in curriculum:trajectories = sample_policy(task, tools, max_steps)verified = [run_tests_and_static_checks(t) for t in trajectories]rewards = compute_reward(verified, trajectory)update_policy(rewards, constraint=policy_drift_limit)if early_stop(task, rewards):continue
4. Agent Orchestration: Each Role Does Its Job
Post-training answers “can the model do it”; orchestration answers “can the system do it reliably.” A practical orchestration structure includes: a planner that decomposes tasks and decides the next step; a primary model for complex reasoning and high-risk patches; secondary models for retrieval, log summarization, and other low-risk steps; a verifier that runs tests and static checks; and an arbiter that merges patches, resolves conflicts, and escalates failures. Cost routing selects the model by task difficulty: simple steps go to a low-cost model, complex steps escalate to the primary model, with a limited number of retries after failure. Pseudocode:
def solve(issue):plan = planner(issue)for step in plan:if step.complexity == "low":patch = small_model(step)else:patch = primary_model(step)if verify(patch):return patchif should_escalate(step):plan = replan(issue, feedback=last_error)return escalate_to_human(issue)
The value of this orchestration: concentrate expensive reasoning on key decisions, hand verifiable steps to the test loop, and turn failures into feedback for the next round — rather than blindly increasing sampling.
5. Controlled Experiments and Interpreting Results
Controlled experiments must use the same evaluation set, sandbox, tool permissions, time budget, and test environment. At least four groups are recommended: the baseline combination, partner-model replacement only, post-trained version only, and post-training plus orchestration. Metrics should go beyond the pass rate to include test pass rate, average steps, per-task cost, latency, regression rate, and win/tie/loss distributions. Repeat runs and report confidence intervals to avoid mistaking random fluctuation for capability gains.
Interpret the example results with restraint: nearly 3× from the weak baseline to the post-trained version shows that post-training significantly shifted the behavior distribution; roughly 1.5× from the un-post-trained counterpart shows the gains do not come entirely from swapping the partner model; if a strong combination is not paired with optimized orchestration, costs may rise while returns diminish. In engineering, invest first in verifiable rewards, test sandboxes, and failure-rollback mechanisms — model replacement comes later.
6. Engineering Deployment Checklist
First, data governance: version the evaluation set, apply time splits and similarity filtering. Second, verifiable rewards: rely mainly on tests and static checks, with process rewards as a supplement. Third, sandboxed execution: restrict network, file system, and resources to guard against unsafe patches. Fourth, observability: log tool calls, verification results, and costs for every trajectory. Fifth, gradual rollout: validate with low traffic first, then scale up. Sixth, cost control: set sampling budgets, early stopping, caching, and tiered routing. Seventh, regression gates: any patch must pass both target tests and regression tests before merging.
7. Risks and Boundaries
Code repair evaluation carries risks of leakage, reward hacking, and overfitting to tests. Hidden tests, time splits, and manual spot checks are essential. Different tool permissions significantly change results, so experiment reports must disclose the environment. Cost and latency are real constraints and cannot be ignored in favor of score alone. Finally, no internal evaluation result should be extrapolated directly into a general capability claim — it must be revalidated on new repositories, new languages, and new defect types.
In summary, the key to stable score improvements in code repair is not a single model replacement, but a closed loop centered on verifiable rewards that combines post-training, agent orchestration, test feedback, and rigorous controlled experiments.
