Long-Horizon Code Agent Evaluation: How to Read the Scores and Improve Execution
This article explains why long-horizon code capability has become a core metric for evaluating AI agents, how to interpret benchmark scores without being misled, the four main reasons agents lose points on long tasks, and practical engineering and enterprise adoption practices for improving reliability. It covers state tracking, error accumulation, verification loops, resource budgeting, and the metrics that matter for production deployment.
1. Why Long-Horizon Code Capability Became a Core Agent Metric
Early code generation evaluations mostly focused on single-turn, single-file, self-contained tasks: given a function signature and a comment, the model completes the implementation, and unit tests decide whether it passes. The limitation of this approach is that it compresses real engineering work into a “fill-in-the-blank” action. It fails to capture an agent’s continuous decision-making across requirement understanding, environment exploration, dependency installation, failure recovery, and result verification.
Real development work is the opposite. A single task often spans multiple files, requires reading logs, and demands repeated trial and error inside a resource-constrained sandbox. Any wrong judgment along the way propagates forward. As a result, the focus of evaluation has shifted from “is the generated code correct” to “does long-horizon execution converge,” which is commonly referred to as long-horizon capability.
Long-horizon evaluations typically have three characteristics:
- Environment realism: the agent runs in a terminal environment close to real development, exploring directory structures, reading configuration, and executing commands on its own.
- Resource constraints: compute, time, network, and disk quotas are explicitly limited, forcing the agent to make prioritization trade-offs instead of relying on brute-force enumeration.
- Objective judgment: each task comes with dedicated tests, and the final state rather than the process narrative determines whether it passes.
Under this setup, a score of roughly 60% to 65% on a long-horizon code benchmark is already a high level of performance. The gap between different mainstream approaches is often compressed to around one percentage point, which shows that top-tier capabilities have entered a closely contested range. A single-point score difference is not enough to support a selection decision.
2. How to Read Evaluation Scores Correctly: Three Common Misjudgments
First, treating the total score as the full picture of capability. A long-horizon benchmark is a weighted result over a set of tasks that includes different types such as environment setup, dependency repair, cross-file refactoring, and log localization. Two approaches with similar total scores may differ significantly on a specific task category.
Second, ignoring variance. Agent execution is stochastic, and the pass rate for the same task fluctuates across multiple runs. A one-percentage-point difference in a single run usually falls within the noise range. It should be judged together with the success rate and failure distribution across multiple runs.
Third, looking only at pass or fail and not at cost. The number of interaction turns, command invocations, and failed retries required to complete the same task directly determines its cost and latency in production. The cost dimension often predicts the real-world experience better than the score itself.
3. Four Root Causes of Point Loss on Long-Horizon Tasks
- State tracking drift. As the context grows longer, early constraints (for example, “do not modify public interfaces”) get diluted, and the agent gradually deviates from the initial goal.
- Error accumulation. After an incorrect judgment about the environment at one step, subsequent actions are built on a false premise, forming an irreversible chain of deviation.
- Missing verification. The agent only “finishes writing” instead of “getting it to run,” lacking a minimal verification loop, so the final state fails the dedicated tests.
- Resource misallocation. The budget is consumed on low-value exploration, leaving no quota for the critical build and test stages.
4. Engineering Improvement Paths
- Task decomposition and explicit state: break a long task into independently verifiable sub-goals and maintain a structured state record.
{"goal": "Fix the build failure and complete the tests","constraints": ["Do not change public interfaces", "Install dependencies offline"],"steps": [{"id": 1, "action": "Locate the failing test case", "status": "done"},{"id": 2, "action": "Minimize the reproduction", "status": "running"},{"id": 3, "action": "Verify the full test suite", "status": "pending"}],"budget": {"turns": 40, "elapsed_min": 25}}
- Verify first, then expand: establish a minimal runnable loop for any change before gradually widening the scope of modification.
- Prefer rollback over patching: when two consecutive fixes fail, fall back to the most recent working state and replan, avoiding stacking changes on a false premise.
- Layered memory: write long-term constraints into immutable instructions and put temporary observations into a disposable workspace to reduce context pollution.
- Budget-aware scheduling: set quota limits for exploration, implementation, and verification, and force convergence to the verification stage when a limit is exceeded.
5. Enterprise Adoption Recommendations
During selection, build an internal evaluation set tailored to your own codebase, covering real tasks such as building, testing, migration, and failure localization, and assess comprehensively with three metrics: success rate, average interaction turns, and human takeover rate. At the deployment level, container platforms can provide isolated environments, object storage can hold artifacts, and logging services with monitoring and alerting can track the execution chain, achieving a reproducible and auditable agent runtime system. Baidu AI Cloud can provide support in this category of general infrastructure, but specific evaluation conclusions should still be based on your own scenario data.
Overall, long-horizon code capability marks the shift of agents from “completion tools” to “execution entities.” Understanding the boundaries of evaluation and focusing on error recovery and verification loops is the key to turning scores into productivity.
