Skip to main content
Antinode Labs

Who's Watching Your AI Agent Erode the Architecture?

QA proves the code does what it should. Fitness functions prove the system is still the system you designed. In an agent-driven codebase, that's the difference between shipping and eroding.

On this page

Open your CI configuration right now.

Count the gates that check architecture. Not tests. Not lint. Not coverage thresholds. Gates that would fail the build if someone violated a module boundary, exceeded a complexity ceiling, changed a public contract without review, regressed a performance budget, or weakened the test suite.

Most people reading this just found zero. A few found one.

I once asked a room of about forty architects and senior engineers the same question. Three hands went up. The other thirty-seven worked at companies with test suites, coverage dashboards, lint rules, and security scanners. They were not careless. They had simply never been asked the question — because on their teams, the question had no owner.

That gap — between "our tests pass" and "our architecture is intact" — is where I have watched more systems rot than anywhere else. And it is the gap that agents widen fastest, because every green test makes the erosion quieter.


Two Different Questions #

QA and fitness functions are not two versions of the same thing. They answer different questions, and confusing them is why the gap stays open.

QA testing Fitness function
Question Does this behaviour match the spec? Does the system still have the property we require?
Scope A feature, a function, a flow The codebase, the pipeline, the deployed system
Time Pass/fail at a point in time Guards a property continuously
Owner QA, developers Architects, platform — in theory
Catches Bugs Architectural erosion
Form Unit, integration, E2E, exploratory Dependency rules, complexity ceilings, latency budgets, mutation score, API diffs

A suite can be 94% covered and 100% green while the codebase quietly becomes a ball of mud. Both statements are true simultaneously, and this surprises people — which is the problem. It was never QA's job to check architecture. It was never anyone's.

Ford and Parsons gave the concept its name in Building Evolutionary Architectures. Their definition is precise and worth holding onto: a fitness function is an objective, automated test of how close a particular architectural characteristic is to its target, run continuously as part of the delivery pipeline. The name matters less than the category. A fitness function is an executable architecture axiom — the invariant from Post 2, made mechanical.

Three reasons QA structurally cannot cover this. Some properties are not behaviours at all: "domain must not import infrastructure" is checked by static analysis, not by executing a scenario. QA tests instances; fitness functions test the class of all instances. And QA runs at merge, while drift accumulates between merges, across pull requests nobody reviewed holistically. A test verifies one path. A fitness function is a tripwire on the shape of everything.

Name the architectural property you would notice being violated today. If you can't name one, you don't have a tripwire. You have a post-mortem waiting to happen.


Why Nobody Builds Them #

If fitness functions are so valuable, why were thirty-seven hands down?

Not because they're hard. Most are five to fifty lines of CI configuration. Not because they're expensive. Not because teams don't care about architecture — the room was full of architects.

Because they fall between three org charts.

THE OWNERSHIP VACUUM

   ARCHITECTS                 QA                      PLATFORM
   ──────────                 ──                      ────────
   write ADRs                 own behaviour           own the pipeline
   draw diagrams              write tests             tune CI
   review designs             chase coverage          manage runners
   think about structure      think about scenarios   think about throughput

        │                        │                        │
        └────────────────────────┼────────────────────────┘
                                 ▼
                    ┌────────────────────────┐
                    │                        │
                    │   "is the system       │
                    │    still the system    │
                    │    we designed?"       │
                    │                        │
                    │      NOBODY            │
                    │                        │
                    └────────────────────────┘

Each group is doing its job correctly. Architects produce design artifacts, not CI configs. QA owns behaviour and has never been asked to own structure. Platform owns the pipeline and treats architecture as someone else's domain.

The property that spans all three belongs to none of them. And a property with no owner does not get measured — not because anyone decided against it, but because nobody was ever in the room where the decision would have been made.

Here is the part worth sitting with. The reason this gap survives isn't that nobody noticed it. It's that everybody noticed it and assumed someone else had already raised it. It is the most common form of organizational blindness: a problem so visible that it becomes invisible, because visibility is mistaken for ownership.

So if you read the opening of this post and thought "yes, that's exactly our problem" — you're the someone else. You are the person who noticed. Which means, as of now, you're the person who owns it.

This is why the gap persists across otherwise excellent teams. It's not a knowledge gap. Every architect in that room could have written the dependency rule in ten minutes. It's an ownership gap, and it reproduces itself on every team that doesn't deliberately close it.

For agent-driven codebases, a slow leak becomes a structural failure. Agents are locally optimising author machines. They will satisfy the tests, ship the feature, and deepen the coupling — because deepening coupling is often the cheapest local path. The tactical tornado isn't a metaphor. It's the default behaviour of a local optimiser with no global constraint.

And the tests will be green the whole way down.


The Five That Pay for Themselves #

Start here. Each one is small, each one is blocking, and each one catches a class of erosion that no behavioural test will ever see.

1. Dependency-direction rules #

Layers that may not import each other, modules with declared boundaries. This is the Post 4 boundary guardrail, now run as a fitness function on every commit.

// ArchUnit
noClasses()
  .that().resideInAPackage("..domain..")
  .should().dependOnClassesThat()
  .resideInAPackage("..infra..");

Catches the agent's most common architectural sin: importing whatever is convenient in the moment.

2. Complexity ceilings on changed files #

Cyclomatic or cognitive complexity above a threshold fails the build for the files you touched. Not the whole codebase — that's a rewriting project. Just the diff. This is how you stop the slow accretion of god functions without halting the team.

// run only against changed files
if complexity(file) > 15 for file in diff:
    fail("complexity ceiling exceeded — decompose before merging")

3. API contract diffs #

No change to a public schema without a visible diff and a review.

if openapi_schema_diff(old, new) is not empty:
    require_review("api-contract-owners")
    attach_diff_to_pr()

This is the fitness function that would have caught the settlement export. The field was added correctly, the shape changed silently, and the consumer two repos away found out in production. A contract diff turns three days in Europe into a comment on a pull request.

4. Performance budgets #

p95 latency on defined endpoints, under a defined load, measured on every merge to main.

budget: p95(latency) < 300ms @ 500rps for /checkout
gate:   fail if p95 regresses > 10% vs rolling 7-day baseline

Catches the slow path no functional test would ever fail, and the query that got added without anyone noticing it was quadratic.

5. Mutation score on touched code #

Kill the mutants in the diff, not the whole repository.

mutation_score(changed_files) >= 70%  →  pass
mutation_score(changed_files) <  70%  →  fail with surviving mutants listed

This is the closest thing to an automated test-quality metric, and it catches exactly what agents are prone to: tests that execute the code without challenging it. If the mutation score on your changed files is 40%, the agent wrote assertions that pass by construction.

Five gates. Perhaps an afternoon of setup each. Together they close the widest gap in the verification stack.


The Verification Stack #

Fitness functions are one layer of four. Each layer catches what the one below it cannot.

THE VERIFICATION STACK

  ┌───────────────────────────────────────────────────────────┐
  │  HUMAN REVIEW                                             │
  │  judgment · usefulness · trust · "should this exist?"     │
  │  resists formalisation — permanently                      │
  ├───────────────────────────────────────────────────────────┤
  │  OBSERVABILITY                                            │
  │  runtime: latency · error rate · saturation · drift       │
  │  catches what only exists under real traffic              │
  ├───────────────────────────────────────────────────────────┤
  │  FITNESS FUNCTIONS                                        │
  │  architecture: boundaries · complexity · contracts ·      │
  │  budgets · mutation score                                 │
  │  catches erosion while every test stays green             │
  ├───────────────────────────────────────────────────────────┤
  │  QA TESTS                                                 │
  │  behaviour: does this do what the spec says?              │
  │  cheapest failure to catch — and the most obvious         │
  └───────────────────────────────────────────────────────────┘

QA at the base, because a behaviour bug is the cheapest failure to catch and the most visible. Fitness functions above it, because a green suite can hide a rotting structure. Observability above that, because some properties only exist at runtime, under real traffic, with real data. And human review at the top, because some properties — is this useful, is this trustworthy, is this the right thing to build — resist formalisation and always will.

The point is not that any layer is better. It's that each one fails differently, and a system with only the bottom layer is blind in three directions at once.


Three Ways This Fails #

I want to be honest about the costs, because "add fitness functions" is not free and the failure modes are real.

They can be false-positive machines. A dependency rule that's slightly too strict blocks a legitimate refactor and teaches the team to bypass it. A performance budget tuned on a noisy CI runner fails randomly and gets muted. A muted gate is worse than no gate, because it looks like protection.

The mitigation is the same as Post 4's: keep the gates few, keep them blocking, and tune them until they're right — rather than adding twenty and disabling fifteen.

They can be gamed. An agent told to keep complexity under 15 will split a function into two functions that call each other. An agent told to raise mutation score will add assertions that kill mutants without testing behaviour. This is the reward-hacking failure from Post 1, applied to architecture. Fitness functions are not immune to it.

The mitigation is human review of why a gate is passing, not just whether it is. The gates catch drift; they don't replace judgment.

They need an owner. This is the real cost, and it's the one that determines whether they survive — which is the whole thesis of this post, arriving as its own failure mode. A fitness function with no named owner will be disabled during the first urgent release and never re-enabled. If you build these, assign them. A name in a CODEOWNERS file, a review cadence, a rule that disabling a gate requires a PR that changes the config visibly.

None of this argues against building them. It argues for building five that work rather than fifty that get muted. The gate you trust is worth more than the twenty you've learned to ignore.


The Property That's Already Degrading #

The property of your system that is currently degrading has no test on it — because if it did, it wouldn't be degrading. For Knight Capital it was "all eight servers are running the same version." For the settlement export it was "the row is a tuple and downstream parses by position."

You will find out what yours is from production. The only question is whether you find out from an alert or from a Slack message that makes your stomach drop.

Fitness functions are how you find out early — not because they're clever, but because they're the only thing watching the shape of the system while every test stays green.


The Five-Minute Audit #

Here's the test, and it's the last one in this series. It takes five minutes and you can do it before you close this tab.

Open your CI configuration. Count the gates that check architecture.

Not tests. Not lint. Not coverage thresholds. Gates that would fail the build if someone violated a boundary, exceeded a complexity ceiling, changed a public contract without review, regressed a performance budget, or weakened the test suite.

Count them.

If the number is zero, you have a QA pipeline. You do not have a quality pipeline. Every agent commit is passing through a gate that checks whether the code does what it says, and no gate at all that checks whether the system is still the system you designed.

If the number is one or two, you're ahead of most teams and you're still missing three directions of blindness.

If the number is five or more, you already know why you built them, and you've probably watched one of them catch something nobody else would have.

Whatever the number is, the fix is the same: build one this week. The dependency rule is the cheapest. It's six lines. It will catch something within a month, and when it does, you'll have the argument you need for the other four.

The property that's degrading right now doesn't need a better model. It needs someone watching. You already noticed. That makes it yours.


The Series, in One Paragraph #

Five posts ago, I asked whether your agent's environment was the problem.

The answer: your agent is a tactical engine, and quality is a strategic property of the system around it. You don't fix that with a better prompt — you fix it with fewer, truer laws it can satisfy, a contract it can be held to, guardrails it cannot silently violate, and tripwires that catch what tests miss. The spec is the contract. The guardrails are the enforcement. The fitness functions are the tripwire. And the loop — spec to production to spec — is the quality.

The agent will keep getting better. The system around it has to get better faster.


This is the last post in the series. If you've read all five, you have the full argument: laws, contract, machine, tripwire. The work is now yours to do — and it starts with one gate, in one repository, this week.

Comments

Loading comments...

Your email will be used for comment notifications