Chapter 9: Quality in the Age of Generation
AgentSpek - A Beginner's Companion to the AI Frontier
The AI-generated code sailed through review and passed every test, then failed in production when two processes collided. Holding a quality bar when code arrives faster than you can read it.
Dijkstra said that program testing can show the presence of bugs, but never their absence. Now the bugs come from an intelligence that makes different kinds of mistakes than we do, and his line cuts deeper.
When It Looked Perfect
There is a particular dread that comes with a production failure in the small hours. Obvious bugs bring panic. This is slower, the dawning horror that something you trusted completely has been quietly failing for days.
The code was AI-generated and beautifully elegant. It had sailed through review. The test suite, also AI-generated, showed green across the board. Static analysis found no issues. I reviewed it carefully, understood the logic, approved the merge.
It had a bug that only showed when two things happened at once. Two processes arriving at the same resource within microseconds of each other, both wanting exclusive access, each waiting for the other. Either one alone was correct. Together, deadlock.
The tests ran serially, so they never caught it. I was reading the logic in isolation, not imagining the chaotic timing of production, so my review never caught it either. The AI never considered it, because the pattern it had learned did not emphasize this interaction in this context.
The code was incomplete rather than wrong, and the gap was between what I thought I had specified and what the AI understood me to mean. Code can be technically perfect and still fail in ways you never imagined.
The Quality Paradox
How do you review code that thinks differently than you do, or test algorithms built on patterns your brain does not naturally follow? And how do you maintain code made with an AI when the failure modes do not match your intuitions?
AI can generate code that looks flawless. Our quality assurance was designed around the ways humans fail.
New Failure Modes
Traditional testing was built around how people fail. We test edge cases because we forget them, error conditions because we do not always handle the exception, performance because we do not always optimize.
The AI fails differently. The most insidious is pattern matching gone wrong. The AI recognizes a pattern from its training and applies it perfectly, and the context makes it the wrong pattern. I have seen Sonnet 4 generate a flawless implementation of OAuth, the standard that lets you sign into one app with an account from another, that still exposed sensitive tokens in logs. Nothing in the code itself was wrong, the pattern it matched just did not emphasize that security concern in that context.
Context window blindness is a different kind. The AI can hold enormous amounts of information and still lose track of a constraint from thousands of tokens earlier. A requirement stated at the start of a conversation is gone by the end, or a pattern set in one file is broken in another.
The subtle semantic errors are the ones that trouble me. Syntactically perfect code that misunderstands the business logic, a payment function that gets the transaction pattern right and the currency precision wrong, an authentication system that works and does not know about your particular user lifecycle.
Then there is over-generalizing from examples. You give it three examples and it extrapolates a pattern you never intended. Three poodles and it concludes all dogs have curly hair.
You’ve read the opening sections of this chapter. The full chapter (Testing What Was Never Written, The Review That Matters, Maintaining What You Did Not Write, Quality Through Dialogue, What “Good” Means Now, Semantic Standards, Trust, The Evolution) continues in the book.
Chapter 9 of 18 in Chapter 9: Quality in the Age of Generation