Evaluating Long-Horizon Coding Capabilities of Large Language Models: A Practical Framework

    Long-horizon coding tasks require more than single-turn code generation. This article explains how to evaluate LLMs on repository-level understanding, multi-step planning, tool use, visual input interpretation, and self-verification; how to build an internal benchmark and scoring pipeline; which metrics and cost calculations to track; and how to manage integration, security, and operational risks.

    1. Why Long-Horizon Coding Needs Dedicated Evaluation

    Single-turn question-and-answer code generation and multi-hour engineering tasks place very different demands on a model. The former focuses on whether a single piece of code is correct. The latter requires the model to maintain goal consistency across multiple interactions, read a large amount of context, call tools, and repeatedly correct its work based on runtime results. As a result, scores on general code benchmarks often cannot determine whether a model can handle work in a real project.

    Evaluation should start from real business tasks. Teams need to answer three questions: Can the model advance a task independently? If it makes a mistake during execution, can it discover and correct the error on its own? Can the final output pass acceptance criteria?

    2. Breaking Down the Capability Dimensions of Long-Horizon Coding

    It is recommended to break the capability into five observable dimensions.

    1. Repository-level understanding: Can the model locate relevant files and understand dependencies between modules, rather than looking only at the currently open file? For example, in a large codebase, can it find all references to a configuration item and determine which modules would be affected by changing it?
    2. Multi-step planning: Can the model break a requirement into subtasks in a logical order and adjust the plan during execution based on actual conditions? For example, when adding an API endpoint, it may need to modify the data model first, then write a migration script, and finally add tests.
    3. Tool use: Can the model correctly call terminal commands, testing tools, and version control commands, and correctly interpret their output?
    4. Visual input understanding: If a task includes a design spec or UI screenshot, can the model translate layout, spacing, colors, and interaction requirements from the image into code?
    5. Self-verification: Can the model run tests, read error messages, identify causes, and fix issues, rather than repeating the same mistake?

    Each dimension should correspond to at least one type of quantifiable task. Otherwise, evaluation results will remain at the level of impressions.

    3. Building an Internal Evaluation Set

    3.1 Selecting Tasks

    Tasks should come from real tickets or code review records from the past six months. Prepare 20 to 50 tasks per category, covering new feature development, bug fixing, refactoring, and frontend redesign. Task descriptions need to be anonymized and accompanied by clear acceptance criteria, such as “the API response structure matches the documentation and passes all integration tests.”

    3.2 Fixing the Runtime Environment

    When the same task is run across different models, dependency versions, test data, timeout settings, and tool permissions must remain consistent; otherwise, comparisons are meaningless. It is recommended to package the runtime environment as a container, start every run from a clean state, and record the environment version number.

    3.3 Scoring Method

    Scoring is divided into three layers.

    • Automated tests: Unit tests and integration tests must all pass for the task to be considered qualified.
    • Static checks: Code style, type checking, and security scanning must not introduce new issues.
    • Human review: Sample and review code readability, naming, and design quality to prevent results that “pass tests but have poor design” from being mistakenly judged as excellent.

    The following example only illustrates the evaluation flow; users configure the test and check commands themselves:

    1. import subprocess
    2. from dataclasses import dataclass
    3. @dataclass
    4. class TaskResult:
    5. task_id: str
    6. tests_passed: bool
    7. checks_passed: bool
    8. steps_used: int
    9. def run_command(cmd: list[str], workdir: str, timeout: int = 600) -> bool:
    10. # Pass commands as an argument list rather than shell concatenation to reduce command injection risk
    11. proc = subprocess.run(cmd, cwd=workdir, capture_output=True, timeout=timeout)
    12. return proc.returncode == 0
    13. def evaluate(task_id: str, workdir: str, test_cmd: list[str],
    14. check_cmd: list[str], steps_used: int) -> TaskResult:
    15. return TaskResult(
    16. task_id=task_id,
    17. tests_passed=run_command(test_cmd, workdir),
    18. checks_passed=run_command(check_cmd, workdir),
    19. steps_used=steps_used,
    20. )
    21. def pass_rate(results: list[TaskResult]) -> float:
    22. if not results:
    23. return 0.0
    24. ok = sum(1 for r in results if r.tests_passed and r.checks_passed)
    25. return ok / len(results)

    4. Metric Design

    A single pass rate cannot reflect the full picture. It is recommended to track the following metrics at the same time.

    Metric Meaning Problem Reflected
    Task pass rate Proportion of tasks that pass acceptance Overall usability
    First-attempt pass rate Proportion of tasks that pass on the first submission Rework cost
    Average steps Tool calls or interaction rounds required to complete a task Execution efficiency
    Regression rate Proportion of changes that break existing tests Code stability
    Cost per task Cost calculated from actual usage Economic efficiency
    End-to-end time Time from task submission to a usable result Delivery speed

    Metrics often constrain one another. For example, a model that uses more steps may have a higher pass rate, but it may also take longer and cost more. Teams need to set weights according to their own business priorities.

    5. Cost Accounting Methods

    Model calls are usually billed by input and output tokens. Long-horizon tasks repeatedly carry large amounts of context, so input tokens often account for the majority. Cost per task can be estimated as follows:

    Cost per task = (average input tokens × input unit price + average output tokens × output unit price) × average number of calls

    A more decision-useful metric is “cost per passed task”:

    Cost per passed task = cost per task ÷ task pass rate

    A model with a lower unit price but only a 50% pass rate may have a higher cost per passed task than a model with a higher unit price and a higher pass rate. This metric helps avoid the mistake of comparing list prices alone. Note that billing rules are subject to the service provider’s latest public terms. During evaluation, record the actual usage of each call rather than relying on estimates.

    6. Integration and Engineering

    1. Unified invocation layer: Add a wrapper layer between business code and model APIs. When switching models or running A/B tests, only the configuration needs to change, not the business logic.
    2. Secret management: Inject keys through environment variables or a secret management service. Do not write them into the code repository or logs.
    3. Budgets and timeouts: Set call limits, total cost limits, and timeout values for each task to prevent long-running tasks from producing unexpected costs after going out of control.
    4. Logging and anonymization: Record summaries of inputs and outputs for each call to support later troubleshooting. Source code, customer data, and credentials in logs need to be anonymized.
    5. Execution isolation: Run model-generated code and commands in an isolated environment, restrict the network addresses and file directories they can access, and follow the principle of least privilege.

    7. Risks and Boundaries

    • Fabricated interfaces: Models may call functions, parameters, or configuration items that do not exist. Verification must rely on compilation, tests, and integration checks, not merely on whether the code looks reasonable.
    • Security vulnerabilities: Generated code needs static security scanning, and humans should review parts involving authentication, authorization, input handling, and encryption.
    • Licenses and compliance: If generated content contains snippets similar to existing code, confirm the applicable license terms. Tasks involving personal information must also comply with relevant data protection regulations.
    • Over-automation: Critical operations such as code merging, releases, and database changes still require human approval.
    • Visual fidelity deviation: Whether the UI matches the design spec should be confirmed through screenshot comparison or human acceptance. A model’s evaluation of its own output cannot be used as the basis for acceptance.

    8. Implementation Recommendations

    1. First spend two to three weeks building an internal task set of about 30 tasks and fixing the runtime environment.
    2. Retest after each model version update and retain historical data to compare trends.
    3. Select low-risk modules for a small-scale pilot, comparing manual development and assisted development in terms of cycle time, defect rate, and rework count.
    4. Use cost per passed task and defect escape rate as the primary decision criteria, and treat public leaderboard scores only as a reference.

    There is no one-time answer for evaluating long-horizon coding capabilities. Teams can obtain conclusions usable for decision-making only by bringing tasks, environments, scoring, and cost into a single process.