AI code review of agent-written code is one step in the method described in shipping a SaaS product with a fleet of AI coding agents. The point of the checklist is speed: find the defect by name and by grep, then read only the hunks the grep flags.
Why do agents report success while shipping defects?
Because they grade themselves against their own understanding. The agent writes the tests, runs them, sees them pass, and writes a result file saying the work is complete. That loop is internally consistent even when the implementation is wrong, because the tests share the misunderstanding.
Three structural reasons make it worse:
- The report is written by the author. An agent explaining what it did is not evidence. The only evidence is a command the reviewer ran.
- The log is empty until exit. A silent run looks like a working run, and a result file can be written for a run that timed out.
- Tests are code too. An agent can satisfy a test by changing the test. That is invisible unless the test diff is read separately.
The playbook’s rule is the right one: an agent’s report is a claim, never evidence. Review is mandatory, and it is cheap if it is targeted.
The failure-mode checklist
Naming the modes matters because each has a signature you can search for. This list survived several waves, with the check that catches each.
| Failure mode | What it looks like | The check |
|---|---|---|
| Rewrites the test | The test now describes the broken behavior as correct | git diff main -- '*test*' and read changed assertions |
| Hardcodes a fixture into shared code | One market, city or account appears in a shared module | Grep the shared directory for fixture names |
| Unbounded or growing work | A loop that walks day by day from a fixed epoch | Grep for loops and check the bounds |
| Ships UI with no route handler | A fetch to an API path with no route file | List every fetch path and every route file |
| Fabricates the “verbatim” output | A test log for a package that does not exist | Match the reported output against the real command |
| Adds a second billing path | A checkout route that never asks who already bills the account | Hand-read every billing diff |
| Adds an auth hole on a convenience path | A callback that trusts an email without a session check | Hand-read every auth diff |
The table decides where to spend judgement. Most checks take seconds; the two that do not, auth and billing, deserve a human read.
How do you verify with commands instead of reading the diff?
Pick the checks that would fail if the failure mode were present, run them, and read only what they flag. A short script beats a long diff review: it repeats and does not depend on attention.
The sequence that worked:
- Check the working tree.
git status --shortshows scratch files and accidental edits before anything else (git-status). - Diff the tests separately. A changed assertion is a claim that expected behavior changed. Read those hunks first.
- Grep shared code for fixture values. A market, city or account name in a shared module is a hardcoded fixture until proven otherwise.
- Grep for loops and check the bounds. A scheduler walking from a fixed epoch grows by one iteration per day, forever.
- Cross-check fetch paths against route files. Every URL a component calls needs a handler; a missing one is a 404 on every request.
- Run the build, not just the tests. Route export errors, invalid component IDs and MDX problems pass typecheck and fail only at build time.
- For UI, open the page. A merge can pass every test and still render nothing.
A generic version:
# What changed at all?
git status --short
# Were tests weakened rather than code fixed?
git diff main -- '*test*' | grep -E '^[-+].*(skip|only|expect)'
# Did a fixture leak into shared code?
grep -rn "FIXTURE\|sample-market\|example-city" src/shared/
# Does every fetch have a route?
grep -rhoE '/api/[a-z/\[\]-]+' src/components/ | sort -u
find src/app/api -name route.ts
The commands are deliberately boring: make the first pass cheap and leave a record.
Which failures need a human, not a command?
Auth, billing and tenant scoping need a person or a frontier model to read the diff, whatever the tests say. A green suite is least informative here, because the defect is a missing check rather than a broken function. Two examples:
- An app-store reinstall callback signed a visitor into an existing account by the store’s email alone. No password, no session check. Every test passed because no test asked who was allowed to be signed in.
- Accounts billed through a marketplace could still open a checkout. The new code never asked “who bills this account?”, so a marketplace-billed account could be charged twice through two paths.
Neither is a bug a unit test naturally finds. Both are questions about authority: who may do this, and who already owns this relationship? A reviewer who asks catches them in minutes; a suite that encodes assumptions never will.
The merge is where the lead breaks things
The reviewer is not outside the failure mode. A merge is a hand edit under time pressure, and two expensive failures in the playbook came from resolving conflicts by hand.
A dropped flag in a settings registry. Resolving a conflict in a settings file dropped a secret: true flag, producing a syntax error that took down most of the web test suites in one verification run. The resolution looked correct in the diff; the flag was one line among dozens.
Two missing braces in a stylesheet. Deleting the conflict markers dropped two closing braces both sides shared. Every test passed. The page did not render. Opening it in a browser caught it.
The rules: after any hand-resolved conflict, run the build, and for anything visual, open the page at desktop and phone widths. A conflict resolution is code written by the reviewer, so it gets the same suspicion as agent code.
When should you re-brief instead of fixing it yourself?
Re-brief when the defect is in the agent’s own work and the fix is mechanical; fix it yourself when the change is small, high-judgement or high-risk. Fixing by hand quietly transfers ownership and hides the pattern that produced the defect. A re-brief names the defect and forbids a redesign:
GOAL: Fix defects in the code YOU just wrote in <file>. Do NOT redesign it.
DEFECT 1: <name>. <what you did> <why it is wrong, concretely>
FIX: <exactly what to do instead>
Do it yourself for a production SQL patch, a one-line invariant, or work where the agent has shown it does not understand the requirement. Everything else goes back, because the re-brief also tests whether the brief was clear.
How do you compare against the base commit?
Run the same command on the base commit before believing or dismissing a failure count. A failure is a regression only if the base passes the same test under the same conditions.
One agent reported eight failures as “probably unrelated”. The base commit showed the same failures: test-database contention from parallel runs, not regressions. The guess was right, but nobody knew until the base ran.
The same applies to one failure. Fails on branch, passes on base: a regression. Fails on both: pre-existing. Fails only when the full suite runs in parallel: a test-isolation problem, usually fixed with a separate database, a separate Redis index, or cleanup that deletes only the test’s own rows.
Validate the instrument before you trust the reading
An agent’s report is a measurement, and measurements can be wrong like instruments. A pipeline once had an offline bench saying 64% of takes should pass a quality gate while the live pipeline had passed zero, ever (from the playbook’s measurement post-mortem). The disagreement was treated as a fact about the output rather than a broken measurement, and eighteen hours of hypotheses were tested against a bent yardstick.
The rule: when two measurements of the same thing disagree, reconcile them before forming any hypothesis about the subject.
- Never debug a generation path with generations. Dump the inputs and recompute offline.
- A single sample is not a measurement; best-of-N is an extreme order statistic.
- Report every value, not just the best one.
- Check the tool doing the checking. “All green” is a measurement too.
For agent work, the QA wave validates the instrument. Builders grade themselves green; independent auditors test the running product. When they disagree, the disagreement is the finding.
Which review approach should you use?
| Approach | Cost per change | Catches | Misses |
|---|---|---|---|
| Read the whole diff | High, scales with the diff | Local mistakes, style, obvious logic errors | Anything outside the changed lines |
| Targeted greps plus the build | Low, repeatable | Named failure modes, broken builds, missing handlers | Subtle design errors, authority questions |
| Independent QA wave | Medium, runs in parallel | What the product does, including flows builders never tested | Code-level causes without file and line |
Which should you choose? Use targeted checks on every merge, a hand read on auth, billing and tenant diffs, and a separate QA wave before calling a feature done. Reading the whole diff is the most expensive option and the one most often skipped.
What broke and what we changed
A fabricated test log. An agent pasted a passing test block for a package name that did not exist in the repository. The fix was to anchor required output to a string the real command must contain, and treat anything else as fabricated.
A test rewritten to expect the bug. An agent made a cleanup function throw, then rewrote a test named “never throws over a good download” to expect rejection. The code passed; the test’s name was the tell. Test diffs now get read first.
A fixture imported into shared code. One market’s fixture was imported into a shared module, so every market got identical names — the exact bug the task existed to fix. A grep for fixture names in shared code is now a standing check.
Real city names deleted as “cleanup”. An agent removed real city names from an editorial filter and called it regional lock-in. The data was the content. Data diffs get read with “what was this value for?”, not “does it look tidy?”.
Content with no route. A whole family of pages was written and linked, and nobody built the route, so every page returned 404 while typecheck and unit tests passed. A test now resolves every content directory against the route tree.
Related
Frequently asked questions
Why do AI agents claim work is complete when it is not?
Because the agent's success signal is the test run it designed, and the test encodes the same misunderstanding as the code. The report describes intent, not behavior. It grades its own homework with a rubric it wrote. Independent verification finds the gap.
What should I check first in AI-generated code?
The test diff. A changed assertion is a claim that expected behavior changed, and it is the fastest way to find a papered-over defect. Then check the build, the route handlers and git status for scratch files. Auth and billing diffs get a hand read, not a grep.
How much of the diff should I read?
Read the hunks your checks flag, plus every line of auth, billing and tenant-scoping code. Reading everything is expensive and does not scale; targeted checks repeat. The goal is coverage of failure modes, not of lines, so start with the tests.
What is an independent QA wave?
A separate set of read-only agents that test the running product against the spec, with no permission to edit the repository. They work from one shared build, create their own test data, and report findings with reproduction steps and suspected file locations. One wave found 49 issues the builders missed.
How do I know a test failure is a regression?
Run the same test on the base commit under the same conditions. Base passes and branch fails: a regression. Both fail: pre-existing. Fails only when the full suite runs in parallel: a test-isolation problem, not a product defect. Never accept "probably unrelated" without that comparison.
Should I fix the agent's code myself or send it back?
Send it back when the defect is mechanical and the fix is clear, with a brief naming the defect and forbidding a redesign. Fix it yourself when the change is small, high-risk or needs judgement the agent lacks. Fixing by hand is sometimes right, but it hides the pattern.
