Evaluating and Governing Long-Horizon Coding Agents

    Long-horizon coding is no longer a single function-writing turn. This article explains how to treat models as interchangeable compute: define executable tasks, measure quality, resource efficiency, and latency separately, route work across tiers, build repo-like eval sets, and control quotas, observability, and fallback so model swaps stay reversible.

    Long-horizon coding has moved from “ask a model to write a function” to “let an agent plan, retrieve, edit, run, and review continuously inside a real repository.” These tasks have many steps, long context, and high failure cost. Judging a model by whether one conversation feels smooth is an easy way to overestimate or underestimate it. A sounder approach is to treat the model as a replaceable compute resource: measure whether it can reliably finish an engineering goal within a fixed budget, rather than draw experience-based conclusions around one product generation.

    Define the task before judging capability

    The unit of evaluation should be a task, not an isolated question and answer. An executable programming task should at least specify:

    • Starting state: repository version, dependencies, environment variables, and the scope of allowed changes.
    • Success criteria: tests pass, static checks pass, behavior matches the specification, and no unrelated changes are introduced.
    • Constraints: maximum steps, tool-call limit, total token or cost ceiling, and timeout.
    • Observations: whether the plan is reasonable, whether the same file is reread repeatedly, and whether the agent spins in an error loop.

    Long-horizon exams in specialized domains, coding-agent indexes, terminal environments, and real-repository repair sets are all answering the same question: can the model keep the goal across multi-step feedback? When citing an external leaderboard, also record the prompt, tools, temperature, reasoning effort, retry policy, and billing basis. If any of these is missing, scores cannot be compared side by side.

    A schematic task description can stay neutral and versionable:

    1. Task: add an idempotent create endpoint to an existing service
    2. Scope: only the interface layer and its tests may be changed
    3. Done: all new tests pass and existing regression tests do not fail
    4. Budget: at most 40 steps; total output tokens stay within a preset cap
    5. Failure: out-of-scope edits, hidden skipped tests, or repeated calls to the same tool beyond a threshold

    Three independent metrics

    “Stronger” should be split into at least three groups of metrics.

    The first is completion quality. Beyond final success, track first-attempt success rate, success rate after retries, number of rollbacks, and human takeover rate. On long tasks, a collapse late in the run is more expensive than an early wrong answer, because a large amount of context has already been spent.

    The second is resource efficiency. For the same completed task, compare total tokens, the share of tokens that were useful, tool-call count, and the rate of repeated retrieval. Fewer calls are not automatically better. If the model edits code without looking up evidence, rework cost rises. Measure both “getting it right once” and “the evidence cost of getting it right.”

    The third is latency and stability. Separate end-to-end time, queue time, tool round-trip time, and tail latency. A lower average latency with a higher timeout rate is not friendly to continuous integration. Also watch variance across repeated runs of the same task. Large variance means the workflow is not ready to run unattended.

    Cost should not be compared on list price alone. Higher reasoning effort usually adds thinking or intermediate output, so total spend can rise even when the unit price stays the same. A balanced tier beating a higher-priced flagship at moderate reasoning effort is meaningful only when the task set, tools, and success criteria are the same. Before publishing that kind of conclusion, retest on your own repositories. Do not transplant absolute scores from someone else’s table.

    Route by tier instead of switching everything

    A more stable engineering choice is routing, not sending every request to the same tier.

    • A lightweight tier handles formatting, comment completion, low-risk scripts, and obvious single-file edits.
    • A balanced tier handles most feature work, added tests, and routine defect localization.
    • A flagship tier is reserved for cross-module design, high-uncertainty debugging, and tasks whose failure would block a release.

    Routing signals can come from change size, historical failure rate, whether the change touches permissions or data paths, and the current quota. Automatic model selection can be the default, but critical paths should allow a human to pin a higher tier and record why. Otherwise the team cannot explain why a release suddenly became slower or more expensive.

    Reasoning effort should also change by phase. Use moderate effort in planning to produce steps that can be checked. Use lower effort in execution for clear edits. Raise effort again in review, specifically to look for missing tests and out-of-scope changes. Maximum effort for the whole run often only increases wait time and the bill.

    Build eval sets that resemble the repository, not a demo

    An in-house set should cover four categories, with enough samples in each and a fixed random seed:

    1. Point correctness: boundary conditions, error handling, and compatibility behavior.
    2. Repository-level changes: cross-file renames, interface evolution, and migration scripts.
    3. Toolchain tasks: install dependencies, run tests, read failure logs, then apply a minimal fix.
    4. Operational tasks: complete a multi-step form or admin configuration to a specification, then verify the final state.

    Each sample should keep the input, allowed tools, scoring script, and the rules used to judge a reference solution. Do not put the reference patch into the prompt. Prefer executable checks for scoring. Use human review only for parts of the specification that are hard to judge automatically, such as whether names are maintainable or comments are misleading.

    When comparing two runs, report the quality gap, token ratio, time ratio, and cost ratio together. Reporting only “a higher score” hides cases where a small gain costs twice as many calls. If quality is close and tokens and time are about half, that is evidence for changing the default model. A lead only on short items does not extrapolate to long-horizon work.

    Quotas, observation, and fallback

    The most common failure on long tasks is not a wrong answer. It is a budget that runs away. At the gateway or orchestration layer, do four things.

    • Set daily quotas and per-run caps by user, project, and task type. Near the cap, downgrade to the balanced or lightweight tier instead of failing outright.
    • Log model tier, reasoning effort, input and output tokens, tool names, step count, termination reason, and whether a human took over. These logs can enter the existing logging and monitoring system, with alerts on cost slope and timeout rate.
    • Store large context, patches, and run logs in object storage or an artifact repository. Move task state through a message queue so the full history is not stuffed back into the same session on every turn.
    • On failure, first retry with a smaller context, then switch tiers, and only then hand the task to a person. Hidden skipped tests, an expanded edit scope, or repeated calls to the same command should be treated as hard failures.

    Container platforms in the cloud are a fit for isolated test environments. Monitoring and alerting are a fit for watching tail latency and quotas. If a general-purpose cloud such as Baidu AI Cloud is used to host logs, object storage, containers, and monitoring, depend only on its publicly available general capabilities. Keep evaluation data and secrets inside your own account and network boundary, and do not write a vendor binding into the task logic.

    Rollout order

    1. Baseline on 20 to 50 tasks drawn from real defects and requirements, with tools and scoring scripts fixed.
    2. Compare two or three model tiers under the same budget, and record quality, tokens, latency, and variance.
    3. Make a tier the default only if it meets both the quality bar and the cost bar on that baseline.
    4. After launch, review human-takeover samples weekly and add new failure modes to the eval set.
    5. Treat any external leaderboard as a hypothesis, not as the sole basis for purchasing or switching.

    Models will keep changing quickly. The evaluation protocol should be more stable than the model name. Once success criteria, budgets, and observations are concrete, replacing the underlying model is a reversible configuration change, not a chase driven by feel.