Code review when AI writes most of the code: goals, small PRs and labelled comments
What review is for when PRs arrive faster than people can read them: splitting the work between CI, AI and human reviewers, PR size (and a figure that's often misattributed), a Java/Spring checklist, peer and group review, labelled TODO/NIT/OPTIONAL/FYI comments.
On this page
1. The problem
A five-person team turns on coding agents: weekly PRs go from 20 to 55, averaging 900 lines, with 2 days to first review. A 1,500-line PR gets approved after two minutes; a 40-line PR gets 30 comments about naming.
2. Key idea
A reviewer's reading capacity is fixed; the amount of code isn't. Review breaks when people read what machines could, or read too much at once. Finding every bug is the job of tests and CI.
| Failure mode | Sign | Fix |
|---|---|---|
| Rubber stamp | 1,500-line PR approved in 2 minutes | split PRs, set a response-time target |
| Battlefield | 30 comments about naming | move rules to CI, taste is a NIT |
| Bottleneck | 2-day waits, one senior reviews everything | CODEOWNERS, measure time to first review |
2.1 Which layer checks what?
| Approach | Use when | Don't use when |
|---|---|---|
| Peer review before merge | the default; anything touching money, security, schema | docs, small config with fast rollback |
| AI first pass | diff summaries, common bugs, missing tests | replacing a human signature in high-risk areas |
| Blocking CI checks | fast, reliable checks: build, tests, format, secrets | slow, flaky checks, or ones needing judgment |
Comment labels: TODO (bug or risk, blocks merge), NIT (small detail), OPTIONAL (suggestion), FYI (for information), plus QUESTION and PRAISE. Every TODO states the consequence and a fix.
3. In Java
Rules reviewers keep repeating become ArchUnit tests, so nobody has to repeat them:
@AnalyzeClasses(packages = "com.example.booking")
class ArchitectureTest {
@ArchTest
static final ArchRule servicesUseFinalFields = fields()
.that().areDeclaredInClassesThat().areAnnotatedWith(Service.class)
.and().areNotStatic()
.should().beFinal()
.because("@RequiredArgsConstructor only injects final fields");
@ArchTest
static final ArchRule controllersDoNotTouchRepositories = noClasses()
.that().areAnnotatedWith(RestController.class)
.should().dependOnClassesThat().areAssignableTo(Repository.class);
}Other languages: dependency-cruiser for TypeScript, import-linter for Python.
How to split a big PR
- Separate refactors from features: a package-rename PR has only imports, and reviewers check "CI green, diff is only imports".
- Stacked PRs: a chain of PRs, each under ~300 meaningful changed lines.
- Feature flags: merge new code switched off, turn it on later.
- Expand/contract for migrations: add the table or column first; nobody uses it yet, so it deploys safely.
- Reading order for a PR: description, tests, design files, then details; also open callers,
switches and DTOs that should have changed.
4. Working with AI
Hand to AI: summarizing the diff by risk area, drafting the PR description, proposing how to split a big PR, suggesting missing tests.
Check yourself when an AI joins the review:
- Bot comments carry labels too; no bot comment blocks a merge without a human confirming it.
- An AI-drafted PR description matches the diff: every file it mentions is in the diff and vice versa.
- "No behavior change" comes with evidence: characterization tests written first, not just "tests still green".
- PRs over ~400 meaningful changed lines were asked to split, even when an agent wrote them.
5. Exercises
Exercise 1: Review an AI-written endpoint
An agent opens a PR "Add an API to search orders by status, tested manually". Write labelled comments, each TODO with a consequence and a fix.
private static final SimpleDateFormat FMT = new SimpleDateFormat("yyyy-MM-dd");
@GetMapping("/orders")
public List<OrderDto> search(@RequestParam String status, @RequestParam String from) {
try {
String sql = "SELECT * FROM orders WHERE status = '" + status + "' AND created_at >= '" + from + "'";
List<Order> orders = jdbc.query(sql, new BeanPropertyRowMapper<>(Order.class));
List<OrderDto> result = new ArrayList<>();
for (Order o : orders)
result.add(new OrderDto(o.getId(), FMT.format(o.getCreatedAt()), items.findByOrderId(o.getId())));
return result;
} catch (Exception e) {
return List.of();
}
}Solution 1
- TODO: concatenating into SQL is SQL injection (
status=' OR '1'='1). Use?parameters, and parsefrominto aLocalDateso bad input gets a 400. - TODO:
catch (Exception e) { return List.of(); }turns every failure (DB down, bugs) into "no orders". Drop the catch and let the global handler return 500 and log. - TODO: a shared
staticSimpleDateFormatisn't thread-safe: wrong dates under load. UseDateTimeFormatter. - TODO:
findByOrderIdin a loop is N+1: 500 orders means 501 queries. Fetch items with oneWHERE order_id IN (...). - TODO: no pagination,
SELECT *: a common status returns hundreds of thousands of rows. - QUESTION: is there a list of valid
statusvalues? If so, use an enum.
"Tested manually" with a few real statuses exposes none of these: review reads failure and load behavior, not just the happy path.
Exercise 2: Read the team's review metrics
After three months with agents: median time to first review 31 hours; median PR 870 lines; 58% of PRs over 500 lines approved in under 5 minutes; 40% of comments about formatting and naming; one senior reviews 70% of PRs. Diagnose it and name three things to do this week.
Solution 2
All three failure modes from section 2.
- Turn on blocking formatter and linter checks in CI, and treat taste as
NIT: most of that 40% disappears. CODEOWNERSby directory; the senior is required only in high-risk areas.- A size convention (warn above 400 meaningful changed lines) for people and agents alike, written into
AGENTS.md; target first review within one working day.
A 5-minute approval of a 500-line PR is a signal, not a crime: ask the reviewer what they relied on.
Summary
- Review protects quality and helps people learn; it doesn't replace tests.
- CI for hard rules, AI for the first pass, humans for design, behavior and risk.
- Only small PRs get really read; split with separate refactors, stacked PRs, feature flags.
- Every comment has a label; only
TODOblocks, with a consequence and a fix. - A rule repeated twice becomes a machine check.
Further reading: Reviewing AI-written code.
Practice interview questions on this topic
- What is code review for, and how do you prepare a PR before asking for review?
- When reviewing a backend PR, what do you look at beyond whether the code works?
- How do you keep code review from becoming a bottleneck or a fight about formatting?
- An agent opens a 1,400-line PR with every test green: how do you review it?
Comments
Community rules