IYIndo Yoon
·4 min read
Read in Korean (한국어 본문)

Where the Cost Actually Leaks When You Delegate to Coding Agents

Most people price coding agents by input tokens. Run them for a week and the real bill is reverting bad diffs. Decomposing expected time into E = (1 - p)S + pR shows why shrinking rollback cost R beats chasing lower failure rate p.

When people evaluate coding agents, the first number they check is token pricing. Run agents on real repositories for a few days and a different cost dominates: the wall-clock time spent untangling failed runs.

This note lays out the cost equation rather than a single benchmark. Plug in your own numbers and the delegation boundary falls straight out.

Expected Cost Splits Into Two Terms

Per delegated task, expected time EE is:

E = (1 - p) * S + p * R
  • p — probability the run fails verification
  • S — time spent on one clean, successful run
  • R — time spent noticing, reverting, diagnosing, and re-running a failed attempt

Token spend is already absorbed inside S and R; treating API cents separately misses the dominant human term.

Why R Almost Always Exceeds S

A failed run never costs just a second try. R compounds four distinct phases:

  1. Detection — noticing that the output is subtly broken (largest leak when automated checks are missing)
  2. Rollback — restoring a clean working tree without losing adjacent work
  3. Diagnosis — isolating whether the prompt, context, or tool boundary failed
  4. Re-execution — running the task again

Prompt engineering only nudges p downward while leaving R untouched. Infrastructure that shrinks R, by contrast, discounts every future failure regardless of model drift.

Plugging In Real Numbers

Suppose a clean agent run takes S = 4 minutes, recovering a bad run takes R = 14 minutes, and doing the task manually takes 11 minutes:

Failure Rate pExpected Time Evs Manual (11 min)
0%4.0 min2.8x faster
10%5.0 min2.2x faster
20%6.0 min1.8x faster
35%7.5 min1.5x faster
50%9.0 min1.2x faster
64%10.4 min1.1x faster
71%11.1 minBreak-even with manual

The break-even failure rate is p = (Manual - S) / (R - S) — here, 71%. Above that threshold, delegating loses time even if tokens are free.

Prompt Tuning vs Shrinking R

Start from p = 35% (E = 7.5 minutes) and compare two interventions:

  • Intervention A — Polish the prompt (p drops from 35% to 20%, R stays 14): E = 0.80 * 4 + 0.20 * 14 = 6.0 min
  • Intervention B — Build an instant rollback & test gate (p stays 35%, R drops from 14 to 5 via pre-task commits/worktrees + automated verification): E = 0.65 * 4 + 0.35 * 5 = 4.35 min

Lowering R saves nearly twice as much time as cutting the failure rate — and unlike prompt tweaks that decay across tasks, a clean worktree + verification gate is built once and compounds across every run.

Order of Operations for Cutting R

  1. Checkpoint or isolate the worktree before every run — reduces Phase 2 (Rollback) to a single command.
  2. Wire deterministic verification (tests, typecheck, DOM/build gates) — collapses Phase 1 (Detection) to seconds.
  3. Scope one logical change per run — narrows Phase 3 (Diagnosis) to one diff surface.
  4. Refine prompts last — once R is cheap, residual p reductions actually stick.

Irreversible Actions Follow a Different Equation

Everything above assumes R is finite. For irreversible external side effects — sending emails, dropping production data, deploying without instant rollback — R approaches infinity. Whenever p > 0, expected cost blows up even at a 1% failure rate:

OperationDelegate?Reason
Local code editsYesInstant git / worktree rollback
Test & build executionYesSide-effect free
Research & code readingYesRead-only
Production deployConditionalOnly behind automated canary/rollback
External messages / deletesNever unattendedR is unbounded

Before asking "Is this model smart enough for this task?", ask "How many seconds does it take to revert if it gets this wrong?" Set up the rollback path first; it is cheaper than prompt craft.