Your AI Agent Passed Every Test. So Why Is Production Down?
A spec constrains one unit of work. It doesn't constrain the system that unit lands in. That's what guardrails are for.
On this page
The most expensive deployment in history took forty-five minutes and cost $440 million. The code was fine.
On 1 August 2012, Knight Capital deployed new trading software to eight production servers. Seven of them updated correctly. The eighth didn't. It kept running old code, which contained a dormant feature — Power Peg — that had been repurposed years earlier and never fully removed.
At 9:30 that morning, the market opened. The stale server began executing orders. Millions of them. Nobody could stop it, because nobody had built a way to stop it.
1 AUGUST 2012 — KNIGHT CAPITAL
08:00 deploy begins
┌───┬───┬───┬───┬───┬───┬───┬───┐
│ ✓ │ ✓ │ ✓ │ ✓ │ ✓ │ ✓ │ ✓ │ ✗ │ 8 production servers
└───┴───┴───┴───┴───┴───┴───┴───┘
│
└── server 8 kept the old code
containing a dormant feature
called Power Peg
09:30 market opens
server 8 begins executing orders
at a rate nobody intended
┌──────────────────────────────────────────────┐
│ │
│ 45 minutes · millions of orders │
│ $440M lost │
│ │
│ no kill switch │
│ no canary │
│ no rollback that would have worked │
│ │
└──────────────────────────────────────────────┘
10:15 trading halted
end of year: firm sold
SEC fine: $12M
Nobody wrote bad code that morning. The deployment was the failure — one server out of eight running the wrong version, no automated check that all eight matched, and no mechanism to stop the damage once it started.
This is the gap this post is about. You can write a perfect spec. An agent can satisfy it perfectly. Production can still break — because the spec constrains the unit of work, and it does not constrain the system that unit lands in.
That's what guardrails are for.
The Principle #
One sentence, and everything else in this post elaborates on it:
Every change must be reversible in minutes, observable in seconds, and attributable to a person.
Three properties. Each one rules out a class of failure.
Reversible in minutes rules out the midnight revert, the hotfix scramble, the four-hour incident. If you can't undo it in fifteen minutes, you don't have a rollback. You have a rollback plan, and plans are what you write when you can't do the thing.
Observable in seconds rules out the slow burn. If a change is degrading a metric and you don't know until a customer complains, your feedback loop is measured in days. Days are how Knight Capital lost $440 million.
Attributable to a person rules out the governance theater we covered in Post 2. If a decision has no name on it, it has no owner. If it has no owner, it has no consequence — until it does, and the consequence arrives as a Slack message from a compliance bot at 4:07 on a Friday.
Why Teams Skip the Guardrail #
Here is the thing nobody says out loud about feature flags.
A feature flag is a written admission that you might be wrong. Functionally, that is what it is. It says: this change is shipping, and I am not certain enough to make it irrevocable. Every flag in your system is a small public statement of fallibility, committed to a repository your whole team can read.
That is one reason teams skip them. But it's not the main one, and the ego explanation is too easy. The real reason is a cost-allocation problem, and it's worse than ego because it doesn't resolve with better character.
Consider who pays and who benefits:
WHO PAYS FOR THE GUARDRAIL WHO BENEFITS FROM THE GUARDRAIL
───────────────────────────── ────────────────────────────────
the engineer shipping today the on-call engineer next Thursday
at 4:55 on a Wednesday at 2 in the morning
15 minutes of setup four hours of incident avoided
one more thing to remember one fewer page at 2 a.m.
a flag to write, test, and delete a customer who never notices
the visible cost of prudence the invisible benefit of an incident
that didn't happen
The person who pays is not the person who benefits. And the benefit is an incident that did not happen, which means it cannot be counted, celebrated, or added to a performance review. The cost is visible and immediate. The benefit is invisible and hypothetical. Any rational actor, optimized for their own incentives, will skip the flag — and be right, by the metrics they are measured on.
This is not an ego problem. It's a structural misalignment, and it explains why the same team can be rigorous about incident response and cavalier about prevention. Post-incident, the cost and the benefit land on the same person, at the same time, and the incentive flips. Before the incident, they don't.
The fix is not to ask individuals to be more virtuous. It's to change who pays. Automate the guardrail, put it in the PR template, make the pipeline refuse without it. Then the cost of the guardrail is zero to the individual engineer — and the benefit, eventually, is theirs too, at 2 a.m. on a Thursday when nothing pages.
The teams without flags are not braver. They're not even more reckless. They're just responding correctly to an incentive that punishes prevention and rewards speed.
The teams with the most flags have done one thing differently: they made the guardrail free at the point of use, and they made its absence fail the build.
That is the whole trick.
And here is the second half. When you know you can flip a flag and be safe in fifteen minutes, you ship more, not less. You experiment. You ship on Thursday afternoon. You deploy a feature to five percent of users and watch. Reversibility is not a brake. It is the thing that lets you take your foot off it.
The trade is lopsided: pay a small cost once, at the pipeline level, and get speed forever.
The Two Families of Guardrails #
Guardrails come in two families, and confusing them is how teams end up with one and not the other.
THE GUARDRAIL STACK
ARCHITECTURAL DELIVERY
keeps the codebase sane keeps production sane
┌──────────────────────────┐ ┌──────────────────────────┐
│ enforced module │ │ feature flags │
│ boundaries │ │ as a precondition │
│ │ │ │
│ deep modules │ │ small, trunk-based │
│ (simple interfaces, │ │ changes │
│ hidden complexity) │ │ │
│ │ │ progressive delivery │
│ fitness functions │ │ canary → % → full │
│ (Post 5) │ │ │
│ │ │ independent CI gates │
│ ADRs with status │ │ (mutation, contract, │
│ │ │ property, security) │
│ ubiquitous language │ │ │
│ │ │ observability as │
│ agent-legible codebase │ │ definition of done │
└──────────────────────────┘ └──────────────────────────┘
│ │
└──────────────────┬───────────────────┘
▼
every change: reversible, observable,
attributable
Architectural guardrails #
These stop the codebase from becoming a place where correct changes are dangerous.
Enforced module boundaries are the load-bearing one, and they matter more with agents than without. An agent will import whatever is convenient in the moment. A rule that says ui may not import infra is not a style preference — it is a boundary that will be violated the first time importing becomes convenient. The difference between a boundary and a wish is whether the build fails:
// ArchUnit — fails the build, does not warn
noClasses()
.that().resideInAPackage("..ui..")
.should().dependOnClassesThat()
.resideInAPackage("..infra..");
// ESLint — a configuration, not a suggestion
"import/no-restricted-paths": ["error", {
zones: [{ target: "./src/ui", from: "./src/infra" }]
}]
That's the whole guardrail. Six lines, enforced in CI, un-bypassable without a PR that visibly changes the rule. The agent cannot quietly violate it. That is the point.
Deep modules — Ousterhout's principle — reduce the surface an agent has to get right. Small interfaces, hidden complexity. Shallow modules with tangled interfaces are where agents hallucinate dependencies and "fix" the wrong thing.
ADRs with status make decisions findable. A ubiquitous language keeps "refund" from becoming "reversal." An agent-legible codebase — explicit entry points, a MAP.md, one error style — reduces the guessing the agent has to do.
Delivery guardrails #
These stop the system from becoming a place where a correct change is catastrophic.
Feature flags as a precondition. Not a best practice — a gate. Small, trunk-based changes. Small diffs are reviewable by humans and verifiable by machines. Progressive delivery. Canary, percentage rollout, automated promotion gates. Independent CI verification. Mutation testing on changed files, contract tests, property tests — because the agent wrote the tests too, and its errors are correlated with its code. Observability as Definition of Done. No instrumentation, no merge.
Conway's Law runs underneath both. Your system will tend to copy your communication structure whether you want it to or not. Guardrails are how you stop the org chart from becoming the system's failure mode.
Cook's observation in How Complex Systems Fail is the condition underneath all of this: complex systems operate as broken systems. They continue to function because they contain so many redundancies, and because people intervene to keep them working despite the flaws. That is the argument for guardrails in two sentences. You are not making the system not-broken — you cannot. You are adding redundancies so that when it breaks, the breakage is contained.
Ousterhout's account of complexity gives the mechanism. Complexity, in his framing, is whatever makes a system hard to understand and hard to modify, and it has two causes: dependencies, where a change in one place forces changes elsewhere, and obscurity, where important information isn't obvious when you need it.
Map that onto the two families and the design becomes legible. Architectural guardrails attack dependencies — a boundary rule means a change in ui cannot force a change in infra, because the dependency doesn't exist. Observability attacks obscurity — you can see what the system is doing without reconstructing it from memory. And delivery guardrails limit the blast radius when both fail anyway, which they will.
This is Brooks' conceptual integrity, enforced by machinery instead of by memory. The three families aren't a checklist. They're three answers to the two ways a system becomes hard to work with.
The Pre-Deploy Gate #
Here is the artifact. Paste it into your PR template.
PRE-DEPLOY GATE — paste into your PR template
□ Feature flag exists and defaults to OFF
□ Flag name follows convention: ..enabled
□ Canary plan defined: target %, duration, promotion criteria
□ Rollback procedure stated: flag flip / revert / both
□ Instrumentation present: metric, log, and alert tied to this change
□ Blast radius tier assigned: low / medium / high
□ If high: signed change record, on-call notified, rollback plan reviewed
□ Independent CI gates green: mutation, contract, property, security
□ Observability confirmed: this change is visible in dashboards
□ Rollback rehearsed, or previously verified for this service
If any box is unchecked, the change does not ship.
Ten lines. It takes ninety seconds to complete and it is the difference between a fifteen-minute rollback and a four-hour incident. It's also the thing that makes the cost-allocation problem disappear: the checklist is in the template, the pipeline refuses without it, and the individual engineer no longer has to choose between shipping and being prudent.
Not All Changes Are Equal #
The mistake most teams make is applying one process to every change. A copy edit and a payments migration do not deserve the same ceremony, and treating them the same is how you get both slow deploys and dangerous ones.
Tier the change by blast radius.
| Risk | Examples | Required guardrails |
|---|---|---|
| Low | UI copy, flags, docs | Automated gates only |
| Medium | Service logic, non-critical APIs | Canary, automated rollback, on-call aware |
| High | Auth, payments, migrations, infra | Human go/no-go, signed change record, staged rollout, explicit rollback plan |
The signature at the high tier is the point. It converts a model output into an accountable decision. And — as we covered in the decision-layer argument — that signature has a shelf life. A signed threshold is valid for one model version and one data distribution. Retrain, and the signature is void. If the sign-off doesn't survive the next retrain, it isn't governance. It's theater.
Now look back at the settlement export from earlier in this series. It was a medium-risk change. It should have been caught by a feature flag, or by an API contract diff on the consumer side. Either would have cost fifteen minutes. It cost three days, and it was found in Europe, in a reconciliation report nobody reads until the numbers don't add up.
Tiering is how you keep the ceremony meaningful by not requiring it where it isn't warranted. The reason many teams have slow, dangerous deploys is that everything is treated as high-risk — so nobody builds the low-risk path, so every change goes through the same ceremony, so the ceremony becomes the bottleneck, so people skip it, and the ceremony stops protecting anything.
The Loop #
None of this works as a checklist. It works as a closed loop.
THE LOOP
┌──────────┐ ┌────────────────────────────┐
│ SPEC │──────►│ ARCHITECTURAL GUARDRAILS │
│ (Post 3) │ │ boundaries · deep modules │
└──────────┘ │ ADRs · ubiquitous language│
▲ └─────────────┬──────────────┘
│ │
│ ▼
│ ┌────────────────────────────┐
│ │ DELIVERY GUARDRAILS │
│ │ flags · canary · tiers │
│ │ independent CI · sign-off│
│ └─────────────┬──────────────┘
│ │
│ ▼
│ ┌────────────────────────────┐
│ │ PRODUCTION │
│ │ DORA: freq · lead · CFR · │
│ │ MTTR │
│ └─────────────┬──────────────┘
│ │
└───────────────────────────┘
incidents → new invariants (Post 2)
Production signals feed back into the next spec. Incidents become invariants. Drift becomes a new fitness function (Post 5). The agent that broke the settlement export teaches you to write the contract you were missing.
The instrument for measuring whether the loop is working is DORA — deployment frequency, lead time for changes, change failure rate, and time to restore. Four numbers, and they only mean something together.
Here is the trap. AI will raise deployment frequency. It will probably lower lead time. If it also raises change failure rate and time to restore, you haven't improved delivery — you have automated the production of risk. More changes, more incidents, same output of value. DORA is how you catch that before your customers do.
You don't measure deployment frequency to go faster. You measure it to know how fast you can safely go.
The Concession #
I want to be honest about the cost, because "add guardrails" sounds like an invitation to bureaucracy and sometimes it is.
Yes, guardrails slow individual changes. A canary takes fifteen minutes you didn't spend before. A feature flag is code you have to write and eventually delete. A signed threshold at the high tier requires a meeting. These are real costs, and they're paid by the person making the change, at the moment they most want to ship.
But the comparison isn't guardrail versus no guardrail. It's guardrail versus the cost of the incident you don't have yet. And the cost of an incident is not just the four hours of downtime. It's the on-call engineer who leaves. It's the trust you lose with the customer who noticed. It's the two weeks the team spends on the postmortem and the follow-up work and the "how could this have happened" that ends with everyone agreeing to add the guardrail you should have had.
DORA's finding is not that high performers deploy more because they take more risk. It's that they achieve speed through stability. The teams with the fastest recovery have the most confidence to change. The teams with the most confidence change most. That is the whole mechanism.
Speed without reversibility isn't speed. It's a countdown.
The teams that move fastest aren't the ones with the fewest guardrails. They're the ones whose rollback is fifteen minutes, whose canary tells them at 5% instead of 100%, whose flags let them ship on Thursday afternoon without a Friday-morning incident. They look less cautious. They're actually more willing to take risks — because the risk is bounded.
The Convention That Isn't #
Here's the test that separates real guardrails from the ones your team talks about.
For each guardrail you claim to have, ask: is this a convention or a blocking gate?
If it's a convention, it's already being violated. Someone skipped the review. Someone deployed on a Friday. Someone merged without the flag. You just haven't found out yet.
If it's a blocking gate, the pipeline refuses. Not warns. Not comments. Refuses.
Go through your guardrails and count. Most teams find that three or four are real and the rest are folklore. The real ones are the reason nothing catastrophic has happened yet. The folklore is the reason it will.
Conventions are guardrails you haven't violated yet. The gate is the guardrail. The convention is the wish.
The spec is a promise. The guardrail is the enforcement. A promise without enforcement is a Knight Capital deployment — forty-five minutes of orders nobody meant to place, and a lesson somebody else already learned for $440 million.
You don't have to learn it again.
The Bottom Line #
So here's the test I want you to run.
Think of your last production incident. Now name the guardrail that would have caught it.
Not the fix — the guardrail. Was it a flag that would have let you ship to 5% first? A canary that would have caught the error rate in fifteen minutes? A boundary rule that would have failed the build? A contract test that would have flagged the shape change?
If you can name it, that's your next guardrail. Build it this week. The incident already told you where the hole is.
If you can't name it — if the incident was something the guardrail stack doesn't reach, or if you can't quite see which gate would have stopped it — then the hole is bigger than you thought, and it's time to look at the whole stack, not just the incident.
One guardrail deserves its own post, because it's the one nobody owns and the one agents erode fastest. QA will never catch it. Your tests will stay green while it rots. It's the tripwire on the shape of the system — and it's the last post in this series.
Next: the fitness function — the guardrail that catches architectural erosion while every test stays green.
Get new posts by email
Essays on AI coding agents and engineering practice. No spam, unsubscribe anytime.
Comments
Loading comments...