A Framework for Evaluating Long-Horizon Coding Tasks: Metrics and Reproduction Methods
This article presents a practical evaluation framework for long-horizon coding tasks, where agents must navigate existing codebases, iterate through multiple rounds, and reach a usable result. It defines core metrics such as task success rate, interaction rounds, token consumption, wall-clock time, and cost-effectiveness ratio, along with precise collection methods. The article also provides a structured comparison table for model configurations, discusses common causes of token inefficiency, and details a step-by-step reproduction procedure to ensure fair and repeatable benchmarking. Additionally, it addresses the automation of computer use with safety boundaries, including whitelists and step limits, to support secure agent-based workflows.
Evaluating Long-Horizon Coding Agents: A Metric and Reproducibility Framework
Why Evaluate Long-Horizon Coding Tasks Separately
Single-turn code generation problems can reveal a model’s knowledge but do not reflect how developers actually work. Real tasks typically require reading a codebase, locating the root cause, modifying code, running tests, and iterating based on error messages. This process may span dozens of interactions, during which the model must remember project conventions, previously attempted solutions, and why they failed.
Therefore, when evaluating long-horizon tasks, the focus shifts from “did the model solve the problem in one shot” to “how many steps, tokens, and seconds did it take to complete a task, and is the final result usable.”
1. Evaluation Objects and Scenarios
Before running any evaluation, freeze three components:
- Task set: Select real problems close to your team’s business, such as fixing a known defect, adding unit tests for a module, or extending an existing API with a new field. Each task must come with an initial repository snapshot, acceptance tests, and a task description.
- Environment: Record the operating system, runtime version, dependency lock file, tool invocation permissions, and timeout settings. Only identical environments allow fair comparison of different models.
- Model under test: Record the model name, version, inference parameters (temperature, max output length, etc.), and whether tools are enabled. Model version changes alter results, so the report must include all these details.
Public leaderboards can serve as references, but their task sets, scoring scripts, and environment configurations vary. Directly comparing leaderboard scores with internal results usually leads to misleading conclusions.
2. Metric Definitions and Collection Methodology
The table below lists the core recommended metrics. All values should be computed from your own experiment logs, not from unreproduced numbers.
| Metric | Definition | Collection Method | Notes |
|---|---|---|---|
| Task Success Rate | Number of tasks passing acceptance tests / total number of tasks | Run acceptance test scripts | Fix random seed or repeat multiple times and average |
| Average Interaction Rounds | Mean number of model invocation calls per task (completed or abandoned) | Count from call logs | Reflects iteration efficiency |
| Input Tokens | Sum of input tokens across all requests for a task | Read from the usage field in API responses | Historical context is counted repeatedly |
| Output Tokens | Sum of output tokens across all responses for a task | Same as above | If reasoning text is included, record it separately |
| Token Consumption per Task | Input tokens + output tokens | Calculated | Report success and failure tasks separately |
| End-to-End Wall-Clock Time | Wall-clock time from task start to acceptance completion | Timer | Includes tool execution time |
| Cost per Task | Monetary cost based on billing unit price | Unit price × token counts | Use the provider’s current price |
| Cost-Effectiveness Ratio | Task success rate / cost per task | Calculated | Only for horizontal comparison within the same task set |
Important notes:
- The denominator for success rate must include all tasks, including timeouts and abandoned ones. If tokens are only counted for successful tasks, cost will be underestimated.
- The cost-effectiveness ratio cannot be compared across different task sets or different pricing schemes.
3. Token Efficiency and Effect Comparison Table
The structure of the comparison table is shown below. Values must be filled from experiments, not pre-filled.
| Model Configuration | Success Rate | Tokens per Task | Avg. Rounds | Avg. Time | Cost per Task | Cost-Effectiveness |
|---|---|---|---|---|---|---|
| Model A (version, params) | to measure | to measure | to measure | to measure | to measure | to measure |
| Model B (version, params) | to measure | to measure | to measure | to measure | to measure | to measure |
When reading the table, note three points:
- Only when success rates are close does token consumption become meaningful. A lower-success model may use fewer tokens per attempt but incur higher total cost due to repeated retries.
- Averages can mask distributions. Always also look at the median and the slowest 10% of tasks to identify task types that cause loop-prone behavior.
- Run at least three repetitions per configuration and report the range of success rate fluctuation. A single run is insufficient to judge whether differences are stable.
Common practices to reduce token consumption include: compressing conversation history with summaries while retaining key decisions; using references for already-read files instead of pasting full text; and breaking large tasks into subtasks. However, over-splitting increases invocation counts, so balance must be found experimentally. Each change should be tested as an independent variable.
4. Reproduction Steps
- Freeze the task set and repository snapshots, store them in version control, and record their hashes.
- Fix the environment using a container image or virtual environment, and lock dependency versions.
- Set unified inference parameters and capture complete logs of requests and responses. Redact sensitive information before saving.
- Set a maximum number of rounds and a timeout for each task; tasks exceeding either are marked as failed.
- Run each configuration at least three times, saving raw results for every run.
- Score all tasks with the same acceptance test suite. Manually inspect at least 20% of passing tasks to confirm there are no “test passes but changes are unusable” cases.
- Aggregate metrics, calculate means, medians, and ranges, and archive everything along with the original logs.
5. Computer Use Automation: Workflow and Risks
When automating web or desktop operations, the model typically works in a loop of “observe, decide, act, re-observe.” The pseudocode below adds safety boundaries such as whitelists, step limits, human confirmation, and audit trails:
# Prerequisite: run in an isolated VM or sandbox, using a dedicated low-privilege account# Dependencies: screenshot and operation library, model inference API (replace with your actual libraries)ALLOWED_DOMAINS = {"staging.example.internal"} # whitelistMAX_STEPS = 30 # maximum number of stepsSTEP_TIMEOUT_S = 10 # per-step timeout (seconds)def run_task(goal):history = []for step in range(MAX_STEPS):state = capture_state() # screenshot plus structured element infoif not url_in_whitelist(state.url, ALLOWED_DOMAINS):pause_and_ask_human() # ask for confirmation or abortbreakaction = model_decide_action(goal, state, history) # model inferenceif action == "DONE":verify_result() # run acceptance checksbreakresult = execute_action(action) # apply the actionhistory.append((state, action, result))if step == MAX_STEPS - 1:mark_task_failed("step limit exceeded")
This approach mitigates common risks in GUI/web automation, such as unintended actions, runaway loops, and security issues. Always log every step and enforce a hard limit on the number of actions. In production, add human confirmation for irreversible operations (e.g., deleting files, sending emails) and keep the agent in a restricted environment that cannot access sensitive data or production systems.
