How Reinforcement Learning Breaks Through the Long-Horizon Coding Bottleneck

    This article explains why long-horizon coding tasks are difficult for supervised fine-tuning alone and how reinforcement learning helps. It covers reward design that balances test outcomes with token and tool-call costs, the stability problems caused by rollout length oscillation, and why benchmark scores vary across harnesses and evaluation versions. It closes with practical guidance for training, data, evaluation, and infrastructure teams.

    1. The Starting Point: Why Long-Horizon Coding Is Hard for Reinforcement Learning

    In coding capability training, supervised fine-tuning is good at teaching a model to produce code that looks correct. Real development work demands something else: locating a problem inside a context of hundreds of thousands of tokens, editing across multiple files, running tests, rolling back and retrying based on errors, and repeating until everything passes. These tasks have sparse feedback and extremely long trajectories, so imitation alone struggles to converge. That is where reinforcement learning comes in.

    The core observation in the original discussion is that a general-purpose large model scored lower on public coding leaderboards than a specialized agent built on top of it with reinforcement learning, and the gap was substantial. To judge whether such a gap is credible, three things must be separated first: model capability, agent harness capability, and the scoring criteria of the evaluation set itself. Mixing the three when discussing benchmark numbers makes distorted conclusions almost inevitable.

    2. Reward Design: From Outcome-Only to Outcome Plus Cost

    In long-horizon tasks, if the reward depends only on whether the final tests pass, the model learns many “inefficient but lucky” strategies, such as repeatedly brute-forcing reruns, generating excessively long patches, or traversing files without purpose.

    Two common improvement approaches in the industry are:

    1. Reward with cost penalties: convert token consumption, number of tool calls, and execution time into negative terms, weighted against the success reward.
    2. Length-weighted reward baseline: normalize advantage estimates by trajectory length or cost buckets, so long trajectories do not naturally dominate the variance.

    Illustrative expression (not a specific product interface):

    1. # Pseudocode: outcome reward + cost penalty + bucketed baseline
    2. reward = success_bonus * passed_ratio - alpha * token_cost - beta * tool_calls
    3. advantage = (reward - baseline_by_length_bucket[len_bucket]) / std_by_bucket

    Note that when penalty coefficients are too large, exploration is suppressed and the model tends to “stop early and submit a blank answer”; when they are too small, the setup degenerates into pure outcome-driven training. In practice, teams usually sweep the coefficients and watch for inflection points in two curves: pass rate and average cost.

    3. Rollout Length Oscillation: The Underrated Stability Killer

    The most typical sign of instability in reinforcement learning training is sampled trajectory length swinging violently between a few thousand and tens of thousands of tokens, which brings exploding return variance, frequent gradient clipping, and a jagged training curve. There are three main causes: the policy wavering between “deliberate thinking” and “careless speed”; excessive length differences within a sampling group distorting relative advantages; and memory or batch constraints forcing truncation, with truncated samples fed back as failures.

    Actionable remedies include: bucketed sampling and bucket-wise normalization by length; marking truncated trajectories separately instead of scoring them as failures outright; limiting the length spread within a single group; introducing length smoothing regularization; and on the training side, using sequence parallelism and more stable numerical precision strategies to reduce long-sequence gradient noise.

    4. Evaluation Credibility: Same Leaderboard, Different Scores

    The original discussion raises a key fact: the same model scored progressively higher across three different runtime environments — lowest in a specialized agent command-line environment, middle in the vendor’s own coding command-line environment, and highest in the evaluator’s general runtime environment. This shows that a considerable share of the score difference comes from the harness rather than the weights.

    Next is the change in evaluation criteria. When the evaluation version shifted from “requirements fully specified” to “large blanks left open, with veto items set by the standards of open-source maintainers reviewing pull requests,” most models’ scores dropped sharply. Typical zero-score cases include: identical defects in other paths within the specified scope left unaddressed, incompatibility with input types already present in the repository, and ordinary unit tests passing while boundary cases fail. Such standards are closer to real engineering acceptance, but they also mean models without targeted adaptation will inevitably lose points.

    Therefore, to judge whether a benchmark number is credible, fix three things before comparing: the same harness, the same evaluation version, and the same sampling and prompting configuration. Also report three metrics — pass rate, average cost, and truncation rate — rather than a single number.

    5. Practical Recommendations for Teams

    • Training side: solve stability first (bucketing, truncation handling, length regularization), then tune reward weights; reversing the order leads to repeated rollbacks.
    • Data side: prioritize adding long-horizon trajectories that span files and require multiple rounds of tool calls, rather than piling up isolated short samples.
    • Evaluation side: build an internal fixed benchmark, retain raw logs and failure samples, and distinguish “capability problems” from “harness problems.”
    • Engineering side: use container platforms for isolated execution, object storage to save trajectories, and logging services with monitoring and alerting to track training and evaluation metrics; Baidu AI Cloud can provide corresponding support in these general infrastructure categories, with specific capabilities subject to the official documentation.

    The conclusion is not complicated: the so-called “2x benchmark score” is more likely the combined result of reward design, training stability, and evaluation environment. Breaking the variables apart and verifying them one by one is the right way to assess the real capability of a coding agent.