Reinforcement Learning for Coding Agents: Evaluation Bias and How to Improve It
Reinforcement learning can improve coding agents, but benchmark gains do not necessarily indicate stronger general-purpose programming ability. This article examines how task definitions, hard-fail criteria, execution harnesses, and reward design shape evaluation results. It also outlines ways to stabilize long-horizon training, validate improvements across environments, and build reproducible internal evaluations for production deployment.
Where the Problem Starts
Software engineering agents typically need to read code in real repositories, edit multiple files, run tests, and iterate on failures. These tasks involve long trajectories, sparse feedback, and success criteria that extend beyond passing unit tests. Reinforcement learning seems like a natural next step: treat a complete repair attempt as a trajectory, construct rewards from test results, review feedback, and resource consumption, then update the policy.
In practice, a confusing pattern often emerges. With the same generation of base model, changing the training data and execution environment can produce a large lead on one leaderboard. Yet that lead shrinks substantially in third-party evaluations or under a different command-line execution framework.
The scores are not necessarily wrong. The mistake is treating adaptation to a particular scoring system as general programming ability. Separating the two requires examining task specifications, execution environments, reward calculations, and independent validation.
Define the Capabilities Before Measuring Them
Long-horizon coding involves at least four distinct capabilities. They should not be collapsed into a single score without explanation.
- Fault localization: Find the paths that actually need changes despite an incomplete description, rather than editing only the files named in the prompt.
- Behavior preservation: Fix the target issue without breaking existing input types, edge cases, or calling conventions.
- Closed-loop verification: Design or extend checks, interpret failure logs, and converge within a limited number of steps.
- Cost control: Avoid unrelated large changes and manage context usage, tool calls, and repeated attempts.
If an evaluation rewards only making the target unit tests pass, the policy will learn to produce minimal patches. If it also requires fixing equivalent issues across related paths while preserving existing inputs, the policy must reason at the repository level. These scores measure different things.
Public reports should specify whether agents can inspect hidden tests, whether a submission explanation is required, whether failed attempts can be retried, and what timeout and tool budgets apply. Without these conditions, scores cannot be compared meaningfully.
Underspecified Prompts and Hard-Fail Criteria
An evaluation designed to resemble maintainer review may deliberately leave requirements incomplete. The prompt might identify a defect in one path while equivalent defects exist elsewhere. Alternatively, a patch might pass newly added tests but reject inputs that the repository previously accepted.
The scoring rules can make these conditions automatic failures: even if all ordinary unit tests pass, the submission receives zero credit.
This design has a reasonable basis. Open-source review evaluates behavioral contracts, not just individual assertions. But it also creates a strong selection effect:
- Models unfamiliar with the hard-fail criteria may follow the prompt literally, make a local repair, and systematically lose points.
- Models whose training data or rewards implicitly encode the same criteria may proactively inspect related paths and check compatibility, producing an apparent jump in performance.
- When a benchmark changes from explicit requirements to underspecified prompts with hard-fail criteria, scores may fall across most models. That does not mean the base models suddenly became worse; the task distribution changed.
Benchmark versions should therefore be treated as different exams. Using a new version’s scores to dismiss work evaluated on an older version, or using an advantage under proprietary rules to claim broad superiority, is not rigorous.
A better approach is to publish the distribution of hard-fail categories: missed equivalent defects, broken existing inputs, missing regression coverage, out-of-scope changes, flaky tests, and so on. Report performance by category rather than only as an aggregate score.
The Execution Harness Is Part of the Policy
A coding agent is not a model operating alone. The system that completes a task consists of the model, tool protocol, context pruning, retry policy, and termination conditions. This execution framework is commonly called a harness.
If reinforcement learning samples trajectories within a particular harness, the policy learns its conventions: tool response fields, the level of detail in error messages, when to reread files, and how to summarize context as the window fills up.
Those habits may stop working when the harness changes. Common sources of performance loss include:
- Different tool schemas, parameter names, and response structures, reducing tool-call success rates.
- Different terminal-output truncation behavior, hiding critical stack traces.
- Different support for parallel edits, patch formats, and rollback, making long trajectories more likely to reach dead ends.
- Different system-prompt defaults about whether to keep exploring under uncertainty, changing both step counts and costs.
A score obtained in the training harness therefore measures the combined system. To compare base models, evaluations should use at least one fixed third-party harness and separately report results from each model’s native harness.
Strong performance in both is more consistent with a capability improvement. Strong performance only in the training harness is more consistent with environment overfitting.
Evaluation reports should consistently record:
- Maximum number of steps.
- Per-step context limit.
- Available tools.
- Whether failure feedback includes complete logs.
- Whether the model is allowed to modify tests.
These variables can affect scores more than switching between adjacent base-model versions.
Reward Design: Cost Penalties and Length-Aware Baselines
In long-horizon tasks, a sparse final pass-or-fail signal is difficult to learn from. If intermediate rewards merely encourage tool use, the policy may stretch trajectories, trading many more attempts for a small increase in success rate. Two adjustments address these problems.
Cost Penalties
Cost penalties incorporate tool calls, patch size, repeated reads, and total latency into the reward. A successful but excessively expensive trajectory should receive less reward than a shorter successful one.
This discourages unrelated refactoring, but it has a trade-off: the model may stop exploring too early and miss equivalent defects that the prompt did not mention. Penalty coefficients should be tiered by task difficulty rather than applied as one global constant.
Length-Aware Reward Baselines
Length-aware baselines aim to reduce variance in advantage estimates. Returns from long trajectories tend to vary more. If all samples share a single baseline, differences between short and long trajectories can distort comparisons and destabilize updates.
Bucketing trajectories by length, or using length as an input to the baseline model, helps compare failed trajectories with others of similar length. This is a training-stability technique, not new programming knowledge. It can make optimization smoother, but it cannot create semantic understanding from nothing.
A trajectory’s scalar reward can be understood as a conceptual combination, not as a fixed formula used by any particular product:
R = task success score+ behavior preservation score- cost penalty(tool calls, lines changed, latency)- hard-fail penalty(missed equivalent defects, broken existing inputs)For advantage estimation, use the average return within the sametrajectory-length bucket as the baseline, rather than the global average.
Every component should be auditable. If the success score quietly includes undisclosed stylistic preferences, someone attempting to reproduce the results cannot determine whether the gains come from the algorithm or from hidden rules.
Oscillations in Trajectory Length
During reinforcement learning, episode lengths often swing back and forth. In one round, the policy becomes conservative and stops after a few steps, lowering success rates. In the next, it retries extensively to recover performance. Trajectory lengths surge, gradient noise increases, and the policy destabilizes again.
This is especially pronounced in coding tasks because reading one more file may uncover decisive evidence—or simply waste context.
Practical stabilization methods include:
- Use a soft length limit. As the agent approaches the limit, reduce the logit associated with continued exploration rather than abruptly truncating the episode and marking the entire trajectory as a failure.
- Increase cost penalties with step count. Allow search early in the trajectory, then push for convergence later.
- Distinguish useful information gathering from repeated reads. Track steps that reveal new information separately and penalize redundant reading.
- Use grouped baselines or clipped advantages. Prevent a few extremely long successful trajectories from dominating updates.
- Apply curriculum learning. Start with small repositories and single defects, progress to equivalent defects across multiple paths, and introduce underspecified prompts last.
These methods improve the optimization process. Evidence should include learning curves, trajectory-length variance, and how well gains persist across different harnesses—not just the final score on an in-house leaderboard.
Why a Lead on One Benchmark Does Not Generalize Automatically
When one organization controls the evaluation set, scoring rules, and execution harness, large score differences should trigger three checks.
1. Are the Benchmark Versions Comparable?
If a new version changes prompt completeness and hard-fail rules, a broad score decline reflects a distribution shift. Rankings on the new version alone do not show whether previously demonstrated capabilities have been preserved.
2. Is the Improvement Tied to the Harness?
If an agent leads in its training harness but the lead narrows elsewhere, some of the gain comes from interface adaptation. That still has engineering value, but it should be described as system optimization—not as a doubling of general-purpose base-model capability.
3. Has Training Shifted the Capability Mix?
If substantial training resources are redirected toward games, 3D environments, or specific interface tasks, general repository repair may receive less attention. Conversely, concentrating on one defect category can hurt performance on other distributions.
Evaluation should examine profiles across multiple benchmarks, programming languages, and repository sizes rather than rely on a single result.
Credible conclusions require all of the following:
- Public scoring rules and a fixed benchmark version.
- At least one execution harness decoupled from training.
- Success rates, hard-fail category distributions, step counts, and costs—not just one percentage.
- Separate scores for underspecified tasks and tasks with explicit requirements.
Applying These Lessons in Enterprise Deployments
Teams building coding assistants do not need to chase a single external leaderboard. An internal gold-standard evaluation set is often more useful.
Sample real defect reports and ask maintainers to annotate the paths that must change, the inputs that must remain supported, and the permitted scope of modifications. Use the same hard-fail categories in training and evaluation, but keep evaluation repositories out of training.
Keep the harness simple and logs complete. Establish reproducibility before introducing reinforcement learning.
Before reinforcement learning, use supervised fine-tuning and rejection sampling to establish reliable behavior around reading failure logs and revising patches. Rewards should cover automatically verifiable properties: test outcomes, static checks, and whether a patch exceeds its allowed scope.
Do not combine human preferences and automated scores into an opaque total. After deployment, monitor regressions by repository language, size, and defect type, and set budget alerts for trajectory length and cost.
If improvements appear only on evaluation sets that closely match the training harness, treat the system as having failed acceptance criteria.
For cloud-based training, object storage can hold trajectories and patches, message queues can smooth demand and schedule sampling, container platforms can isolate command execution, and logging and monitoring can track steps, failure categories, and unit costs.
These are general infrastructure capabilities. Their value lies in making experiments traceable, not in tying the system to a proprietary evaluation.
Conclusion
Improving long-horizon coding through reinforcement learning depends on whether training data covers real review standards and whether optimization remains stable—not on the size of a lead on one leaderboard.
Underspecified prompts, hard-fail criteria, proprietary harnesses, and cost-sensitive rewards all change what a score means. Reporting task definitions, execution harnesses, reward design, and cross-validation separately is essential for distinguishing general capability gains from overfitting to a particular set of rules.
