Torna agli articoli

Reviewing AI-Generated Code: A Process That Scales

8 min di lettura
AI
Code Review
Agents
Engineering Strategy
Software Quality
CI/CD

Agents write most of the diff now. Here is a review process that scales: provenance tags, diff budgets, risk tiers, and the checks humans must still own.

Condividi:LinkedInX

When Agents Write the Diff, Review Becomes the Bottleneck

A pull request lands at 11:47pm. 1,900 lines across 34 files. The description reads "implement billing retry logic per spec." CI is green. A reviewer opens it the next morning, scrolls for four minutes, approves.

Nobody on that team wrote those 1,900 lines. Nobody read them either.

This is the most common pattern we see in codebases that adopted coding agents in the last eighteen months. Generation throughput went up five to ten times. Review throughput went up by exactly zero, because review is still a human reading code at human speed. The constraint did not disappear. It moved one step downstream, where it is harder to see and much more expensive when it breaks.

Writing code got cheap. Reading it did not.

Code review has always rested on an implicit contract: the author understood the change, and the reviewer checks that understanding against the rest of the system. Two mental models, one diff.

Agent-authored code breaks that contract on the author's side. The person who opened the PR did not build a model of the change. They wrote a prompt, watched tests go green, and shipped. If you ask them why the retry uses exponential backoff with jitter capped at 30 seconds, they have to go read the code, same as you. The review now has one model where it used to have two, and that model is being built under time pressure by someone who did not choose any of the decisions in front of them.

That is the whole problem. Everything below is a way to put the second model back, or to make the absence of it safe.

Three ways AI-generated PRs fail review

From the PRs we have audited on client codebases, the failures cluster hard:

  1. The plausible abstraction. The agent writes a clean, well-named RetryPolicy class. It is genuinely good code. It also duplicates BackoffStrategy, which already exists two modules over and is used by four services. Tests pass, lint passes, the reviewer has no reason to object. Six months later you have two retry systems with different jitter semantics and an incident that only reproduces on one code path.
  2. Silent scope creep. Asked to fix a null check, the agent reformats the file, renames three variables for clarity, and bumps a dependency because the type signature annoyed it. Forty lines that matter sit inside six hundred lines that do not. Review attention is a fixed budget, and noise spends it.
  3. Test theater. The same agent wrote the implementation and the tests. The tests assert what the implementation does, mock the one boundary where real failures happen, and raise coverage by nine points. Coverage goes up, confidence stays flat, and now you have a number that actively lies to you.

A fourth one is rarer but worse: dependency smuggling. An agent pulls in a package to solve a problem your standard library already solves, and that package is now in your supply chain, your SBOM, and your next security questionnaire.

None of these are caught by "looks good to me." All of them are caught by process.

Tier the review instead of reviewing everything the same way

The instinct after the first bad agent PR is to mandate line-by-line human review on everything. That lasts about three weeks before the backlog forces people to rubber-stamp, and rubber-stamping is worse than no review because it creates a false record.

Spend review attention where blast radius lives. We implement this as four tiers, enforced by path-based rules in CI rather than by discipline:

TierWhat lands hereDiff capRequired gates
0 CosmeticFormatting, docs, test fixtures, generated clientsnoneAutomated checks only; agent may merge on green
1 ContainedFeature behind a flag, internal tooling, new isolated module400 linesOne human reviewer, mutation tests on changed lines
2 SharedShared libraries, schema migrations, public API surface200 linesNamed code owner reviews line by line, migration dry run
3 Blast radiusMoney movement, PII, authn/authz, IAM and infra, deletion paths150 linesTwo humans, one outside the generating team, critical path hand-written

Tier 3 is the one people argue about. Our position: an agent can draft the code, but a human types the final version of anything that moves money, grants permission, or deletes data. Not because the agent is worse at it, but because you want a person who can testify under oath that they understood the authorization check.

Diff budgets are the highest-leverage rule you can ship this week

Every code review study from the last twenty years says the same thing: defect detection rate falls off a cliff past a few hundred lines. Reviewers do not get worse at reading. They run out of attention, and then they start pattern-matching instead of verifying.

Agents make long diffs for free. So cap them.

Put the budget in two places. First in CI, as a hard fail on changed lines by tier. Second in the agent harness system prompt, so the agent plans around it instead of discovering it at submit time. The second placement matters more than the first. An agent told "you have 200 lines" decomposes the work into three PRs on its own. An agent told nothing produces 1,900 lines and then gets rejected, which burns a full generation cycle.

Pair the budget with one more rule: no PR mixes a rename with a behavior change. Refactors go in their own PR, reviewed as a diff of structure. Behavior changes go in theirs, reviewed as a diff of logic. This single rule removes most of the noise that makes agent PRs unreadable, and it is trivially enforceable by asking the agent to split.

Make provenance a field, not folklore

Six months from now, during an incident at 3am, someone will ask whether a human ever read the function that just paged you. Right now, on most teams, there is no way to answer that.

Fix it with commit trailers. We use three:

  • Generated-By: <agent>@<model-version>
  • Prompt-Ref: <link to the task or transcript>
  • Human-Verified: <paths a person actually read>

This costs nothing and buys you two things. During incidents, it narrows the search. Over quarters, it lets you compute escape rate by authorship: defects per thousand lines, human-written versus agent-written versus agent-written-and-human-verified. That third bucket is the one that tells you whether your review process is doing anything at all. If verified and unverified agent code have the same escape rate, your reviews are decorative and you should stop paying for them.

Split the checklist: machine first, human last

Human attention is the scarce resource. Never spend it on something a tool can decide.

Machine decidesHuman decides
Formatting, lint, types, buildIs this even the right problem to solve
Unit and integration tests passDoes this abstraction already exist in the repo
Mutation score on changed linesWhat happens on the failure path, not the happy path
Dependency diff and license checkBlast radius if this is wrong in production
Secret and credential scanningIs the test asserting behavior or asserting the implementation
Duplicate-code and dead-code detectionDoes this match how the team will maintain it in a year
Diff budget and tier classificationIs the error message useful to the person who gets paged

The right-hand column is five questions, not fifty. A reviewer who answers those five on a 200-line diff does more for your reliability than a reviewer who skims 1,900 lines looking for typos.

Mutation testing is the cheapest cure for test theater

The fastest way to find out whether agent-written tests are real: mutate the changed lines and see if the tests notice. Flip a boolean, change a comparison operator, delete a return. If the suite stays green, the test asserts nothing.

Full-repo mutation testing is too slow to be practical. Mutation testing scoped to the diff runs in the time it takes to get coffee, and it turns "coverage went up" into a claim you can verify. We gate tier 1 and above on it. It has caught more useless tests than any human reviewer on any project we have run.

The five numbers worth tracking

  1. Review latency, p50 and p90, from PR open to first substantive comment.
  2. Changed lines per approving review, trended weekly. If this climbs, your review is degrading no matter what people say in retro.
  3. Escape rate by authorship, using the provenance trailers.
  4. Revert rate within seven days of merge.
  5. Count of duplicate abstractions flagged by your similarity detector, per month.

If diff volume tripled and these five numbers stayed flat, your process absorbed the change. If diff volume tripled and latency doubled while lines-per-review climbed, you are not shipping faster. You are accumulating unreviewed code and calling it velocity.

If your team is somewhere in that second scenario and you would rather fix it before the incident than after, that is work we do: agent harnesses with budgets built in, tiered gates wired into CI, provenance you can query. Talk to us.

What to do Monday morning

  1. Pull the last 50 merged PRs. Compute median changed lines and median time from open to approval. You now have a baseline, and it will probably be uncomfortable.
  2. Add a CI check that fails any PR over 400 changed lines unless it carries an explicit override label. Ship it as a warning for one week, then make it a hard fail.
  3. Put the same line budget into your coding agent's system prompt, plus the rule that refactors and behavior changes never share a PR.
  4. Add the three commit trailers and make Human-Verified required on any path under your auth, billing, or data-deletion directories.
  5. Turn on diff-scoped mutation testing for one service. Look at the first report with the team. The conversation that follows is the actual deliverable.

None of this slows your agents down. It stops you from mistaking generated lines for shipped value, which is the only metric that was ever real.

Condividi:LinkedInX