LESSON 8

Code Review in the Age of AI

Review AI-generated and human-written changes effectively, use AI as a first-pass reviewer, and keep human judgment responsible for the final decision.

Introduction

When code is cheap to produce, review becomes the bottleneck and the main quality control. A single developer with an assistant can generate more code in a day than a colleague can review properly in the same time. If review quality drops, defects flow through.

This lesson covers what to review, how to keep reviews effective, and how to use AI as an aid without letting it replace judgment.

Learning Objectives

  • Explain the purposes of code review beyond finding bugs.
  • Apply a structured checklist to review a change.
  • Review AI-generated code with appropriate skepticism.
  • Use AI as a first-pass reviewer and understand its limits.
  • Write clear, constructive review comments and good pull request descriptions.
  • Keep review load manageable through size and automation.

1. Why We Review

Review exists to:

  • Catch defects that tests and the author missed.
  • Check design fit: does this belong here, and does it respect the architecture?
  • Spread knowledge: at least two people understand each change.
  • Maintain consistency and shared standards.
  • Share accountability: the author and reviewer both stand behind the merge.

With AI-generated code there is an additional purpose: confirming that a human understands what was generated. If the author cannot explain the change, it is not ready for review.

2. Authors Own Their Changes

Before requesting review, the author:

  1. Reads the full diff as if someone else wrote it.
  2. Runs the full quality gate and the relevant manual checks.
  3. Removes debug output, dead code, and unrelated changes.
  4. Writes a pull request description (lesson 3): what, why, how verified, risks, and significant AI-generated portions.
  5. Keeps the change small enough to review in one sitting.

Sending unread generated code to a colleague and calling it “review” shifts the work, and the risk, onto someone else. Teams should treat this as unacceptable behavior.

3. A Structured Checklist

Reviewing in a consistent order reduces misses:

Area Questions
Purpose Does the change do what the requirement and description say, and nothing more?
Correctness Are edge cases, empty or large inputs, and error paths handled?
Design Does it respect module boundaries and ADRs? Is the abstraction justified?
Security and privacy Input validation, authorization, tenant filter, secrets, logging of personal data, dependency changes
Data Migrations safe and reversible? Constraints and indexes?
Tests Do tests verify behavior and failure paths? Were any weakened or removed?
Readability Clear names, small functions, comments that explain why?
Operations Logging, metrics, configuration, failure behavior, rollout and rollback
Dependencies and licenses New packages justified, real, maintained, compatibly licensed?
Documentation README, API contract, or ADR updated if needed?

Start with the description and the tests, then the design, then the details. Understanding the intent first makes the details reviewable.

4. Reviewing AI-Generated Code

Generated code has recognizable patterns to watch for:

  • Plausible but wrong: reads fluently, handles the happy path, fails an edge case.
  • Invented APIs and packages: verify that every called function and imported library exists in your versions.
  • Weakened tests: assertions loosened or tests deleted to turn the build green.
  • Scope creep: unrequested changes, reformatting, or “improvements” in unrelated files.
  • Over-engineering: extra layers, configuration, and options nobody needs.
  • Confident comments: comments that claim behavior the code does not have.
  • Copied patterns: code that resembles public examples, which raises licensing questions and sometimes carries known vulnerabilities.
  • Silent error handling: broad exception handlers that hide failures.

A useful discipline: for each significant block, ask “What would make this fail?” If you cannot think of anything, you may not understand it yet.

An example finding. The assistant produced:

1
2
def get_feedback(item_id: int, session):
    return session.query(FeedbackItem).filter_by(id=item_id).first()

It works in every test. The review comment: “No workspace filter. Any authenticated user can read any item by guessing IDs. Please go through the workspace-scoped repository and add a cross-tenant test.” The reviewer found this because the checklist said to look for it, not because the code looked wrong.

What Reviewers Should Not Spend Time On

Automate everything a machine can check: formatting, lint rules, type errors, import rules, secret scanning, and test results. Reviewers should not discuss style that a formatter can settle. This frees attention for design, correctness, and risk.

5. AI as a First-Pass Reviewer

An assistant can read a diff quickly and flag candidates: missing checks, inconsistent naming, suspicious logic, untested branches. Use it before human review to reduce trivial findings.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Act as a careful senior reviewer.

Context:
- Project conventions: [ASSISTANT_INSTRUCTIONS.md]
- Requirement and acceptance criteria: [paste]
- Diff: [paste]

Review for: correctness against the criteria, unhandled edge cases,
tenant-isolation and authorization gaps, injection or unsafe input
handling, error handling, performance risks (loops with queries,
unbounded data), missing or weak tests, and violations of module
boundaries.

For each finding give: location, severity (high/medium/low), the
failure scenario, and a suggested fix. Separate "definite problems"
from "questions or suspicions." Do not comment on formatting.
If you find nothing in an area, say so rather than inventing issues.

Limits to keep in mind:

  • False positives and false confidence. The assistant may raise non-issues and miss real ones. A clean AI review is not an approval.
  • Limited context. It does not know the rest of the system, deployment, or history unless told.
  • Same blind spots. A model reviewing code it generated may share the same misunderstanding.
  • No accountability. It cannot approve a merge. A person does.

Use AI review to prepare, and human review to decide. Verify each AI finding before acting: some are wrong, and “fixing” a non-issue can introduce a bug.

6. Writing Good Review Comments

  • Explain the why: state the risk or the principle, not just the preference.
  • Distinguish blocking issues, suggestions, and questions. Label them (“blocking:”, “suggestion:”, “question:”).
  • Be specific: point to the line, give an example or an alternative.
  • Critique the code, not the person. The same applies when the code came from an assistant: no need for sarcasm in either case.
  • Praise good work when you see it; review is also how standards spread.
  • Resolve disagreements by talking, then record the outcome in the pull request.

As an author, respond to every comment, ask when unclear, and avoid defensiveness. A request to change is about the code.

7. Keeping Review Sustainable

  • Small changes: aim for a size that can be reviewed in under an hour. Ask the author to split larger ones.
  • Agree on turnaround: for example, first response within one working day.
  • Rotate and spread reviewers so knowledge is shared and no one becomes the permanent bottleneck.
  • Review risk-weighted: give security, data, and architecture changes more scrutiny than a typo fix.
  • Do not measure reviewers by number of comments or speed; that rewards the wrong behavior.
  • Track recurring findings and fix their cause (an instruction file line, a lint rule, a test helper).

8. Practical Exercise

For SignalDesk (or your project):

  1. Write the team’s review checklist and place it in CONTRIBUTING.md, tailored to your risks (including multi-tenancy).
  2. Take a pull request or branch from the previous lessons. Run the AI first-pass review prompt and record each finding.
  3. Verify every AI finding: mark each as confirmed, false positive, or unclear, with evidence.
  4. Perform your own human review using the checklist, and record at least three findings the AI missed or got wrong, or explain why there were none.
  5. Write review comments for two findings, labeled blocking or suggestion, with explanations.
  6. Keep a review log with the date, change, findings, and what was fixed.

Verification

You are ready to continue when:

  • A review checklist exists and matches your project’s real risks.
  • Every AI finding was verified before action.
  • Human review covered design, security, and tests, not only style.
  • Review comments are specific, labeled, and constructive.
  • Pull requests have descriptions that include verification and AI-involvement notes.

Key Takeaways

  • Review is the main quality control when code is cheap to generate.
  • Authors own their changes and must understand them before asking for review.
  • Use a structured checklist and automate everything a machine can check.
  • AI is a useful first-pass reviewer, but not an approver; verify its findings.
  • Keep changes small and review sustainable.

What’s Next?

So far we have worked on code we control. Next, we deal with code we did not write or no longer understand: legacy and unfamiliar code, and how to use AI to build understanding safely.