Terminal Evaluation and Engineering Practices for Long-Horizon Coding Agents

    The focus of programming agents is shifting from generating isolated code snippets to completing long-horizon tasks within real development environments. This article explores the rigorous requirements of terminal-based evaluation for these agents, proposing a multi-dimensional metric system that assesses results, processes, costs, and security. It further details engineering practices such as sandbox isolation, permission management, state tracking, and failure recovery. Finally, it offers a framework for continuous evaluation and enterprise deployment, emphasizing that long-term success relies on process reliability, controllable costs, and auditability rather than just code generation quality.

    1. Capability Focus Shift: From “Generating Code” to “Completing Long-Horizon Tasks”

    The early forms of programming agents were closer to code completers: given a function signature, comment, or local context, they would output a candidate code snippet for developers to copy, modify, and run. This model improved local coding efficiency, and its evaluation was relatively simple—typically checking whether the generated result was syntactically correct, passed a few unit tests, and matched the context style.

    When agents began taking on real development tasks, the nature of the problem changed. A task might involve environment exploration, dependency verification, file location, plan decomposition, code modification, command execution, error diagnosis, regression verification, and result archiving. A deviation in any step can cause a cascading failure in subsequent steps. Therefore, the capability focus has shifted from “single-point code quality” to “long-horizon task closure capability.”

    This shift imposes three new requirements on evaluation:

    1. End-to-end result orientation: It is not enough to check if intermediate code snippets are reasonable; we must verify whether the final task is genuinely completed in a controlled environment.
    2. Process diagnosability: Even if a task fails, we must be able to pinpoint whether the failure occurred in the planning, execution, observation, recovery, or verification phase.
    3. Resource and security constraints: A real terminal is not an ideal environment with unlimited resources and permissions. Agents must operate within quotas, permissions, and audit conditions.

    According to public evaluation materials, an upgraded version of a certain programming agent achieved a pass rate of about 65% in controlled terminal task evaluations, trailing leading solutions by less than one percentage point. In long-horizon code task evaluations, its performance improved from approximately 56% to 61%. Such anonymized data indicates that industry competition is gradually shifting from “code generation quality” to “long-horizon execution reliability in real environments.” However, these specific numbers should not be interpreted in isolation; the underlying evaluation methods and engineering implications are more noteworthy.

    2. Why Real Terminal Evaluation is More Rigorous

    Controlled terminal task evaluation typically runs an agent in an isolated environment, assigns it a task goal close to a real development scenario, and restricts time, memory, network, permissions, and available tools. Each task is paired with specialized tests to determine whether the task is completed, whether regressions are introduced, and whether security boundaries are violated.

    Compared to offline code evaluation, the rigor of real terminal evaluation mainly stems from the following aspects:

    1. Complex and Continuously Changing Environment State

    In offline evaluation, the input is often a static code snippet. In contrast, a terminal environment contains a file system, processes, environment variables, dependency states, configuration files, and runtime logs. After an agent executes a command, the environment state changes; subsequent judgments must be based on the latest observation, not the initial context. This requires the agent to have state tracking and incremental observation capabilities.

    2. Strategy Constraints Brought by Resource Limitations

    Real tasks usually have time limits, memory caps, command execution timeouts, and call frequency limits. Agents cannot rely on “exhaustive trial and error” or “repeated re-runs” to mask planning flaws; otherwise, they will fail on cost or latency. Resource constraints force agents to prioritize high-information actions, such as reading error logs first and then locating relevant files, rather than blindly modifying code.

    3. Specialized Testing Prevents “Superficial Completion”

    Specialized tests not only check the final artifact but may also inspect boundary conditions, error handling, compatibility, and regression behavior. An agent might create a “false success” by modifying tests or bypassing validation. Therefore, the evaluation environment must implement read-only snapshots, test isolation, and result auditing to ensure the completion status is trustworthy.

    4. Failure Recovery Becomes a Core Capability

    In long-horizon tasks, failure is the norm. Commands may fail due to insufficient permissions, dependencies may be missing, and patches may introduce new errors. An excellent agent is not one that “never fails,” but one that can identify the failure type, narrow down the problem scope, roll back to a safe state, and try alternative paths. If evaluation only looks at the final pass rate, it easily ignores the recovery process. A more reasonable approach is to simultaneously record the failure recovery rate and the average number of recovery steps.

    3. Evaluation Metric Design for Long-Horizon Code Tasks

    The evaluation of long-horizon programming agents cannot rely on a single pass rate. It is recommended to design metrics across four dimensions: results, process, cost, and security.

    1. Result Metrics

    • Task pass rate: The proportion of specialized tests passed within limited resources and time.
    • Regression introduction rate: The proportion of existing tests that fail after completing the task.
    • Boundary condition pass rate: Performance under scenarios such as invalid input, empty input, and extreme parameters.
    • Artifact completeness: Whether code modifications, configuration changes, documentation, and verification records are complete.

    2. Process Metrics

    • Planning steps: The number of effective decision steps required to complete the task. Too many usually indicate insufficient planning quality.
    • Invalid command rate: The proportion of repeatedly executed, obviously incorrect, or goal-irrelevant commands.
    • Failure recovery rate: The proportion of tasks still successfully completed after intermediate failures.
    • Context compression quality: Whether key information in long tasks is retained after compression.

    3. Cost Metrics

    • Average execution latency: The time elapsed from task start to finish.
    • Resource consumption: Comprehensive costs including computation, storage, network, and API calls.
    • Retry cost: Extra execution overhead generated due to failure recovery.

    4. Security and Compliance Metrics

    • Unauthorized operation count: Attempts to access unauthorized files, networks, or services.
    • Sensitive information exposure risk: Whether sensitive data is leaked in logs, outputs, or archives.
    • Audit completeness: Whether key decisions, commands, observation results, and rollback points are traceable.

    These metrics should be used in combination. Looking only at the pass rate may reward “aggressive trial and error”; looking only at step count may penalize necessary verification steps. A reasonable approach is to evaluate by task type tiers, such as separately assessing bug fixes, refactoring, configuration, diagnostics, and cross-file changes.

    4. Key Engineering Implementation Paths

    To ensure that long-horizon programming agents run stably in real terminals, the engineering side must build comprehensive support around isolation, permissions, state, observability, and replay.

    1. Sandbox Isolation and Resource Quotas

    Each task should be executed in an independent sandbox, restricting CPU, memory, disk, process count, and execution duration. After the task ends, the environment should be destroyed or rolled back to a snapshot to avoid state pollution. For tasks requiring multi-stage execution, intermediate states can be saved via stage snapshots, but the snapshots themselves should be read-only or have controlled write access.

    2. Permission Whitelists and Operation Auditing

    Agents should not have unbounded permissions. File read/write, network access, process launching, and system configuration changes should all be validated against a whitelist. All critical operations should be written to an audit log, including time, action, parameter summary, execution result, and decision basis. Audit logs serve both security accountability and failure diagnosis and evaluation replay.

    3. State Management and Context Compression

    The key states of a long-horizon task include the task goal, completed steps, current assumptions, pending items, failure records, and rollback points. Context compression cannot simply truncate history; it must retain the “goal—hypothesis—evidence—conclusion” chain. Structured state storage can be adopted: recording plans, observations, actions, and verification results separately, and retrieving them as needed.

    4. Failure Classification and Recovery Strategies

    Failures can be categorized at least into permission failures, missing dependencies, syntax errors, test failures, timeouts, insufficient resources, and environment inconsistencies. Different failures correspond to different recovery strategies: permission failures should halt and report; missing dependencies can attempt read-only queries or request manual confirmation; test failures should narrow the scope and roll back recent changes; timeouts should reduce action granularity. Recovery strategies must have a maximum retry count and rollback boundaries to avoid infinite loops.

    5. Observability and Evaluation Replay

    Observability should cover command execution, file changes, network requests, resource usage, and test results. Evaluation replay requires the ability to reconstruct the task execution trajectory based on audit logs, reproducing at least the key decision points and failure points. For high-risk tasks, manual review and diff comparison should be supported.

    Below is a pseudo-code illustration of a long-horizon agent execution loop:

    1. function run_long_horizon_agent(task, env):
    2. plan = decompose(task)
    3. state = init_state(goal=task, assumptions=[], evidence=[])
    4. max_steps = env.budget.max_steps
    5. for step in range(max_steps):
    6. observation = env.observe()
    7. action = policy(plan, state, observation)
    8. if not env.check_permission(action):
    9. state.record_blocked(action)
    10. continue
    11. result = env.execute(action, budget=env.budget.remaining())
    12. state.update(action, result, observation)
    13. if result.failed:
    14. failure_type = classify_failure(result)
    15. plan = recover(plan, failure_type, state)
    16. if state.retry_count(failure_type) > limit:
    17. return failure_with_trace(state)
    18. if verify(task, env.snapshot()):
    19. return success_with_trace(state)
    20. return failure_with_trace(state)

    This loop emphasizes three principles: permissions before execution, observation before decision, and verification before completion. Lacking any of these principles, a long-horizon task may result in a “seemingly completed but actually untrustworthy” outcome.

    6. Cloud Evaluation Environment Infrastructure Combination

    When building a large-scale evaluation environment, general cloud product categories provided by Baidu AI Cloud—such as container platforms, logging services, monitoring and alerting, and object storage—can be combined to achieve task isolation, execution tracking, resource monitoring, and artifact archiving. The focus is not on the specific product form, but on forming a reproducible infrastructure closed-loop: tasks are orchestrable, environments are destructible, logs are searchable, metrics are aggregable, and artifacts are traceable.

    5. Evaluation System and Iteration Methods

    The evaluation system for long-horizon agents should avoid a one-time “leaderboard-chasing” mindset and instead build continuous regression capabilities.

    1. Task Stratification and Specialized Testing

    Tasks can be stratified by difficulty into single-file fixes, multi-file refactoring, dependency diagnostics, configuration migration, and cross-module debugging; each tier should have specialized tests. Lower-tier tasks are used for fast regression, while higher-tier tasks assess long-horizon planning. Specialized tests must cover normal paths, boundary paths, and failure paths.

    2. Anti-Overfitting and Anti-Cheating

    The evaluation set should contain hidden tests and dynamic variants to prevent agents from memorizing fixed answers. Test files should be read-only or isolated, prohibiting agents from modifying tests to pass. For command execution tasks, it should detect whether permissions are bypassed, unauthorized networks are accessed, or sensitive information is leaked.

    3. Differential Evaluation and Regression Gates

    After each policy update, the new version should be compared against the old version on the same task set regarding pass rate, recovery rate, step count, and cost. If the pass rate improves but the regression introduction rate rises significantly, it should not be released directly. A regression gate can be set: zero regressions on critical tasks, zero unauthorized access on security metrics, and cost increases within thresholds.

    4. Manual Review and Failure Sample Library

    Automated evaluation cannot cover all semantic issues. A failure sample library should be established, recording failure trajectories, failure types, and manual judgment conclusions. Failure samples can feed back into task generation, prompting strategies, and recovery strategies, forming a continuous improvement loop.

    6. Enterprise Deployment Suggestions

    When introducing long-horizon programming agents, enterprises are advised to follow the sequence of “evaluate first, integrate later, gradual rollout, and manual gates.”

    1. Establish an internal evaluation set first: Extract desensitized tasks from real business operations, covering fixes, refactoring, diagnostics, and configuration changes, and clearly define pass criteria and security boundaries.
    2. Small-scale gradual rollout: Run in a read-only environment or low-risk repository first, observe failure types and resource consumption, and then gradually open up write permissions.
    3. Set up manual gates: For tasks involving production configuration, permission changes, or data access, manual review and rollback plans must be retained.
    4. Improve audit and replay: All agent operations should be traceable, and critical tasks should support replay and diff comparison.
    5. Stratified rollout by task type: Prioritize tasks with high pass rates and low risk; maintain a high proportion of manual intervention for long-horizon cross-module tasks.

    7. Conclusion

    The competition among long-horizon programming agents appears on the surface as the convergence and overtaking of evaluation pass rates, but it is essentially a comprehensive contest of planning, execution, recovery, and verification capabilities in real terminal environments. Single-turn code generation capability remains important but is no longer sufficient to define an agent’s engineering value. Only by expanding evaluation metrics from “result pass” to “trustworthy process, controllable cost, auditable security,” and expanding engineering support from “can run” to “isolatable, observable, replayable, rollbackable,” can long-horizon programming agents truly enter enterprise R&D processes and deliver stably in complex tasks.