The factory that doesn't eat your budget
An autonomous factory has a failure mode CI never had: it can keep spending. 'Keep going until it's fixed' is a great instruction and a terrifying one. Cost has to be a first-class constraint, not a metric you check after the fact.
CI has a fixed cost profile: you know roughly what a pipeline run costs, and it stops when it’s done. An autonomous factory doesn’t. It can retry, branch out, spin up workers, and burn tokens while it works — and “keep going until it’s fixed” is a great instruction and a terrifying one. Left unattended, that mode can scale to thousands of workers and a very large compute-and-token bill overnight, before anyone notices.
So cost has to be a first-class constraint — something the factory obeys while it runs — not a metric you look at in the morning.
The cap ladder
Cost control isn’t one number; it’s a stack of ceilings, each one catching what the one below it can’t:
global factory budget (the hard outer bound)
┌───────────────────────────────────────────────┐
│ per-team budget │
│ ┌─────────────────────────────────────────┐ │
│ │ per-job caps │ │
│ │ ┌───────────────────────────────────┐ │ │
│ │ │ a single job: tokens, spend, │ │ │
│ │ │ wall-clock, retries │ │ │
│ │ └───────────────────────────────────┘ │ │
│ └─────────────────────────────────────────┘ │
└───────────────────────────────────────────────┘
The innermost cap bounds a single job; the outermost bounds the whole factory. A runaway job is caught at the job level; a runaway team is caught higher up. Design each layer so the one below failing loudly doesn’t blow the one above.
Hard caps, and the factory stops at them
Every job and every factory gets ceilings: max concurrent workers, max tokens, max spend, max wall-clock. And the critical behavior is what happens at the ceiling: the factory stops and asks — it becomes a decision gate, holds its state, and notifies — it does not keep going. A cap the system can exceed or ignore isn’t a cap.
caps:
per_job:
max_concurrent_workers: 4
max_tokens: 2_000_000
max_spend: 25.00 # in currency units
max_wall_clock: 45m
max_retries: 3
on_breach: stop_and_ask # never: continue | ignore
Design for the worst case. Ask: what happens at 100× the expected concurrency and spend? The caps have to make that a non-event. An unattended “until it’s fixed” mode is only safe if the ceiling sits below the point where the damage is annoying.
Meter per job, from day one
Track tokens, spend, and utilization per job, from the first run. Not (only) for billing — for modeling. A per-job meter record is the unit everything else is computed from:
{
"job_id": "j-1042",
"ticket": "4821",
"tokens": 1_840_000,
"spend": 18.40,
"wall_clock": "22m10s",
"workers_peak": 3,
"outcome": "done"
}
Before you scale the factory out to more teams, you need real numbers: cost per task, nodes per developer, how utilized the pool actually is. You can’t price the service, set sane caps, or right-size hardware without them. Teams that skip this find out their unit economics the expensive way, after they’ve already scaled.
Utilization is the other half
Spend without utilization is waste in the other direction. A pool that’s ninety percent idle is as much a mistake as one that runs away — you’re paying for capacity the work isn’t using. Right-size the pool, and especially the dedicated host-locked hardware slice (the expensive part), against measured demand, not a hunch.
The trade-off, stated plainly
A cap is a false-stop cost in exchange for a runaway bound. Set it tight and you’ll get jobs that hit the ceiling and stop-and-ask when they were one more iteration from done — a human wakes up to approve a continuation that would have been trivial. Set it loose and you’ve bought throughput with the risk of a bill you didn’t expect. There is no cap that’s free.
The honest way to hold it is the same as the autonomy dial: price the cap against the cost of being wrong. A cheap, reversible job can afford a loose cap; an expensive, hard-to-undo one wants a tight one with a hard stop. “What should the cap be?” is the wrong question — “how much does a false stop cost versus how much does a runaway cost?” is the right one.
Autonomy and budget are the same dial
The more autonomy you grant an agent — the further it can run without a human — the more the caps have to hold. Autonomy and budget control are two sides of one principle: trust, but bound. Give the factory room to work, and make the boundaries hard.
Open questions
- How do you set the “worst case” ceiling? It should be below the point of real damage, but “real damage” depends on the team’s budget and the job’s blast radius. I don’t think there’s a universal number — it’s per-team, and it should be revisited as metering produces real data.
- How do you meter tokens you can’t see? Compute is metered cleanly; token spend depends on the model and the agent’s behavior, which is noisier. The per-job record above assumes you can attribute tokens to a job — that attribution is easier to claim than to get exactly right.
- Per-team vs. global budgets. A global cap protects the company; a per-team cap protects the team. Reconciling the two (a team that’s under its budget but the factory is over its global one) is a policy call, not an engineering one — and I’m least sure about it.
This is part of the Software Factory series.