Technical Breakthroughs in Long-Horizon Coding for Chinese LLMs

    This article examines the shift in coding LLM evaluation from single-pass correctness to long-horizon task reliability. It explains why multi-turn engineering tasks are difficult, outlines a five-dimension capability matrix, presents a reference architecture for long-horizon agents, and offers practical guidance on evaluation and rollout. Readers will gain a constraint-driven, evidence-based, and rollback-ready framework for assessing and deploying coding agents.

    1. From “Correct on the First Try” to “Correct Throughout”: A Shift in Evaluation

    For the past few years, the way we evaluated code LLMs was highly uniform: provide a function signature, a bug description, or an algorithm problem, and check whether the model produces the correct answer in a single generation. This type of evaluation essentially follows an “exam mindset,” emphasizing first-attempt hit rate. The metrics are clear and reproduction costs are low, making it suitable for quick side-by-side comparisons.

    But real software engineering is rarely built in one pass. An engineer’s work loop is closer to: write a first implementation, run benchmarks or unit tests, read performance and failure information, locate the bottleneck, switch algorithms or data structures, and run validation again, repeating until the constraints are met. This process can last hours or even days, accompanied by extensive log searching, dependency troubleshooting, and regression verification.

    As a result, the industry has begun shifting its focus from “first-attempt accuracy” to “long-horizon task capability”: whether a model can keep the goal from drifting across hundreds of interactions, whether it can make effective attributions from failure signals, and whether it can proactively switch strategies instead of mechanically retrying. The significance of this shift is that the evaluation target changes from “generating a piece of code” to “completing a piece of engineering.”

    2. Why Long-Horizon Tasks Are the Real Technical Battleground

    The difficulty of long-horizon tasks lies primarily in error accumulation and goal retention. Single-turn generation only needs to satisfy local constraints; long-horizon tasks require the model to make decisions in every turn that do not break the global objective.

    The main challenges can be broken down into four layers:

    • Context management: interaction history, benchmark output, logs, and code snippets expand rapidly. Once the window is exceeded, compression and summarization are required, and the compression process can easily lose critical constraints, such as “recall must not fall below a certain threshold.”
    • State consistency: multiple rounds of modification leave the codebase in an intermediate state. The model needs to maintain a reliable “current set of facts,” including modified files, ruled-out approaches, and failure reasons.
    • Tool-call orchestration: actions such as compilation, testing, benchmarking, static checks, and version comparison need to be correctly ordered and parallelized. As the number of calls rises, so do error rates and noise.
    • Termination judgment: deciding when a task has “met the bar” rather than continuing pointless optimization requires explicit acceptance criteria rather than subjective feeling.

    A common failure mode is “thrashing retries”: the model repeatedly tweaks parameters along the same line of thinking, treats log noise as signal, and the number of turns skyrockets while the metrics stay flat. Truly valuable long-horizon capability shows up as staged hypotheses, validation, refutation, and replanning.

    3. A Multi-Dimensional Capability Matrix: What a Single Score Misses

    To evaluate coding agents, it is advisable to cover at least five dimensions and avoid single-point conclusions:

    1. Bug fixing and repository-level understanding: locating and fixing issues in real codebases, testing cross-file reasoning and regression control.
    2. Natural language to a complete repository: generating a runnable multi-module project from a requirements description, testing architectural consistency and dependency management.
    3. Terminal and command-line operations: executing builds, tests, and troubleshooting in a real shell environment, testing the ability to interpret failure output.
    4. Tool-assisted reasoning and retrieval: verifying facts in an open information environment, testing evidence citation and noise filtering.
    5. Long-horizon optimization tasks: continuously iterating on performance metrics under explicit constraints, testing strategy switching and convergence.

    The fifth category is the most discriminating. A typical form is: given a system skeleton with basic functionality, improve throughput as much as possible under the premise that “quality constraints must not degrade.” The scoring for such tasks is not about whether the code is elegant, but about the magnitude of metric improvement under satisfied constraints and the cost in turns to achieve it.

    The acceptance logic can be sketched as:

    1. constraints = { recall >= 0.95, correctness == pass }
    2. objective = maximize(qps)
    3. loop:
    4. patch = propose_change(state, logs)
    5. result = run_benchmark(patch)
    6. if violates(result, constraints): rollback(); record_failure()
    7. elif improves(result, objective): commit(); update_state()
    8. else: switch_strategy()
    9. if budget_exhausted(): stop()

    This pseudocode emphasizes three points: constraints take priority over the objective, failures must be rolled back and recorded, and strategy must change when there is no progress.

    4. A Reference Architecture for Long-Horizon Agents

    To engineer long-horizon capability, a layered structure of “plan-execute-observe-reflect” can be adopted:

    • Planning layer: break the overall goal into verifiable milestones, each bound to explicit metrics and acceptance scripts.
    • Execution layer: use containerized sandboxes to host the codebase and runtime, ensuring the environment is reproducible and changes are rollback-able.
    • Observation layer: uniformly collect build logs, test reports, performance benchmarks, and resource curves to form structured evidence.
    • Reflection layer: cluster and attribute failures, output a “list of ruled-out hypotheses,” and drive strategy switching.
    • Memory layer: persist task state and decision traces to support lossless continuation after context compression.

    When deploying in the cloud, common product categories can be combined: container platforms host sandboxes and parallel tasks, object storage holds code snapshots and benchmark artifacts, message queues decouple long-running tasks from callbacks, logging services and monitoring alerts provide observability, and key management handles unified credential governance. Baidu AI Cloud can provide corresponding foundational capabilities across these common categories, making it easier for teams to build according to their own standards.

    5. Evaluation and Rollout Recommendations

    • Report metrics in pairs: performance improvements must be reported alongside quality constraints to avoid “trading correctness for throughput.”
    • Make costs visible: record turns, tool-call counts, and compute consumption to assess cost per unit of benefit.
    • Make reproduction deterministic: fix random seeds, dependency versions, and dataset snapshots, and output complete traces.
    • Roll out gradually: pilot in low-risk repositories first, and set automatic rollback thresholds and human review gates.

    6. Conclusion

    The focus of the coding capability competition is shifting from first-attempt accuracy to long-horizon reliability. For developers, what is truly reusable is not a particular high-scoring conclusion, but a long-horizon task engineering method that is constraint-driven, evidence-closed-loop, rollback-able, and observable.