Reinforcement Learning Post-Training for Coding Agents: How It Works and How to Evaluate It

    Unlike open-ended Q&A, coding tasks produce verifiable outcomes: whether tests pass, whether a patch builds, and whether regressions are introduced can often be judged automatically. This article explains why reinforcement learning (RL) fits post-training for coding agents, how to build a closed-loop RL pipeline in code environments, why specialized post-training can widen the gap with base models, and how to design controlled experiments that avoid misleading conclusions. It also covers multi-model collaboration, leakage prevention, and how to preserve gains in production.

    Unlike open-ended Q&A, coding tasks produce verifiable outcomes: whether tests pass, whether a patch builds, and whether regressions are re-introduced can often be judged automatically. This property makes reinforcement learning (RL) a natural fit for post-training coding agents — the policy can explore repeatedly inside real toolchains without humans scoring every attempt. Claims like “the tuned model dramatically outperforms the base model” usually aren’t mysterious; they result from task distribution, rewards, sampling, and evaluation protocols acting together. This article breaks down that path from an engineering perspective, so that controlled experiments aren’t misread as product rankings.

    Separate Base Model Capability from Task Strategy

    General-purpose LLMs already have the basics: reading and writing code, calling tools, and revising across turns. Software engineering scenarios demand more — locating defects in long contexts, following repository conventions, keeping changes narrowly scoped, and adapting after failures based on feedback from the compiler, tests, and static analysis. These behaviors are closer to strategies than to memorized knowledge.

    Post-training typically follows three paths. Supervised fine-tuning (SFT) teaches the model “what a good solution looks like” using high-quality patches and reasoning traces. Preference alignment nudges the model toward the more maintainable of two candidates. RL lets the model sample multiple trajectories itself and update its policy from environment feedback. For coding agents, RL’s value lies in covering branches that supervised data can barely enumerate: tests going red then green, dependency installation failures, partial fixes introducing new errors, or the need to roll back to a previous patch.

    So when comparing a post-trained model against a base model, keep the tools, timeouts, and test oracle identical. If one side gets multi-turn self-correction and the other gets a single generation, the score gap can’t be attributed to the training algorithm.

    How RL Closes the Loop in Code Environments

    A minimal loop looks like this: given a problem and a repository snapshot, the agent produces a sequence of actions, the environment returns a computable reward, and the trainer keeps only informative trajectories.

    The action space shouldn’t be just “output the entire file.” A more robust action space includes retrieving symbols, reading relevant files, running targeted tests, committing small incremental patches, viewing diffs, and deciding to stop. If actions are too coarse, credit assignment becomes difficult; if too fine, trajectories get long and sampling costs explode.

    Rewards should come from objective signals — not from another model judging whether code is “elegant.” Usable signals include: whether target tests pass, whether existing tests regress, whether patch line count is out of control, whether irrelevant directories were touched, whether the build succeeds, and how many new static-analysis warnings appeared. The main reward should be sparse and unambiguous — for example, all target tests passing counts as positive, while a timeout or broken build counts as negative. Process rewards should stay auxiliary, to keep the model from gaming the score by “running more tests.”

    A schematic reward aggregation can stay simple and auditable:

    1. reward = pass_target * 1.0
    2. - regression * 0.6
    3. - build_fail * 0.8
    4. - clip(changed_lines / budget, 0, 1) * 0.2
    5. - timeout * 1.0

    Weights must be tuned independently on a validation set — never iteratively against the final leaderboard. Otherwise the improvement is just overfitting the evaluation script.

    Don’t collect only the shortest “success on first try” trajectories. Trajectories that recover from failure often teach the model to read error messages better than direct successes do. Also scrub for leakage: if problem descriptions contain the answer, test names point directly at the lines to change, or reference patches remain in the repository, the reward will be inflated.

    Why Specialized Post-Training Can Widen the Gap

    A base model is optimized for broad next-token prediction or general conversational preference — it isn’t sensitive to “change less, change correctly, keep it reversible.” Software-engineering-oriented post-training pushes the policy toward a different distribution: localize first, hypothesize, make a small patch, then verify. If the evaluation set happens to emphasize multi-file defects, long logs, and regression constraints, the specialized policy will look much stronger.

    The gap typically widens for four reasons. First, more exploration: the model can try several patches per problem, while a base model’s single sample often stops at a superficial fix. Second, rewards penalize regressions, so the model learns not to break existing behavior. Third, explicit stopping criteria cut off meaningless long reasoning. Fourth, training repositories resemble evaluation repositories in language, build system, and defect type — out-of-distribution tasks won’t benefit equally.

    So claims like “2x better” are only meaningful under the same metric, same problem count, and same attempt budget. Mixing pass rates, win/loss records, and score ratios makes cross-comparison impossible. Goal-style scoring is also easily dominated by hard problems’ point values, so rankings can swing wildly on small samples.

    Single-Model vs. Two-Model Collaboration Aren’t the Same Thing

    In practice, teams often use a stronger model for main planning and a faster model for retrieval, summarization, or subtask execution to control cost. This arrangement changes system performance, but you can’t simply credit the system’s score to a single model.

    The primary model decomposes the problem and produces the final patch; the secondary model reads logs, lists relevant files, and generates candidate retrieval queries. The benefit depends on clean interfaces: subtasks need well-defined inputs and outputs, and failures must escalate back to the primary model rather than silently accepting low-quality results. If the secondary model frequently misses key errors, the primary model will keep iterating on a wrong premise — and team scores can end up below either model’s individual score.

    Evaluations should report three setups: primary model alone, primary-secondary division of labor, and the secondary model swapped for a different strategy of equal cost. This distinguishes “the collaboration protocol works” from “we just swapped in a stronger executor.” Cost matters too: at the same pass rate, if total tokens, tool calls, or wall-clock time double, the setup may not be better in practice.

    Designing Controlled Experiments That Don’t Mislead

    Split experiments into individual and team tracks, but define them upfront. The individual track measures a single policy’s pass rate within a fixed attempt budget, average patch size, and average time. The team track measures the end-to-end result of the multi-role system, recording separately how often the primary model was escalated to.

    At minimum, your comparison should include: the base model without this post-training, the same base model plus SFT, SFT plus RL, and an ablation that changes the regression penalty in the reward. Change one factor at a time. Stratify the problem set by language, repository size, and whether cross-file changes are needed, and report stratified pass rates — not just a total score.

    Statistically, watch confidence intervals and problem difficulty. If a few repositories account for most failures across a few hundred problems, rankings are hostage to those repositories. Publish failure types: environment setup failures, flaky tests, misread requirements, oversized patches, and correct fixes that introduced regressions. Environment failures should be fixed in the evaluation infrastructure, not counted against the model.

    Leakage prevention is part of experiment design too. Isolate training trajectories, retrieval corpora, and evaluation repositories; time-based splits beat random splits; reference answers must never be reachable from the agent’s workspace. The more tightly post-training fits the answers, the more fragile the model is in production.

    Preserving Gains After Deployment

    Once offline pass rates improve, still roll out gradually on real tickets. Observable metrics include: first-submission acceptance rate, human rework rate, average files touched per change, rollback rate, sensitive-directory access counts, and tool failure rate. Constraints not encoded in the reward — licensing, secret scanning, permission boundaries — must be enforced by gateways outside the policy, not left to the model’s judgment.

    When repository builds are slow, run the test subset relevant to the change first, then run the full suite on candidate patches. This two-phase verification must match the reward definition used in training, so the model doesn’t just adapt to “cheap tests.” Logs, diffs, and final test results should land in object storage or a logging service for auditing incorrect rewards. Monitoring and alerting should catch pass-rate spikes and tool timeouts — without tying the article to any particular vendor’s proprietary interfaces.

    A sensible iteration order: first clean up the verifiable environment and leakage controls, then use SFT to stabilize action formats, then run small-scale RL to verify the reward can’t be gamed, and finally expand task distribution. If the reward can be cheated by “deleting tests” or “skipping builds,” fix the environment before adding training steps.

    Conclusion

    Visible gains in coding agents come from turning verifiable feedback into stable training signals and keeping the evaluation protocol consistent with real toolchains. RL amplifies exploration, error correction, and regression constraints — it doesn’t automatically make every language and repository equally stronger. Two-model collaboration needs protocol and cost evaluated separately. Only with stratified metrics, ablations, and failure attribution in place can score differences guide the next round of post-training — rather than remaining an unreproducible comparison contest.