When Code Is Free, Architecture Is the Job: Governing Software Built by AI Agents
My English retelling of @hylarucoder's essay on why AI coding agents rot codebases, and the five layers of guardrails that keep a long-lived system maintainable.
Source: @hylarucoder (海拉鲁编程客), "当写代码的速度趋近于无限,我们靠什么守住软件的命门?", X article in Chinese, 31 October 2026. This is my English summary and commentary, not a full translation. The ideas and structure are the author's; the wording and the opinions in "My take" are mine.
I run several coding agents most days, and the hard question stopped being "can it write this?" some time ago. Now it's "will anyone still understand this repo in three months?" This essay is the most practical answer I've read, because almost every fix it proposes is a type, a script or a CI gate rather than a longer prompt.
The problem: growth without understanding
The author starts with a scene many of us have lived through. You queue up a handful of tickets for agents before bed, and in the morning everything is green: tests pass, no merge conflicts, thousands of new lines. Nobody can review that much code before stand-up, so it gets merged on trust. A few weeks later every small change touches a dozen files, fixed bugs come back, and eventually an incident hits a codebase that no human on the team really understands.
The essay's thesis is that cheap code flips the central problem of software engineering. Speed is no longer the constraint. The constraint is keeping entropy down and keeping the system understandable to the people responsible for it.
Why agents make this worse
The author doesn't blame weak models. The mess follows from what an agent optimises for, which is getting the current ticket to pass with the smallest, safest-looking change. In practice that shows up as a handful of habits:
- It patches locally and never refactors globally, so the third similar integration is a copy of the second with two lines changed.
- It won't delete anything it isn't sure about. Old functions survive next to their replacements, and later agents read the dead code as if it were live.
- Under pressure it reaches for
as any, swallowed exceptions, or, worst of all, editing a test's assertion until it passes. - It writes happy-path code: queries inside loops, caches that never evict, full rewrites of state on every small update.
- Every session starts with amnesia, so unwritten architectural rules get broken and each agent picks its own date library.
- Detailed instructions help less than you'd hope. Agents follow most of a rules file and skip the one rule that mattered.
The author's conclusion from that last point is the one I agree with most: a rule that lives only in documentation, unchecked by a compiler or script, should be assumed broken. Agents have split writing code apart from maintaining architecture. Humans have to supply the force that pulls the system back together, and prompts aren't strong enough to do it.
The answer: a five-layer "anti-entropy" pyramid
The essay organises its fixes into five layers. The lower layers lean on compilers and deterministic scripts, which are fast, exact and cost no tokens. The upper layers are about locking down what "correct" means and being willing to throw implementations away. I've grouped the ten techniques the essay describes rather than walking through each one.
Layers 1 and 2: let the machine say no
Make the compiler find the missed edits. Model state as discriminated unions with exhaustiveness checks instead of piles of booleans, and ban default branches. When an agent adds a new state, the compiler lists every place that doesn't handle it yet, which gives the agent a precise to-do list. Branded types (separate Cents and Millicents, a distinct type for a validated path) push the same idea into units and validation order.
Write lint errors as fixes. This was the idea that stuck with me most. In an agent loop the error output is the last thing the model reads before its next attempt, so it works as a prompt. The author writes AST rules (ast-grep in the examples, though ESLint, Semgrep, Biome and dependency-cruiser can all do versions of it) whose messages include the approved replacement and a pointer to a reference file. The author reports that agents then fix the violation on the next try more than 95% of the time.
Delete dead code automatically. Run reachability tools such as knip in CI and fail the build on unreferenced exports. Require every @deprecated tag to carry a removal date that the build enforces.
Give agents blanks to fill in, not a blank page. Organise the repo by feature, with one public entry point per feature. Put timeouts, retries, locks and process clean-up into a small harness that humans review and then lock, so a new integration is a narrow adapter that can't leak resources. Route core state changes through a single state machine and let everything else subscribe to events.
Layer 3: lock the contracts, test deterministically
Split the repo into a read-only zone (schemas, interface signatures, acceptance tests) and a writable zone (implementations). Write the failing acceptance test first, then lock those directories by hash, and only then let the agent change implementation code. An agent that tries to edit the test to make it pass gets its commit rejected.
Replace scattered mocks with one set of in-memory fakes that count reads and writes. Instead of timing tests, assert I/O counts, for example that rendering 200 tickets reads storage no more than twice, which catches N+1 loops deterministically. Keep real save files from every past version and make CI migrate all of them on every commit.
Layers 4 and 5: separate the loops, and be ready to rewrite
After every three feature tickets, run clone detection and a co-change analysis of recent history, then generate a fourth ticket that only refactors. It isn't allowed to touch tests and it has to make the code measurably smaller. Large mechanical changes go through codemods rather than file-by-file agent edits. Every merge goes through a merge queue that rebuilds and retests against the latest main, because the dangerous conflicts are semantic ones Git never sees, like one branch switching a function to millicents while another still expects cents.
Then comes the line the essay is built around: "契约是钻石,实现代码是厕纸", roughly "contracts are diamonds; implementation code is toilet paper." Regenerating a small module from scratch is now cheaper and safer than getting a model to understand code that has been patched ten times. So keep implementations small, lock their contracts and acceptance tests, and when a module keeps producing regressions, delete the implementation and regenerate it. A neat corollary: each rewrite gets the newest model, instead of making this year's model work around last year's code.
Bricklayer or legislator
The author places all this in a familiar pattern. Compilers, garbage collection and declarative infrastructure each took something people used to manage by discipline and turned it into a constraint enforced by tools. Agents call for the same move again. You either hand-check everything they write, which doesn't scale, or you become what the author calls a "system legislator": you design the types, structure, gates and tests, and treat each agent mistake as a reason to add another rule. The essay ends with a sensible caveat. All of this happens before merge, so you still need observability, gradual rollouts, feature flags and fast rollback, because more code shipped faster means more things going wrong in production.
My take
The cheapest idea here is the one I'm adopting first. I have rules in CLAUDE.md files that agents quietly ignore, and those same rules would do more inside a lint check that prints the fix. Locking acceptance tests by hash comes second. I've seen an agent "fix" a failing test by editing the test, and a pre-commit hook would have stopped it in an afternoon's work.
I'm more cautious about the specific numbers, like the 300-line module cap, the 15% shrink target and the 95% self-repair rate. They read as the author's own experience, and I'd treat them as starting points. Regeneration also only works if your acceptance tests really capture the behaviour you care about, and writing those well is hard. If this approach takes off, that's where the expensive human effort will go.
The central argument matches what I see in my own repos, though. The agents aren't the bottleneck any more. What I'm short of is checks that run without me.
Original by 海拉鲁编程客 (@hylarucoder), published 31 October 2026: x.com/hylarucoder/status/2116377073849950439. Summarised in English with commentary by Tony Ye.