Chapter 1 established that enterprise modernization with generative AI fails because teams wrap a fast generator in a slow process, and that agile's real contribution was shrinking the distance between making a mistake and finding it. Chapter 2 examined the obvious fix — running agents in tight micro-loops — and found three walls: self-healing agents that game their own judge, role-play swarms that mistake consensus for evidence, and an amnesia that makes the same bug return every week.
Chapter 2 concluded with two requirements. The checks that decide whether a change is acceptable must sit outside the generator's reach, and generation, verification and memory must be separate components with separate permissions.
Requirements are not an architecture. This chapter turns them into three components that can be built, staffed and operated: an independent judge, a feedback-to-schema engine, and contract-bound micro-contexts. They are not three improvements to a prompt. They are three places where the system says no.
The shape of the system
The whole system on one page.
┌────────── contract compiler ─────────┐
contract ────▶│ write-set · read-set · pre/post │──▶ micro-context
└──────────────────────────────────────┘
│
▼
sandboxed synthesis (N workers, disjoint write-sets, judge read-only)
│ diff + artifacts
▼
independent judge ─▶ tier 0: types ─▶ tier 1: contracts
│ │
│ ├─▶ tier 2: mutation · integration
│ │
fail ◀───┴──────────────┘
│
├─▶ repair (bounded) ─▶ human
│
pass ─▶ merge + telemetry ─▶ schema engine
│
rule store ◀─────────────┘
│
rules enter judge and compiler (next run)
Read it as three loops with three different clocks. Synthesis runs in minutes. Verification runs in minutes too, but it is the loop that sets the pace. The schema engine runs in hours or days, because a human is usually in it. Contract edits are made by an architect, deliberately and rarely.
The rest of this chapter takes the pillars one at a time, then examines how the architecture fails.
Pillar I: Decoupled deterministic arbitration
The judge must not be editable by the defendant
In almost every production agent setup, the test suite is just more files in the repository, and the agent has write access to all of it. Nobody decided this. It is the default, and the default makes the loop self-grading.
Chapter 2 described the consequences: a loosened assertion, a mocked dependency, a special case for the test input, a test marked skipped "temporarily". Each looks defensible in a diff. Together they let an agent reach green without fixing anything.
The fix is not a stricter instruction. It is a permission boundary. The judge lives outside the repository the generator can write to, is mounted read-only into the synthesis sandbox at a pinned version, and changes to it go through a separate review path owned by someone other than the team shipping the feature. Every merge record then carries the digest of the judge that approved it. If the judge changes, the evidence changes, and it can be seen.
This is the same design choice SWE-bench made when it hid its evaluation tests from the agent. It is what makes a score mean something. Production systems usually drop it by accident.
Only deterministic verdicts count as evidence
A gate should return pass or fail, not a paragraph. That limits what can serve as the final arbiter:
- a compiler and a type checker;
- contract and property-based tests;
- schema validation at API, message and database boundaries;
- integration runs in a container that resembles production;
- static analysis and policy checks: banned APIs, secrets, licences, dependency direction;
- a mutation score, which measures whether the tests can detect faults at all;
- a dependency blast-radius check, which measures how much of the estate the diff can reach.
An LLM reviewer can still be useful. It can flag a design smell, suggest a simpler interface, or predict which module will break. It should be advisory. The moment a model's approval is the thing that lets a change through, the loop is coupled again, just with an extra step and a bill.
The distinction is not philosophical. Consensus between two similar models is weak evidence, because they share training data, blind spots and a preference for fluent code. A compiler that refuses to build is evidence. Keep the opinions, but do not let them be the gate.
Testing the tests
A deterministic gate is only as trustworthy as its assertions, and in an AI-native pipeline the assertions are often written by the same kind of model that writes the code. A suite that asserts almost nothing passes everything and looks like a gate.
Mutation testing is the cheapest defence. Tools such as PIT, Stryker and mutmut introduce small faults into the code, one at a time, and check whether the suite fails. A suite that survives most mutations is not verifying behaviour; it is verifying that the code runs. Score it, set a floor per package, and let the floor rise as the suite improves.
For critical invariants, add holdout tests the generator never sees and cannot retrieve. They are the equivalent of an exam with an unseen paper. When an agent repeatedly passes the visible suite and fails the holdout, something important has been learned about the visible suite, and the schema engine has work to do.
Risk-tiered gates
Not every change deserves a full verification run. Running everything on every micro-sprint makes the judge the bottleneck for no reason. Gates should be tiered by the risk of the contract, and the tier should be fixed by the contract, not chosen by the generator:
- Tier 0: compile, types, lint, secret scan. Seconds. Always.
- Tier 1: unit, contract and property tests for the touched interfaces. Minutes.
- Tier 2: mutation score on changed packages, integration in a production-like container, dependency and blast-radius audit.
- Tier 3: performance budgets, security review, migration rehearsal, human sign-off for irreversible changes.
The agent may know which tier applies. It may not change it. That single rule removes a large class of "the tests were slow so I skipped them" behaviour.
| Tier | Checks and cost |
|---|---|
| Tier 0 | Compile, types, lint, secret scan. Seconds. Always. |
| Tier 1 | Unit, contract and property tests for the touched interfaces. Minutes. |
| Tier 2 | Mutation score on changed packages, integration in a production-like container, dependency and blast-radius audit. |
| Tier 3 | Performance budgets, security review, migration rehearsal, human sign-off for irreversible changes. |
Pillar II: The feedback-to-schema engine
Redefining done
Agile's definition of done was about shared understanding: tested, reviewed, documented, deployed. In an AI-native pipeline it needs one more clause.
A task is not done when the code passes. It is done when the reason the code was corrected has been encoded somewhere the system enforces.
That sounds bureaucratic until the cost is counted. Human review is the most expensive input in the pipeline: it is slow, scarce, and it is the only source of judgement that is not a sample from the same model. If a correction is made in a review comment and disappears when the pull request closes, the organization pays for the same lesson again next week. Chapter 2 named this amnesia. The schema engine is the cure.
From prose to constraint
Feedback arrives as prose: "don't round before the ledger write", "this client is deprecated", "the retry must be idempotent", "we cannot hold a transaction across the HTTP call". Prose is advice. Advice is followed sometimes.
The engine's job is to move each piece of feedback down a ladder of increasing strength:
- A regression test. The exact input that broke, as a fixture. Cheap, narrow, and it stops the specific bug from returning.
- A property or contract test. The class of input that broke, expressed as an invariant. Broader, and it survives refactoring.
- A static rule. A linter rule, a type constraint, a dependency rule (ArchUnit and similar tools make architecture testable), a banned API, a JSON Schema or database constraint. Now the mistake fails before the tests run.
- An interface change. The strongest form: make the mistake unrepresentable. A currency type instead of a bare decimal. A non-nullable result. A function that cannot be called without a transaction handle. A result type that forces the caller to handle the error.
The rule of thumb: encode at the strongest level that is cheap. Not every lesson deserves a type-system change, but most teams stop at level 1 when level 3 was a twenty-line rule.
A rule is only real if it is verified
Adding a rule is a change to the judge, so it needs evidence like any other change. Three checks, in order:
- It fails on the offending commit. Take the bug that produced the feedback, replay it, and confirm the new rule rejects it. A rule that would not have caught the incident is documentation.
- It passes on current main. Otherwise the build is broken to teach a lesson.
- It does not flood the estate. Run it in shadow mode first, count the hits, and read a sample. A rule with three hundred true positives is a migration. A rule with three hundred false positives will be disabled within a week, which is amnesia with extra steps.
Rules have a lifecycle and a budget
Constraint systems rot in a predictable way. Rules accumulate, nobody remembers why one exists, false positives make developers route around the linter, and eventually someone turns the whole set off. The engine has to manage rules as products:
- Proposed, with a link to the incident or review that justified it.
- Shadow, measured but not enforced.
- Enforced, with an owner and a false-positive budget.
- Retired, with a reason, when the underlying risk is gone.
Every rule needs an owner and a rationale link, because the alternative is a rule base nobody dares touch. Consolidate rules periodically. Count how many times each one fires; a rule that never fires may be dead weight, and one that fires constantly may be describing a design problem rather than catching mistakes.
Why not a longer instruction file
Project instruction files, style guides and "rules" documents help, and teams should keep them. They share one weakness: they are natural-language advice of unbounded length, with no enforcement and no test of whether they were followed. Nothing fails when the model ignores paragraph forty.
The schema engine's output is different in kind. It is executable, versioned, owned, and it fails a build. Chapter 2's third wall was that corrections were stored as advice. This pillar stores them as machinery.
Pillar III: Contract-bound micro-contexts
Compile the context, do not retrieve it
Retrieval answers a question: what looks similar to this task? Synthesis needs a different question answered: what is in scope, and what must hold?
Those are not the same. Chapter 1 explained why retrieval fails on cross-cutting concerns: the rule that "settlement amounts are never rounded before the ledger write" is not textually similar to the forty call sites that can violate it. A retriever will happily return the wrong forty files, or the right helper and none of its callers.
So stop retrieving. Compile the context deterministically from the contract, the dependency graph and the rule store:
- which files may be modified (the write-set);
- which interfaces and types may be depended on (the read-set);
- which invariants, pre-conditions and post-conditions must hold;
- which error semantics and side effects are permitted;
- which budgets apply: latency, memory, cost, transaction duration;
- which gates apply, at which tier;
- and, explicitly, the non-goals, so "while I was here" refactors are out of scope.
Same contract, same context. A run becomes reproducible, which means a failure becomes debuggable instead of anecdotal.
The write-set is a permission, not a suggestion
A contract that says "please only modify these files" is advice again. The write-set should be enforced by the sandbox's filesystem permissions and checked against the diff at the end. An edit outside it fails the run, full stop.
This single mechanism does more for reliability than most prompt engineering. Scope creep stops being a review conversation and becomes a failed build. Changes that would have quietly touched a shared module cannot land. The blast radius of a bad micro-sprint is bounded by construction rather than by hope.
It also makes parallelism safe. Ten workers can synthesize at once if their write-sets are disjoint and their shared interfaces are read-only. Conflicts surface at the contract level, before any text is merged, instead of as a merge conflict three hours later.
Contracts are the senior engineer's artifact
Chapter 4 argues that the senior engineer's output shifts from code to invariants. This pillar is where that happens concretely. The contract is the design: the interface, the guarantees, the budgets, the boundaries, the definition of acceptable evidence.
Review moves up a level with it. A reviewer who used to read two hundred lines now reads a page of contract and a verdict from the judge, and spends their attention on the part a machine cannot check: is this the right boundary, is this invariant actually true of the business, is the non-goal list complete.
That is also the only way one architect can supervise many parallel workers. You cannot read every diff. You can read every contract, and you can require that the diff never crosses one.
How the pillars work together
The three pillars are not independent features. They are a single control loop, and each one closes a hole the others leave open.
- Without Pillar I, the agent grades its own work, and every other control is downstream of a compromised verdict.
- Without Pillar II, the same class of bug returns forever, and the judge's rules never improve from the incidents it sees.
- Without Pillar III, the agent chooses its own scope, so the context drifts and no amount of arbitration can tell whether the change was the one that was asked for.
Together they produce a property none of them has alone: a micro-sprint whose blast radius is known before it starts and whose lesson is retained after it ends.
That is what makes sub-hour iterations safe rather than merely fast. The sprint can be short because the scope is bounded, the verdict is independent, and the correction persists.
What breaks this architecture
An honest architecture document includes the ways it fails. This one has five.
The judge becomes the bottleneck. It will be, and that is the point. Once synthesis is cheap, throughput is set by verification. Teams used to buying more generation capacity discover they need to buy test infrastructure, golden datasets, ephemeral environments and mutation runs. If the judge takes forty minutes, the sprint is forty minutes no matter how fast the code appears. Plan for it, and tier the gates so the cheap checks run constantly.
Rules accumulate until nobody trusts them. Constraint systems grow monotonically unless someone is responsible for pruning. Without owners, budgets and retirement, the rule store becomes a wall of noise that developers route around. Treat the rule base as a product with a roadmap.
Contract authoring becomes the new bottleneck. Architects can only write so many contracts a day. Templates, a contract DSL, and generating first drafts from existing interfaces and OpenAPI specs help, but the real fix is reuse: most micro-sprints should extend an existing contract, not invent one.
The contract can be gamed. An agent can satisfy the letter of a weak contract, exactly as it can satisfy a weak test. Mutation testing, holdouts and contract review are the countermeasures. A contract is a specification, and specifications can be underspecified.
Organizational pressure re-couples the judge. This is the failure mode that kills the architecture in practice. If the team that owns the judge also owns the delivery date, there will eventually be a week when the gate is loosened to ship. Independence has to be structural: a separate owner, a separate budget, and an escalation path that does not run through the release manager.
A staged adoption path
Nobody should build all three pillars at once. The order matters, because each step makes the next one cheaper.
- Separate the judge. Move the test suite and verification credentials out of the generator's write path. Pin a version, record its digest in the merge. This is mostly permissions and CI identity, and it removes the worst failure immediately.
- Make the judge trustworthy. Add mutation testing to the packages that matter, and holdout tests for the invariants that matter most. Now a green run means something.
- Start the schema engine with incidents, not aspirations. Take the last twenty production incidents and the last fifty substantive review comments. Encode the five that recur. Verify each rule by replay before enforcing it.
- Introduce contracts in one bounded domain. Pick a service with clear interfaces. Write the write-set, the pre/post conditions and the gate tier. Run micro-sprints inside it for a month and measure the escape rate.
- Only then shorten the cycle. Two-week sprints to one day, one day to hours. Speed is the output of the architecture, not an input to it.
The sequence matters because each stage produces the evidence needed to justify the next. A team that starts by declaring one-hour sprints has inverted it, and will spend the next quarter discovering why verification cannot keep up.
Next
Chapter 4 turns the architecture into an operating blueprint: a sixty-minute iteration with four phases, the queueing model behind it, and what the post-coder role of a senior engineer actually looks like day to day.