Reinforcement Learning Post-Training for Code: Why the Same Base Model Shows a Multi-Fold Gap
This article explains why code-specialized models post-trained with reinforcement learning can outperform the same general-purpose base model by a wide margin across coding benchmarks. It breaks the gap down into three factors: consistency between the evaluation harness and the training environment, hidden constraints in scoring rules that can veto an otherwise passing patch, and the trade-off in how capability budget is allocated during post-training. It then offers a reusable practice framework: a layered evaluation matrix, key points for constructing training data from real repository history, and an ablation order for attributing score changes. The takeaway is to treat benchmark numbers as a reference signal rather than a conclusion.}
1. Background: Why “Same Base, Different Post-Training” Opens a Multi-Fold Gap
A common pattern in engineering practice is that, starting from the same general-purpose base model, a specialized model post-trained with reinforcement learning for code tasks can significantly outperform the original general version across multiple coding benchmarks, sometimes reaching more than twice the score on certain leaderboards. This is not mysterious. It is the combined result of three forces: whether the evaluation environment matches the training environment, whether the scoring rules can be optimized against, and how the model’s capability budget is allocated.
It is worth stressing that cross-leaderboard comparisons are only meaningful under the same conditions: same environment, same scoring criteria, and same budget. Once these three diverge, the numeric gap usually cannot be attributed to model capability itself. The following sections unpack each layer.
2. Factor One: Consistency Between Evaluation and Training Environments (The Harness Effect)
A policy trained with reinforcement learning is highly sensitive to its “action space” and “observation format.” The action space refers to the set of tools the model can call and the calling protocol; the observation format refers to how repository context, error messages, and test output are organized. If the model only ever saw one tool orchestration and prompt template during training, its success rate typically drops noticeably once the execution framework is swapped.
A similar pattern is visible in public industry evaluations: the same model scores highest under an execution framework from the same source as its training, dips slightly when switched to the vendor’s own command-line interface, and may recover when switched to the evaluator’s general-purpose execution framework. This indicates that a substantial share of the score comes from “protocol adaptation” rather than pure code reasoning ability.
Engineering recommendations:
- Fix the evaluation execution framework, and clearly state its version and prompt template in the report;
- Have training and evaluation share the same tool descriptions and failure-feedback format wherever possible;
- If a cross-framework comparison is unavoidable, run a “protocol alignment experiment” first to quantify the score gap introduced by the framework.
A schematic evaluation call skeleton (pseudocode):
def run_task(model, repo, task_spec, harness):obs = harness.build_observation(repo, task_spec)for step in range(MAX_STEPS):action = model.plan(obs) # structured action: read/write files, run tests, retrieveresult = harness.execute(action) # unified sandbox executionobs = harness.append(obs, result)if harness.is_solved(obs):return True, stepreturn False, MAX_STEPS
3. Factor Two: Hidden Constraints in Scoring Criteria and One-Vote Vetoes
The second source of divergence comes from scoring details. Some high-difficulty leaderboards deliberately leave large gaps in the prompt, no longer spelling out every requirement, and instead adopt standards close to how maintainers of open-source projects review pull requests, with several “one-vote veto” items attached. Typical cases include:
- Only a defect on one call path is required to be fixed, while the same class of defect also exists on another path;
- Existing input types or historical usage elsewhere in the repository are not kept compatible;
- The change introduces an implicit behavior change: unit tests pass, but hidden cases fail;
- Necessary boundary handling, logging, and consistency of error semantics are missing.
The defining trait of such rules is that “passing ordinary cases does not equal scoring points,” so models without targeted adaptation generally lose points. When the leaderboard and the training side come from the same source, the training side has a fuller grasp of scoring preferences, and its scores are naturally higher. This suggests that a leaderboard score should be understood as a composite metric of “capability + rule adaptation.”
4. Factor Three: Capability Budget Allocation and the Seesaw Effect
A general model must simultaneously cover broad tasks such as multimodal understanding, long-text processing, and office and research work, whereas a code-specialized model only needs to be strong enough along the code dimension. During post-training, there is a clear trade-off among different capabilities: over-strengthening one direction (for example, longer chains of thought or more aggressive exploration) often weakens another (for example, response latency, instruction-following stability, or code conciseness).
A commonly observable pattern is that a version with stronger agent capabilities may actually score lower on pure coding, and only months later does the community bring coding ability back to near the original level on some sets through a more balanced training mix and inference-budget control. This shows that “capability trade-offs” are a matter of training mix, not a model ceiling.
5. A Reusable Practice Framework
5.1 Build a Layered Evaluation Matrix
It is advisable to split evaluation into four layers to avoid a single number misleading decisions:
- Syntax and compilation layer: whether it can produce a buildable patch;
- Unit verification layer: pass rate on public cases;
- Hidden constraint layer: boundaries, compatibility, and regression risk;
- Long-horizon task layer: engineering tasks spanning multiple files and steps that require retrieval and verification.
5.2 Key Points for Training Data Construction
- Build “defect-fix” samples from the commit history of real repositories, preserving the original context;
- Construct “same defect, multiple paths” samples to suppress the short-sighted strategy of fixing only one spot;
- Add regression samples to penalize changes that break existing behavior;
- Apply preference optimization to tool-call trajectories, rewarding “verify before modifying” behavior.
A minimal structure example for preference data:
{"task_id": "repo-1024","context_files": ["src/a.py", "src/b.py"],"rejected": "Only src/a.py is modified; the same branch in src/b.py is left unhandled","chosen": "Extract a shared validation function called in both places, with a regression case added"}
5.3 Attribution Method for Gains
When scores change, run ablations in this order: first fix the framework variable, then fix the prompt template, then fix the decoding budget, and only then compare model weights. Only after the first three are aligned can the remaining difference be attributed to the post-training strategy.
6. Conclusion
A huge gap in coding evaluations is usually not a single-point capability difference, but the combined result of “execution framework consistency + scoring rule adaptation + capability budget allocation.” For development teams, a more pragmatic approach is to build a layered evaluation matrix, fix the evaluation protocol, apply preference optimization with real repository samples, and treat leaderboard numbers as a reference signal rather than a conclusion. If large-scale training and evaluation workloads need to be supported, a stable and reproducible experiment pipeline can be built on top of general-purpose cloud capabilities such as container platforms, object storage, message queues, and monitoring and alerting.
