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 is:
E = (1 - p) * S + p * R
p— probability the run fails verificationS— time spent on one clean, successful runR— 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:
- Detection — noticing that the output is subtly broken (largest leak when automated checks are missing)
- Rollback — restoring a clean working tree without losing adjacent work
- Diagnosis — isolating whether the prompt, context, or tool boundary failed
- 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 p | Expected Time E | vs Manual (11 min) |
|---|---|---|
| 0% | 4.0 min | 2.8x faster |
| 10% | 5.0 min | 2.2x faster |
| 20% | 6.0 min | 1.8x faster |
| 35% | 7.5 min | 1.5x faster |
| 50% | 9.0 min | 1.2x faster |
| 64% | 10.4 min | 1.1x faster |
| 71% | 11.1 min | Break-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 (
pdrops from35%to20%,Rstays14):E = 0.80 * 4 + 0.20 * 14 = 6.0 min - Intervention B — Build an instant rollback & test gate (
pstays35%,Rdrops from14to5via 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
- Checkpoint or isolate the worktree before every run — reduces Phase 2 (Rollback) to a single command.
- Wire deterministic verification (tests, typecheck, DOM/build gates) — collapses Phase 1 (Detection) to seconds.
- Scope one logical change per run — narrows Phase 3 (Diagnosis) to one diff surface.
- Refine prompts last — once
Ris cheap, residualpreductions 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:
| Operation | Delegate? | Reason |
|---|---|---|
| Local code edits | Yes | Instant git / worktree rollback |
| Test & build execution | Yes | Side-effect free |
| Research & code reading | Yes | Read-only |
| Production deploy | Conditional | Only behind automated canary/rollback |
| External messages / deletes | Never unattended | R 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.