How RL Post-Training Doubles the Benchmark Scores of Code Agents
Reinforcement learning (RL) post-training can significantly enhance code agent performance in repository-level software engineering benchmarks, achieving up to 1.5x the score rate of non-post-trained equivalents and 2.7x that of general ad-hoc model combinations. This article abstracts this phenomenon into a reusable systematic engineering approach. It details how to define comprehensive evaluations, implement layered verifiable rewards, leverage high-quality trajectory sampling and curriculum learning, optimize inference orchestration with cost routing, and conduct strict ablation studies to ensure stable, reproducible performance improvements for code agents in real-world repository tasks.
In repository-level software engineering benchmarks, a code agent combination that has undergone reinforcement learning (RL) post-training can achieve a score rate approximately 1.5 times that of its non-post-trained counterpart, and about 2.7 times that of a general ad-hoc combination. On the surface, it may seem like “a certain model simply scored higher.” In reality, it is a systematic engineering effort: task distribution alignment, verifiable rewards, failure trajectory feedback, multi-turn verification during inference, and strict ablation studies working in synergy. This article does not focus on specific brands or model versions; instead, it abstracts this phenomenon into reusable technical methods to explain how to achieve stable improvements for code agents in real-world repository tasks.
1. Defining Evaluation: Both Team and Individual Matches Are Essential
Repository-level programming tasks differ significantly from simple code completion. Models must read multi-file contexts, locate defects, generate patches, run tests, handle regressions, and converge within a limited number of turns. Evaluations should include at least two types of scenarios:
- Team/Combo Match: One model is responsible for planning and long-context understanding, while another handles execution, editing, and test fixes. This measures the system capability of a “planner + executor” architecture.
- Individual/End-to-End Match: A single model independently completes the entire process from localization to repair. This measures the model’s inherent capabilities in tool calling, context management, and multi-turn repair.
Looking only at team matches can lead to misinterpreting orchestration gains as individual model capabilities. Conversely, looking only at individual matches ignores the cost routing and sub-agent collaboration common in real production environments. Therefore, evaluations should simultaneously record the score rate, test pass rate, regression failure rate, average interaction turns, timeout rate, and cost per task. Ablation studies must fix the task set, tool permissions, timeout limits, sandbox environment, and random seeds to avoid false improvements caused by “switching to a more lenient execution environment.”
2. Core Mechanism 1: Verifiable Rewards Provide Stable Signals for RL
The advantage of code tasks is that they are “verifiable.” Whether a patch passes hidden tests, introduces regressions, or maintains minimal changes can all be translated into reward signals. A simplified reward function can be designed as follows:
def compute_reward(trajectory):if not trajectory.sandbox_ok:return -1.0if trajectory.cheat_detected:return -1.0if not trajectory.hidden_tests_pass:return -0.5score = 0.55score += 0.20 * trajectory.regression_pass_ratescore += 0.10 * trajectory.process_efficiencyscore += 0.10 * trajectory.patch_minimalityscore += 0.05 * trajectory.tool_call_validityreturn clip(score, 0.0, 1.0)
The key here is not the formula itself, but the layered structure of the rewards:
- Final Outcome Reward: Passing hidden tests is the primary signal, preventing the model from making only superficial modifications.
- Regression Reward: Patches must not break existing functionality; otherwise, they are unusable in real repositories.
- Process Reward: Encourages logical trajectories—searching first, then locating, modifying, and finally verifying—rather than blind, massive overhauls.
- Security and Compliance Penalties: Prohibits reading test answers, bypassing sandboxes, skipping verification, or submitting out-of-scope changes.
If only final test passes are rewarded, the model might learn to “accidentally guess the right fix” or overfit to visible tests. If only process is rewarded, it may produce trajectories that are formally correct but fail the actual tests. Therefore, final and process rewards must be dynamically weighted based on task difficulty. Hidden tests, randomized test order, invisible test files, and sandbox isolation are necessary measures to prevent reward hacking.
3. Core Mechanism 2: High-Quality Trajectory Sampling and Curriculum Learning
The effectiveness of RL post-training depends heavily on trajectory quality. Each trajectory should include states, actions, and observations: states include file trees, error logs, test results, and the current patch; actions include searching symbols, reading files, editing code, running tests, and rolling back changes; observations include command outputs, test failure info, and static check results.
The training process typically involves three steps:
- Cold-start Supervised Fine-Tuning (SFT): Uses successful repair trajectories to teach the model the basic “search-locate-edit-verify” workflow.
- Rejection Sampling and Preference Optimization: Samples multiple trajectories for the same task, retaining those that pass hidden tests with minimal regressions to construct preference pairs. This teaches the model to distinguish between good and bad strategies.
- Policy Optimization: Continues optimization under verifiable rewards, biasing the model toward trajectories with high success rates, low regressions, and low costs.
Curriculum learning is equally important. Training should start with single-file, low-dependency tasks before gradually transitioning to multi-file, cross-module tasks with regression constraints. Failure trajectories should not be discarded; instead, perform failure replay to analyze where the model made a mistake—whether in localization, out-of-bounds editing, or insufficient verification. By compressing context and summarizing logs, long trajectories can be condensed into trainable key segments, significantly reducing training costs. These mechanisms enable the post-trained version to show a marked improvement over the non-post-trained version: the model doesn’t just “know more code,” it learns how to act within a repository.
4. Core Mechanism 3: Inference Orchestration and Cost Routing
Post-trained models require an orchestration strategy during the inference phase. A “Plan-Execute-Verify” loop is recommended:
- The Planner reads the task description and repository structure, breaking it down into localization, modification, and testing sub-goals.
- The Executor calls tools to search files, generate patches, and run tests.
- The Verifier checks test results, regression risks, and patch scope. If it fails, it rolls back and retries.
- Sub-agents handle low-risk sub-tasks like retrieval, log compression, and dependency analysis, reducing the context pressure on the main model.
Cost routing is also common: the main model handles key planning and final decisions, while secondary models handle summarization, retrieval, and simple edits. This is effective in cost-sensitive scenarios but must include verification gates so that secondary model outputs do not directly become final patches. The combo’s gains come from division of labor: the long-context base model provides global understanding, while the post-trained executor provides task-distribution-aligned editing and repair capabilities. The risk is error propagation; therefore, tests must be run and regression results recorded after each modification round.
5. Ablation Studies: Decomposing the “Improvement” into Explainable Sources
A reasonable ablation study should include at least four groups:
- Same base model + non-post-trained executor: Measures the gain from post-training itself.
- Same base model + post-trained executor: Observes the target approach.
- General flagship model + lightweight partner: Measures the baseline of ad-hoc combinations and cost routing.
- General flagship model + stronger partner: Measures the upper limit of “stacking larger models.”
In internal ablation evaluations, the post-trained combo scored approximately 58.2%, the same-source non-post-trained combo about 38.9%, and the general ad-hoc combo fell in the 20% to 21% range; the individual end-to-end match scored about 66.0%. These results indicate three points: First, the task distribution alignment brought by post-training is more effective than simply swapping partners. Second, combo orchestration amplifies the advantages of the post-trained executor. Third, absolute scores are still limited by test coverage and task difficulty, so specific benchmark results should not be extrapolated to mean that all programming tasks will double in performance. Statistically, confidence intervals, multi-seed results, and task stratification results should also be reported to avoid relying solely on averages.
6. Engineering Implementation Checklist
To reproduce similar improvements in a production environment, establishing the following closed loop is recommended:
- Isolated Execution Environment: Use containerized sandboxes to run tests, restricting network and file permissions.
- Data and Logging: Use object storage to save trajectories, patches, and test logs. Use logging services for search and auditing, and monitoring alerts to track timeout and regression rates. In general cloud environments like Baidu AI Cloud, these capabilities can be utilized as standard service categories.
- Anti-Pollution: Time-split training and evaluation sets, deduplicate tasks, keep hidden tests invisible, and periodically check for test leakage.
- Cost Control: Cache repository indexes, set timeouts and maximum turns, and use the main model for planning while secondary models execute—always maintaining verification gates.
- Reproducibility: Lock model versions, sandbox images, tool permissions, and random seeds. Record the reward and failure reason for each turn.
Finally, it is crucial to clarify the boundaries: doubling benchmark scores is not magic from a single model “getting smarter.” It is a systematic effect formed by verifiable rewards, high-quality trajectories, inference orchestration, and strict ablations. Developers should prioritize building evaluation and data feedback loops before iterating on reward functions and routing strategies. Enterprise users should make tiered decisions balancing cost, latency, and regression risk. Only by turning “Train-Infer-Eval-Feedback” into a closed loop can improvements in code agents be reproducible, explainable, and sustainable.
