Reinforcement Learning for Coding Agents: Long-Horizon Tasks and Evaluation Pitfalls

    Targeted reinforcement learning for coding agents can produce large gains on one long-horizon benchmark while leaving other benchmarks flat or worse. This article explains how to separate benchmark coverage, checkpoint comparisons, and evaluation scaffolds; why reviewer-style long-horizon benchmarks can cause broad score drops; what targeted RL actually changes in task design, environment-derived rewards, and trajectory-length control; how to report scaffold settings; what safety side effects to expect; and how to plan compute, data governance, and validation before treating a single score multiplier as evidence of general capability.

    Long-horizon software engineering tasks are becoming a central battlefield for coding agents: requirements are incomplete, repositories impose many constraints, a single change may span multiple files, and the agent must repeatedly validate work in a terminal. When a base model is put through targeted reinforcement learning for this kind of task, scores can sometimes separate sharply on one benchmark, then tie or fall behind on another. The more reliable conclusion is not that “twice the potential has been unlocked,” but that post-training pulls the model toward certain long-horizon tasks and certain review criteria. If the benchmark, scaffold, or comparison target is misaligned in any one respect, the multiplier cannot be extrapolated.

    Separate the comparison criteria first

    When reading results of this kind, check at least three things at the same time.

    First, does the lead appear only on a single evaluation? Long-horizon engineering benchmarks emphasize cross-module edits, implicit constraints, and reviewer-style vetoes. Terminal-operation benchmarks focus more on whether command sequences run successfully. Question-answering code-understanding benchmarks are closer to retrieval and local reasoning. These three distributions are different, and the same post-training run may raise only one of them.

    Second, are you comparing before and after versions of the same checkpoint? Continuing training on one open-source base model and then comparing it with a newer base model mixes in iteration of the base model itself and cannot be treated as a strict ablation.

    Third, is the evaluation environment the same? Open weights are often placed into an evaluator’s own agent scaffold: system prompt, tool permissions, retry strategy, and context truncation are all defined by the evaluator. Closed models more often use their recommended runtime. A home-field scaffold changes tool-calling habits and failure-recovery paths, so part of the score is “interface adaptation,” not pure model capability. Until a third party reproduces the result with a unified scaffold, the multiplier should be treated only as a clue.

    Why some benchmarks drop across the board

    After a long-horizon engineering benchmark changes from “hard-coded requirements” to “scoring changes by the standards a maintainer uses to review a change,” most models drop noticeably. Typical designs include: the prompt deliberately leaves gaps and names a defect on only one path; the scoring rule treats failure to fix the same class of issue, incompatibility with the repository’s existing input types, or breakage of unrelated behavior as an automatic veto. Ordinary unit tests may still pass, but the review score is zero.

    This kind of benchmark measures “a complete fix under an incomplete specification,” not “a patch that follows a literal instruction.” Models not trained on a similar distribution will optimize the one path named in the prompt and ignore symmetric paths and type branches. A score decline means the evaluation became harder; it does not automatically mean the model regressed. Conversely, a surge only on this benchmark does not prove that terminal operation or general code question answering became stronger at the same time. Targeted post-training, including task construction close to the review rules, will raise the score, but that is not the same statement as “comprehensive dominance.”

    What targeted reinforcement learning actually changes

    Public materials usually do not provide a complete algorithm. What can be reused is the methodological skeleton, not any one organization’s private recipe.

    Tasks and environments need to scale together, not just prompts get longer. Short tasks should retain basic editing, unit-test repair, and local refactoring so the policy does not forget stable behavior on short horizons. Long tasks should cover multi-file modifications, scientific computing scripts, performance hotspot localization, and safety checks in controlled environments. Each task category needs an automatically judgeable terminal state: tests passing, a performance threshold, static checks, or review rules, not just the model saying “done.”

    Rewards should come from the environment as much as possible, not from another round of vague preference scoring. In coding scenarios, executable signals include test diffs, type checks, whether benchmark latency crosses a threshold, and whether a diff goes outside allowed directories. Reviewer-style vetoes can be made into a rule set: missing the same class of path, breaking existing input types, or introducing large changes unrelated to the task should be recorded as failure. Rules should be written into the task description or scorer, and training and evaluation should use the same interpretation, avoiding “train by unit tests, deploy by review.”

    Post-training algorithms must explicitly manage trajectory length. Long-horizon coding episodes easily stretch out among errors, repeated file reads, and invalid retries. Once length oscillates back and forth, advantage estimates and truncation bias both grow, and the training curve can suddenly diverge on a scale of hours to days. Feasible controls include: applying a length penalty or early truncation to overly long episodes, and correcting value for truncated states; using a length target or quantile constraint so that trajectory lengths within a batch fall into a stable interval; and a curriculum that gradually relaxes the step limit, first stabilizing the policy on short tasks and then adding long tasks. After suppressing oscillation, training can run continuously for many days, and validation-set scores have a chance to improve monotonically. This is engineering stability, not mysterious capability multiplication.

    The following is an illustration of length constraints. It expresses only the control logic, not a training framework that can be put directly into production:

    1. def shaped_return(steps, success, max_steps, length_coef):
    2. # success comes from tests and review rules, not model self-report
    3. base = 1.0 if success else 0.0
    4. over = max(0, len(steps) - max_steps)
    5. return base - length_coef * over
    6. def should_truncate(steps, limit):
    7. return len(steps) >= limit or repeated_tool_failure(steps)

    Coefficients and caps must be selected on your own validation set. There is no universal “best length,” and an overly strong length penalty on short tasks encourages premature stopping.

    Treat the evaluation scaffold as a separate variable

    With the same weights, changing the system prompt, tool list, whether multiple retries are allowed, and how context is compressed can shift scores by a tier. Reports should therefore fix at least: scaffold version, tool permissions, maximum steps, temperature and number of samples, and whether failures are automatically rerun. If open and closed models run in different environments, present two columns side by side: “each model’s recommended environment” and “unified environment,” to avoid writing adaptation differences as model differences.

    Internal iteration can use a self-built environment for fast feedback, but external conclusions should preferably wait for independent reproduction. If a self-built benchmark shares the same source as training tasks, keep a set of repositories that never entered training sampling; otherwise the upward curve mainly reflects memorized review criteria.

    Safety capability gains should come with side effects by default

    After cybersecurity-style tasks are placed in a sandbox, the model becomes more willing to try boundary conditions, so a rise in safety-related success rates is not surprising. The side effect is that the policy may encounter unexpected escape or privilege paths inside the training sandbox. The responsible approach is to deploy escape detection and alerts in advance rather than waiting for manual spot checks; once an alert fires, freeze that checkpoint first, then audit the trajectory. External releases should tighten tool permissions, network, and filesystem access by default. If the business needs a looser security research environment, it should have a separate version, separate audit, and separate permissions; weights with relaxed restrictions must not be released as a general coding model.

    This section discusses only training governance and does not provide steps for discovering or exploiting vulnerabilities. Sandbox isolation, least privilege, and alerts are required infrastructure for post-training, not optional optimization.

    Compute and data in practice

    Long trajectories mean that GPU memory, logs, and object storage all scale up. In practice, episode logs, diff patches, and test outputs can be placed in object storage; container platforms can scale executors by task type; logs and monitoring can track length quantiles, truncation rate, and reward variance. If you use general cloud resources such as Baidu AI Cloud, group resources only by these categories: containers to run tests, object storage to retain trajectories, and monitoring and alerts to watch for divergence. There is no need to bind to a particular set of proprietary interfaces. For data governance, repositories and tests should be reproducible, and keys and production credentials must not enter trajectories.

    How to judge whether this post-training was worth it

    Whether it was worth it depends on the validation design, not on a single multiplier. It is advisable to keep at the same time: a long-horizon review benchmark, a terminal-task benchmark, a code question-answering or completion benchmark, and a regression set that does not overlap with training repositories. If only the long-horizon benchmark rises while the others stay flat, the targeted distribution has been saturated; the base model’s general capability has not been multiplied, though it may not necessarily have been broken. If short tasks or terminal tasks regress noticeably, the length curriculum or reward has overfit the review rules, and the data mix needs to be adjusted.

    For the party providing the base model, being selected for targeted post-training usually indicates that the weights are usable, the protocol is clear, and continued learning in application scenarios is allowed. For the party building applications, the goal should be to stabilize the engineering scenarios it cares about most: how tasks are judged, how trajectory length is controlled, how the scaffold is disclosed, and how safety boundaries are tightened by default. This is application-layer reinforcement learning engineering, not treating one benchmark multiplier as a comprehensive conclusion about the model.