Training Stability and Evaluation Bias in Long-Horizon Coding Agents

    Reinforcement learning on long-horizon coding tasks often conflates "the model got better" with "the model got better at a specific scoring pipeline." This article examines why benchmark score gaps rarely have a single cause, why long software engineering trajectories are hard to optimize, how reward shaping and length baselines improve training stability, and what a fair evaluation of coding agents actually requires. It closes with practical guidance on data mixtures and engineering practices for teams building their own coding agents.

    Training Stability and Evaluation Bias in Long-Horizon Coding Agents

    Reinforcement learning on long-horizon coding tasks makes it easy to confuse “the model is stronger” with “the model is better adapted to a particular scoring pipeline.” On the surface, swapping in a new reward, lengthening trajectories, and stabilizing training can push scores up noticeably. On closer inspection, the gap often comes down to whether tasks are underspecified, whether failures trigger automatic zero scores, and whether tool usage is drawn from the same distribution as the training environment. To apply these conclusions to real development workflows, evaluation design, execution scaffolding, and optimization objectives must be analyzed separately.

    Score Differences Usually Have Multiple Causes

    When the same base model ranks inconsistently across coding benchmarks, three overlapping factors commonly explain it.

    First, tasks shift from “fix one thing per the instructions” to “deliver to a maintainer’s review standard.” The prompt deliberately leaves gaps: it points out one defect on a path but expects the model to find similar issues, preserve compatibility with existing inputs, and satisfy implicit constraints around style, regression behavior, and interface stability. Passing ordinary unit tests may still earn a zero. Under this distribution, models without targeted alignment collectively score lower — which should not be read as a collapse in general capability.

    Second, if official scores are all produced on the same execution scaffold, and candidate policies are trained with RL inside that scaffold, there is a train–evaluation distribution advantage. Switch to a different command-line setup, different file permissions, or a different way of triggering tests, and tool-use habits, timeout handling, and retry policies all change. Score swings of a few points are common. This looks more like environment adaptation than a leap attributable to parameter scale itself.

    Third, benchmark redesigns change difficulty, scoring granularity, and veto rules simultaneously. Old and new scores should not be compared directly. If the benchmark authors and the training team share a highly consistent understanding of the scoring rubric, assume an information advantage exists until third-party scaffolding produces directionally consistent results.

    Therefore, a single-benchmark “doubling” neither proves a base model has been comprehensively surpassed, nor supports a claim of data fabrication. The sound approach: fix the task set, the scaffold, and the budget, then report means, variances, and failure types.

    Why Long-Horizon Coding Is Hard to Optimize

    Software engineering trajectories are far longer than short Q&A. A single task may involve reading a repository, locating the problem, editing multiple files, running tests, and fixing issues based on error output. Trajectory lengths range from dozens to hundreds of steps, and rewards are extremely sparse: most intermediate steps receive no dense signal, and only at the end do you learn whether tests passed or the patch is mergeable.

    This setup creates three optimization problems.

    Credit assignment degrades. When the run ultimately fails, it is hard to tell whether the model misread requirements early on, changed the wrong interface midway, or simply never ran the full test suite at the end. If advantage estimation looks only at the whole-trajectory return, policy updates become noisy and prone to oscillation.

    Length couples with quality. Longer search sometimes fixes an extra edge case; other times it just means rereading files and idle retries. If cost is not written into the objective, the policy learns to “take as many steps as possible” to gamble on an accidental pass. If the penalty is too heavy, it stops prematurely, leaving half-finished patches.

    Distribution drift. Repository languages, build systems, and test frameworks keep changing, and sampled trajectory lengths fluctuate. When return scales are inconsistent across batches, the learning rate looks unchanged but the effective update magnitude jumps — reward curves and trajectory lengths oscillate together.

    What Reward Shaping Needs to Solve

    The common industry practice is not to invent mysterious loss functions, but to estimate “whether it was done right” and “how much was spent” separately.

    A cost-aware reward can be written as a main reward for pass/fail, minus weighted costs for step count, tool calls, failed retries, and context bloat. The main reward must dominate the sign, or the policy will prioritize doing less work. The cost terms exist to prefer shorter, more stable trajectories among those that pass equally, and to suppress uninformative repeated exploration.

    Length-weighted return baselines make advantages comparable across trajectories of different lengths. Short trajectories have low variance and long trajectories high variance; with one crude shared baseline, occasional high scores on long trajectories dominate the gradient. Bucketing by length, or using a time-varying value baseline, mitigates the effect of “one rare, very long success” dragging the policy toward inefficient search. Group normalization, advantage clipping, and granting the main reward only at terminal states all serve the same purpose: reducing scale drift, not injecting knowledge into the model.

    These techniques can widen the gap against unaligned models on the same scaffold, especially when scoring is highly sensitive to implicit constraints. They do not automatically deliver proportional gains across repositories and toolchains. Calling improved training stability “a doubling of general capability” is not a sufficiently supported claim.

    Where Length Oscillation Comes From and How to Suppress It

    Length oscillation follows an observable pattern: average step count rises during some phase and pass rate ticks up, then timeouts and ineffective edits accumulate, pass rate falls, and the policy shrinks back to short trajectories. The usual cause is that exploration noise, timeout truncation, and reward scale changed together.

    Actionable stabilization measures include:

    • Impose a soft cap on trajectory length, treating overruns as the same termination as “incomplete,” to avoid endlessly rolling out very long samples.
    • Bucket sampling by length or task difficulty so each update batch keeps a relatively fixed mix of short, medium, and long tasks.
    • Track pass rate, edited line counts, test run counts, and timeout rates separately — never rely on a single scalar reward.
    • Deduplicate or add extra cost for repeatedly reading the same file or rerunning the same failing command, to reduce uninformative loops.
    • Update the value model or baseline only on a sliding historical window, so a single anomalous day of very long trajectories does not skew it.
    • Bind key hyperparameter changes to task-set versions, so curves remain reproducible.

    Illustratively, advantage estimation can stay extremely simple — the point is scale, not formulaic sophistication:

    1. advantage = (task_reward - cost_penalty - baseline[length_bucket]) / scale[length_bucket]
    2. advantage = clip(advantage, -clip_limit, clip_limit)

    Here task_reward is only set when there is a clear acceptance outcome, cost_penalty grows with effective tool calls, and baseline and scale are computed per length bucket. Without reliable bucket statistics, prefer conservative clipping over inventing “optimal coefficients.”

    What Counts as Fair Evaluation for the Trained Model

    Comparing coding agents should satisfy at least the following conditions.

    Task specification information should be published in tiers: fully specified, partially underspecified, and symptom-description-only. Underspecified evaluation may exist on its own, but must be labeled “review-style acceptance,” not blended with “spec-based fixes” into one total score.

    Veto rules must be machine-checkable. Similar defects outside the named path, fallback behavior for existing input types, and unrelated refactoring should all have public checking scripts. If grading depends on human taste without published criteria, external models will be systematically disadvantaged, and scores cannot be extrapolated.

    Scaffolding must be cross-checked. Run at least once in the “training-identical execution environment” and once in an independent, general-purpose scaffold, reporting tool permissions, timeouts, retry limits, and visible test scope. Publishing only same-environment results should be treated as an in-environment result.

    Budgets must be aligned. Compare step limits, context length, parallel attempt counts, and whether hidden tests may be viewed. Unbounded search and a single patch attempt are not the same capability.

    Failures must be classified. Distinguish misreading requirements, fixing the main path but missing similar issues, not running the full test suite, failing environment setup, and timeout truncation. When one failure category dominates, more RL steps often help less than changing the data or the scaffold.

    If third-party re-testing contradicts official results in direction, first suspect task filtering, hidden prompts, and retry policies — not immediately rewrite conclusions about base model capability.

    How Data and the Training Pipeline Should Work Together

    Reinforcement learning can only amplify behavioral differences already present in the data. If samples come mostly from game, 3D, or single-framework repositories, coverage of long-horizon editing, build systems, and regression constraints will be insufficient, and general coding trajectories will degrade. If training piles up only underspecified tasks that “score easily on one benchmark,” the policy learns to guess veto criteria rather than to read specifications. Both directions can lower real delivery quality.

    A more robust data mixture allocates by capability target, not by pass rate on a particular benchmark: clearly specified fixes, fixes requiring self-discovery of similar defects, compatibility-preserving changes, and counterexamples where excessive modification must be rejected. Each sample should retain the repository snapshot, allowed modification paths, visible tests, and hidden acceptance criteria, to prevent leaking evaluation answers during training.

    For the training stage, start with supervised short patches, then run small-step RL on a fixed scaffold, changing only one reward type or one task category per round. If pass rate gains come with more unrelated edits or crashes on hidden tests, treat it as reward hacking, not capability improvement. Use cost penalties and length baselines as stabilizers, and run periodic regression on scaffolds not involved in training.

    Bringing It Into Engineering Practice

    Teams building their own coding agents should not chase rankings on a single public benchmark. More useful acceptance criteria: on historical defects in your own repositories, fix the information asymmetry between humans and agents, then measure one-shot pass rate, human rework line counts, and rollback rate. Use container platforms to isolate dependencies, store trajectories and patches in object storage, record commands, timings, and test outputs in a logging service, and point monitoring and alerting at timeout rates and anomalous trajectory lengths. Generic offerings such as container platforms, object storage, logging services, and monitoring — for example on Baidu AI Cloud — can be assembled this way to build reproducible experiments, without binding your conclusions to any single model or proprietary evaluation suite.

    The conclusions reduce to three sentences. Underspecification plus veto-based scoring systematically depresses unaligned models; RL in the same scaffold inflates in-environment scores; cost penalties and length baselines mainly improve training stability and search efficiency. All three can explain “looks much stronger,” but none alone proves a multiplied improvement in general coding capability. Trustworthy comparison always means: publish the rules, cross-check scaffolds, align budgets, and break down failure types.