Time and Cost of Long-Horizon Coding Tasks: The Accounting Beyond Inference Speed

    Token generation speed and end-to-end task duration are two different metrics. For coding agents that execute multi-step tasks, total completion time is what matters, and it is composed of model generation, tool-call round trips, context compaction, failure retries, queuing, and human review. This article breaks down these six components, provides a simple estimation formula with a worked example showing that retries often dominate total time, discusses the hidden costs of context compaction and how to mitigate them, and explains why increasing compute depth can be an alternative to scaling model parameters.

    Time and Cost of Long-Horizon Coding Tasks: The Accounting Beyond Inference Speed

    1. Introduction: Token Speed and Task Duration Are Two Different Metrics

    The inference performance of large language models is usually measured in output tokens per second. This metric reflects the throughput of a single generation stream and is well suited for comparing the responsiveness of different deployment options. But for coding agents that execute tasks across many steps, users care about something else: how long it takes from receiving a requirement to delivering a usable artifact.

    The gap between the two is large. A single Q&A requires one generation, while a software development task may involve dozens of model calls, hundreds of tool operations, and multiple rounds of revision. No matter how fast generation is, if any link in the chain frequently stalls, the overall duration stretches out. Therefore, when evaluating an agent’s efficiency, end-to-end task duration should be the primary metric, with per-token speed as just one of its inputs.

    2. The Six Components of Task Duration

    The duration of a typical coding agent task can be broken down into the following six parts.

    1. Model generation time. The time required for each output equals the number of output tokens divided by the generation speed. Long code files and detailed reasoning traces both increase this portion.

    2. Tool-call round trips. The agent reads files, runs tests, queries documentation, and executes build commands. Each call carries network transfer and process startup overhead. When the number of calls is high, the accumulated time is significant.

    3. Context loading and compaction. When the conversation history exceeds the context window, the system must summarize old content or discard some information. Compaction itself consumes model calls, and afterward the agent often needs to re-read files to recalibrate its understanding of the project state.

    4. Failure retries and self-correction. Test failures, compilation errors, and insufficient tool permissions all trigger retries. The number of retries is directly related to task difficulty and requirement clarity, and it is usually the hardest component to estimate.

    5. Queuing and rate-limit waiting. The server side may queue requests during peak hours, and requests are paused when the frequency exceeds quota. This part is easy to overlook in local estimates.

    6. Human review and rework. Deliverables require human review before acceptance. If acceptance criteria are unclear, rework rounds increase noticeably, extending the overall cycle.

    3. Estimating Task Duration with a Simple Model

    Writing the above components as a formula allows for a rough estimate before scheduling:

    Total duration ≈ total generation time + total tool-call time + total compaction time + total retry time + queuing wait + human review time

    The example function below implements this estimation.

    1. def estimate_task_hours(
    2. output_tokens: int,
    3. tokens_per_second: float,
    4. tool_calls: int,
    5. avg_tool_seconds: float,
    6. compactions: int,
    7. avg_compaction_seconds: float,
    8. retry_rounds: int,
    9. avg_round_seconds: float,
    10. queue_seconds: float,
    11. review_hours: float,
    12. ) -> float:
    13. generation = output_tokens / tokens_per_second
    14. tools = tool_calls * avg_tool_seconds
    15. compaction = compactions * avg_compaction_seconds
    16. retries = retry_rounds * avg_round_seconds
    17. machine_seconds = generation + tools + compaction + retries + queue_seconds
    18. return machine_seconds / 3600 + review_hours

    Assume a medium-sized feature development task with the following parameters (all values are illustrative assumptions, not measured data): 300,000 output tokens, generation speed of 80 tokens/s, 400 tool calls at 6 seconds each, 5 compactions at 120 seconds each, 8 retry rounds at 900 seconds each, 20 minutes of queuing, and 1.5 hours of human review.

    The machine execution portion totals about 4.2 hours; adding human review, the total duration is about 5.7 hours. Broken down, generation takes about 1.0 hour, tool calls about 0.7 hour, compaction about 0.2 hour, retries about 2.0 hours, and queuing about 0.3 hour.

    This example shows that doubling the generation speed would only save about 0.5 hour. The largest cost comes from retries. Therefore, optimization should focus on reducing invalid retries and improving requirement clarity, rather than merely pursuing faster generation.

    4. The Hidden Cost of Context Compaction

    Context compaction looks like a small operation, but its cost is not low. Compaction is usually lossy: early design decisions, already-rejected approaches, and pitfalls already encountered can all be lost in the summary. The agent may then re-explore paths that were already ruled out, resulting in duplicated effort.

    Common mitigation methods include the following.

    • Write plans, progress, and key decisions into text files within the project, so the agent reads them when needed instead of relying on conversation history.
    • Control the scope of a single task and avoid involving too many modules at once, slowing context growth.
    • Reference file paths instead of pasting full file contents, reducing context usage.
    • Before compaction, proactively output a stage summary and verify that it covers all unfinished items.

    5. With Fixed Parameters, the Compute Path Can Still Grow Longer

    Capability improvements in large models usually rely on increasing parameter scale, but that raises storage and memory costs at the same time. Another line of thinking reuses the weights of the same set of layers, letting the input pass through them multiple times to form a recurrent or recursive compute depth. In academic research, this type of method has several implementations.

    The core characteristic of this design is that the total parameter count stays the same, while the number of compute steps each token passes through increases, making the effective depth greater. It can be compared to a team of reviewers reading the same material over multiple rounds, rather than expanding the team itself.