Evaluating LLM Long-Horizon Programming Tasks: Methods and Engineering Practices

    Evaluating the long-horizon programming capabilities of Large Language Models (LLMs) requires moving beyond single-turn accuracy. This article outlines the core dimensions for assessing long-horizon coding tasks, common failure modes, cost calculation strategies, and practical engineering recommendations to determine whether an LLM can independently and cost-effectively complete multi-step software engineering goals.

    1. Why Long-Horizon Programming Capabilities Require Separate Evaluation

    Single-turn Q&A only requires the model to generate one response, whereas long-horizon programming demands that the model maintains state across multiple steps: decomposing requirements, creating files, invoking tools, running tests, and debugging based on errors. Errors in each step propagate to subsequent steps, meaning single-turn accuracy cannot represent the completion quality of a long-horizon task.

    There are three main risks in long-horizon tasks:

    1. Error Accumulation: Early design flaws are amplified in subsequent modules.
    2. Planning Drift: During execution, the model might silently alter the architecture, while the final report still claims completion according to the original plan.
    3. Silent Failure: The model claims tests passed, but the tests were never actually executed.

    The goal of evaluation is to answer three indispensable questions: Can the model complete the task independently? Is it completed correctly? Is the incurred cost acceptable?

    2. Four Core Evaluation Dimensions

    Long-horizon programming capability can be broken down into the following four dimensions, each corresponding to observable metrics:

    Dimension Observation Focus Measurement Method
    Planning Completeness Whether it decomposes the data model, business modules, interfaces, and validation steps Check against requirements list; count missing features and dependencies
    Execution Consistency Whether actual operations follow the plan and if key steps are missing Compare execution logs with planning entries item by item
    Self-Correction Ability Ability to locate issues, modify code, and perform regression verification after errors Count error occurrences, fix success rate, and average fix rounds
    Tool & Environment Interaction Success rate of file I/O, command execution, and dependency installation Count tool invocation failure rates and observe recovery paths after failures

    Planning completeness is easily overestimated. A beautifully structured planning document does not guarantee reliable execution results. Therefore, planning scores should be calculated separately from execution scores.

    3. Designing Evaluation Tasks: A Bookkeeping Application Example

    A bookkeeping application has a clear structure, encompassing database table design, CRUD operations, category management, and statistical summaries, making it an ideal standard sample for long-horizon tasks.

    Task design should account for two types of prompts:

    1. Open-ended Prompt: Only provides the business goal without specifying technical solutions, used to evaluate the model’s autonomous planning ability.
    2. Constrained Prompt: Explicitly lists fields, interface behaviors, and acceptance criteria, used to evaluate execution accuracy.
      The conclusions from these two prompts often differ: open-ended tasks reflect the model’s design judgment, while constrained tasks reflect execution precision.

    The acceptance checklist should be auto-checkable or semi-auto-checkable, including the following items:

    • Whether the database table structure, primary keys, and foreign keys are designed reasonably.
    • Whether insert, update, and delete operations are correctly written and reflected in the list.
    • Whether the handling of associated records after a category deletion meets expectations.
    • Whether amount inputs validate negative numbers and illegal characters.
    • Whether statistical summaries match manually calculated results.
    • Whether explicit prompts are provided for exceptions instead of failing silently.

    UI aesthetics is a subjective metric and should be scored separately, not mixed with functional correctness.

    4. Common Failure Modes and Identification Methods

    There are four common failure modes in long-horizon tasks:

    1. Reasoning Loops: The model repeatedly executes the same or similar operations without making substantive progress. Identification method: Check if the action sequence of recent steps shows periodic repetition.

    2. Overthinking: Faced with a simple problem, the model generates lengthy derivations and ultimately reaches an incorrect conclusion. This is particularly evident in common-sense problems. Mitigation method: Establish a simple problem benchmark set, compare accuracy rates under different reasoning budgets, and find the most cost-effective configuration.

    3. Silent Failure: The model reports task completion, but tests were not executed or exited with a failure code. Mitigation method: Require the model to attach test commands and outputs before reporting completion, and have the evaluation program independently verify them.

    4. Planning Drift: The data model or interface design is changed mid-execution without synchronously updating the planning document. Mitigation method: Write the plan into a persistent design document and cross-check it after completing each module.

    The pseudo-code below demonstrates how to log execution steps and detect periodic repetitions in recent actions:

    1. def detect_cycle(action_list, window=4):
    2. if len(action_list) < window * 2:
    3. return False
    4. tail = action_list[-window * 2:]
    5. first_half = tail[:window]
    6. second_half = tail[window:]
    7. return first_half == second_half
    8. def summarize_evaluation(log):
    9. report = {
    10. "step_count": len(log),
    11. "tool_error_count": sum(1 for entry in log if "error" in entry),
    12. "suspected_cycle": detect_cycle([entry["action"] for entry in log]),
    13. "input_token_count": sum(entry["input_tokens"] for entry in log),
    14. "output_token_count": sum(entry["output_tokens"] for entry in log)
    15. }
    16. return report

    This code is a conceptual illustration; actual implementation needs adjustment based on the logging format of the tools used. The window size for cycle detection also needs calibration based on task complexity—an overly small window may cause false positives for normal repeated compilation operations.

    5. Cost Calculation: Per Task, Not Per Unit Price

    The total cost of a long-horizon task is not equal to the unit price multiplied by the output length. During task execution, the context is repeatedly submitted to the model, meaning the proportion of input tokens is often much higher than intuition suggests. Input tokens can further be divided into cache hits and cache misses, which are priced differently.

    Total cost can be calculated using the following formula:

    1. Total Cost = (Uncached Input Tokens * Uncached Price)
    2. + (Cached Input Tokens * Cached Price)
    3. + (Output Tokens * Output Price)

    When calculating costs, note the following:

    1. Unit prices should be based on the current prices published by the service provider, and the calculation date should be recorded as prices are subject to change.
    2. The cache hit rate depends on the stability of the context; frequently rewriting system prompts will lower the hit rate.
    3. Costs should be calculated by phase (e.g., planning, coding, debugging, validation) to identify high-cost stages.

    6. Practical Engineering Recommendations

    1. Establish a tiered evaluation set: Simple Q&A, moderately complex single-module tasks, and complete long-horizon engineering tasks should be evaluated separately to avoid representing all capabilities with a single metric.
    2. Combine automated checks with manual acceptance: Test scripts can detect functional defects, while manual reviews can identify logical and user experience issues. Reliable evaluation results require both.
    3. Set budgets and safety boundaries: Define maximum steps, timeout limits, and cost ceilings for each task. Set manual confirmation checkpoints at critical nodes (e.g., database schema changes, dependency upgrades).
    4. Retain complete logs for review: Logs should include the action, tool output, token usage, and time consumed for each step. Post-mortem records of failure cases are more valuable references than those of successful cases.
    5. Select capability tiers based on scenarios: Simple Q&A can use fast, low-cost configurations, while complex engineering tasks require stronger planning and self-correction capabilities. Before selection, validate using the evaluation process described in this article rather than relying on marketing metrics.