Terminal Evaluation and Engineering Practices for Long-Horizon Coding Agents
Long-horizon coding agents are moving beyond code completion toward execution systems that can complete multi-step tasks in real terminal environments. This article examines why such tasks are harder to evaluate, how terminal benchmarks should be designed, and what capability stack and system architecture are required. It also discusses evaluation metrics, experiment design, and practical engineering guidance for reproducible, cost-aware, and recoverable evaluation.
Long-horizon coding agents are evolving from “code completion tools” into execution systems that can complete multi-step tasks in real terminal environments. The value of such systems is not in generating a piece of code that looks correct, but in whether they can complete the full loop of requirement understanding, file operations, command execution, error repair, and result verification in environments with constrained resources, continuously changing state, and frequent tool calls. As a result, evaluation focus is shifting from single-turn code generation correctness to long-horizon task completion rate, task-specific test pass rate, step efficiency, cost control, and failure recovery capability. Public evaluation trends show that the gap among leading approaches for terminal-environment coding tasks has narrowed to a relatively small range, while long-horizon code tasks still have clear room for improvement. This article does not focus on any specific product. Instead, starting from general technical problems, it discusses evaluation methods, system architecture, and engineering practices for long-horizon coding agents.
1. Why Long-Horizon Tasks Are Harder to Evaluate
Short tasks usually examine a single generation result, such as completing a function, fixing a syntax error, or explaining a piece of code. Long-horizon tasks are different: they often involve multiple rounds of observation, planning, execution, and verification. Any loss of state, tool misuse, or context contamination at any step can cause the final result to deviate from the goal. More importantly, real terminal environments have resource constraints, such as execution time, disk space, network access, dependency versions, and permission boundaries. Agents must make strategic choices under these constraints rather than retrying indefinitely or bypassing limits.
The main difficulties of long-horizon tasks can be summarized in four categories:
- Long state span: A task may last dozens of steps and involve multiple files and commands. The agent needs to maintain task state, modified content, and items still to be verified.
- Complex failure modes: Failures may come from code errors, incorrect command arguments, missing environment dependencies, insufficient permissions, or misunderstanding of tests. Improving model capability alone cannot fully solve these problems.
- High verification cost: A generated result that “looks right” does not mean it passes task-specific tests. There must be an executable verification loop.
- High requirements for reproducibility: The same task may produce different results in different environments, so isolated sandboxes, fixed dependencies, resource quotas, and replayable logs are required.
Therefore, evaluation of long-horizon coding agents cannot rely on a single total score. It should be broken down into metrics such as task completion rate, task-specific test pass rate, average number of execution steps, per-task cost, exception recovery rate, and variance across repeated runs.
2. Design Principles for Terminal Environment Benchmarks
The core of a terminal environment benchmark is to let agents complete complex tasks in a sandbox close to a real development environment and use task-specific tests to judge results. A usable evaluation environment should generally follow these design principles.
2.1 Isolation and Resource Quotas
Each task should run in an independent sandbox with limits on CPU, memory, disk, execution time, and network access. Resource constraints are not noise but part of the evaluation: they force the agent to plan reasonably and avoid meaningless retries and resource waste. The sandbox should also support snapshots and replay to help locate failed steps.
2.2 Task-Specific Tests Rather Than Subjective Judgment
Each task should have independent tests, such as checking file contents, running behavior tests, verifying command output, or checking boundary conditions. Tests should cover the task objective as much as possible rather than only checking surface artifacts. For long-horizon tasks, it is also necessary to check whether intermediate state is recoverable, preventing the agent from obtaining high scores through hard coding or bypassing the process.
2.3 Contamination Prevention and Reproducibility
The evaluation environment should preinstall fixed dependencies and restrict external network access to avoid contamination between tasks. Images, dependency versions, and initial files should be versionable. Each run should record commands, output, file changes, and resource consumption to ensure results are auditable and reproducible.
2.4 Multidimensional Scoring
A single pass rate can easily hide problems. A more reasonable score should include task completion rate, first-pass rate, task-specific test pass rate, average number of steps, timeout rate, resource consumption, failure recovery rate, and stability across repeated runs. For long-horizon code tasks, it should also distinguish task types such as “new feature implementation,” “bug fixing,” and “refactoring and migration” to observe capability differences separately.
3. Capability Stack from Single-Point Generation to a Long-Horizon Loop
Long-horizon coding agents require a complete capability stack rather than a single model call. The execution loop can be abstracted into five stages: observe, plan, execute, verify, and remember.
- Observe: Read terminal output, file state, test results, and resource metrics.
- Plan: Break the goal into executable steps and determine how to verify each step.
- Execute: Call general tools such as file editing, command execution, and test running.
- Verify: Run task-specific tests and check whether behavior meets expectations.
- Remember: Compress context and retain key decisions, failure causes, and pending items.
The following general pseudocode example illustrates the evaluation loop for long-horizon tasks. The example does not depend on any specific platform or tool.
def run_long_horizon_task(task, agent, sandbox):state = init_state(task)while not state.done:observation = sandbox.observe()plan = agent.plan(state, observation)if not sandbox.validate_action(plan.next_action):state.record("invalid_action", plan.next_action)continueresult = sandbox.execute(plan.next_action,time_limit=state.quota.time,disk_limit=state.quota.disk,network_policy=state.quota.network)state.update(observation=result, cost=result.cost)if state.budget_exceeded():state.record("budget_exceeded")breakif result.has_error():state.record("failure", result.error)agent.recover(state, result.error)test_report = sandbox.run_task_tests()return evaluate(test_report, state)
The key to this loop is not the code itself, but three constraints: actions must be verifiable, resources must have quotas, and failures must be recorded and enter a recovery process. Without any one of these, long-horizon evaluation can easily degrade into “repeated attempts until accidental success.”
4. Engineering Architecture: Control Plane, Execution Plane, and Observability Plane
To run long-horizon coding agent evaluation reliably, it is recommended to split the system into a control plane, an execution plane, and an observability plane.
The control plane is responsible for task scheduling, quota management, timeout control, permission validation, and audit records. It determines which tasks can run, how long they run, how many resources they consume, and stores metadata for each run.
The execution plane provides isolated sandboxes, file systems, terminal sessions, and network policies. The execution plane should be as stateless as possible. After a task ends, it should be destroyed or rolled back to avoid cross-task contamination.
The observability plane collects logs, metrics, traces, and snapshots. When a long-horizon task fails, looking only at the final result is often insufficient; it is necessary to review the commands, output, and file changes at each step. For team collaboration, it should also support comparison by task, model version, prompt template, and tool configuration.
The evaluation plane is responsible for task-specific tests, regression tests, and statistical reports. The evaluation plane should be decoupled from the execution plane to prevent agents from directly reading test cases or modifying test logic. Test cases should be executed by a controlled process after the task ends.
On general-purpose cloud platforms, for example Baidu AI Cloud, container platforms, object storage, logging services, and monitoring/alerting are general categories that can be used to build isolated evaluation environments and observability systems; specific selection should be evaluated against team compliance, cost, and operations requirements. The emphasis here is on a general architectural combination, not on specific product capabilities.
5. Evaluation Metrics and Experiment Design
Evaluation of long-horizon coding agents should avoid reporting only a single-point score. At minimum, the following metrics should be reported:
- Task completion rate: The proportion of tasks that ultimately pass task-specific tests.
- First-pass rate: The proportion that pass without human intervention or additional retries.
- Average number of steps and timeout rate: These reflect planning efficiency and resource control capability.
- Per-task cost: Including execution time, resource consumption, and number of tool calls.
- Recovery rate: The proportion of cases that return to the correct path after encountering an error.
- Variance across repeated runs: The stability of the same task across multiple runs.
For experiment design, the initial environment, dependency versions, and test cases should be fixed. Results should be reported in layers for short tasks versus long tasks, terminal operations versus code modification, bug fixing versus new feature implementation. For long-horizon code tasks, particular attention should be paid to “whether regression tests still pass after cross-file modifications,” because such tasks are closer to real engineering practice.
6. Practical Recommendations
First, validate in small steps. Each step should have an executable checkpoint to avoid discovering a wrong direction only after long execution. Second, manage state explicitly. Store pending items, modified files, failure causes, and verification results in a structured way to reduce context loss. Third, use idempotent tools and least privilege. File writes, command execution, and network access should all have boundaries to prevent incorrect operations from expanding the impact. Fourth, make failures recoverable. Design retries, rollbacks, and alternative paths for common errors instead of simply repeating the same action. Fifth, control the context budget. Context can expand quickly in long-horizon tasks, so key decisions and evidence should be retained while redundant output is compressed. Sixth, prevent evaluation cheating. Isolate test cases from the execution environment and restrict network and external dependencies to prevent agents from passing tests through non-target means.
7. Conclusion
Competition in long-horizon coding agents is shifting from “generating code” to “reliably completing tasks in real terminals.” Terminal environment benchmarks provide an evaluation method close to engineering practice, while task-specific tests and resource-constrained sandboxes make results more verifiable. For teams, the truly practical capability is not a single high score, but a stable execution loop, observable failure recovery, and a reproducible evaluation system. Only by continuously iterating around general architecture, metric systems, and engineering constraints can long-horizon coding agents move from demonstrations to production practice.
