Sub topic 8
Reviewing AI-assisted pull requests
This chapter assumes you know the basic pull request workflow, have reviewed code in a team, and have used an AI coding assistant. It builds on the previous chapter, where the author owns the change. Here the focus is the reviewer's side: what changes when the code in front of you was partly or fully drafted by a tool.
Why review needs adjusting
Review has always been a check on the author's judgment. With AI assistance, three things shift.
- Volume goes up. A tool can produce a 600-line diff in minutes. Reviewer time does not grow at the same rate.
- Surface quality goes up. Generated code is usually well formatted, consistently named, and commented. It looks trustworthy even when it is wrong.
- Author familiarity goes down. The author may not have worked through the problem, so the usual question "why did you do it this way?" can get a weak answer.
The policy does not need a separate review process. It needs the same process with a few explicit adjustments, so reviewers know what to look for and what they can expect from authors.
The reviewer's baseline: the author has already reviewed it
The first rule belongs to the author. Before requesting review, the author reads the whole diff as if someone else wrote it. The pull request template from the policy makes this a visible commitment:
<!-- .github/pull_request_template.md -->
## What changed and why
## How I verified it
- [ ] I read and understand every line in this PR
- [ ] I ran the tests locally
- [ ] New or changed behavior has tests
## AI assistance (per team policy)
- [ ] No AI tool was used
- [ ] AI tool used for part of this change (tool and scope: ____ )
- [ ] No secrets, customer data, or restricted code were shared with the toolReviewers can use this as a gate. If the description is empty or the author cannot explain a section, the reviewer sends the pull request back without a line-by-line review. Reviewing unread code is a poor use of the reviewer's time.
Common failure patterns in generated code
Knowing what tools tend to get wrong lets you review with a checklist instead of general suspicion.
| Pattern | What it looks like | What to check |
|---|---|---|
| Plausible but wrong API use | A call that matches a real library's style but uses a method, argument, or default that does not exist or behaves differently | Look up unfamiliar calls in the library documentation. Confirm the dependency version in use |
| Invented dependencies | An import of a package that does not exist, or a near-miss name of a real one | Check every new entry in the lockfile. Confirm each package is known and expected |
| Missing edge cases | Happy-path logic with no handling of empty input, nulls, timeouts, or concurrency | Ask what happens at each boundary. Look for tests that cover them |
| Insecure defaults | String-built SQL, disabled certificate checks, broad CORS settings, weak hashing, secrets in code | Review any code touching input handling, authentication, and crypto with extra care |
| Tests that prove little | Tests that assert what the code already does, mock away the real logic, or never fail | Break the code on purpose and confirm a test fails |
| Scope creep | Unrelated renames, reformatting, or "improvements" mixed into the change | Compare the diff to the stated purpose. Ask for a split |
| Copied local patterns that do not fit | Code that mimics a nearby file but ignores a different constraint here | Check that the approach suits this module, not just the one it resembles |
None of these are unique to AI. They are simply more frequent, and harder to spot because the code reads well.
Review the behavior, not just the text
A diff shows what changed, not whether it works. For AI-assisted changes, put more weight on evidence of behavior.
- Read the tests first. Tests describe intended behavior. If they are thin, the code is not ready no matter how clean it looks.
- Run it. For risky changes, check out the branch and exercise the feature. Do not rely only on a green CI run.
- Mutate a test. Change one condition in the code, such as flipping a comparison. If all tests still pass, they are not protecting that logic.
- Ask for an explanation. A short comment such as "why this approach instead of X?" tests whether the author understands the change. A good answer is quick and specific.
The following snippet shows the kind of test weakness reviewers should look for. The test passes, but it would pass for almost any implementation.
def apply_discount(price: float, percent: float) -> float:
return price - price * percent / 100
def test_apply_discount_weak():
# Only checks that something numeric comes back.
assert isinstance(apply_discount(100, 10), float)
def test_apply_discount_useful():
assert apply_discount(100, 10) == 90
assert apply_discount(100, 0) == 100
assert apply_discount(100, 100) == 0A reviewer should also ask what happens with a percent above 100 or below 0. The function accepts both and returns nonsense. A tool that wrote only the first test would never reveal this.
Calibrate depth by risk
Not every change deserves the same scrutiny. A practical policy sets review depth by what the change touches, not by whether AI was used.
- Low risk: documentation, test-only changes, small refactors with strong existing tests. Normal review.
- Medium risk: new features in non-sensitive areas, changes to shared libraries. Normal review plus a reviewer who runs the change or checks the tests closely.
- High risk: authentication, authorization, payments, cryptography, data migrations, infrastructure, and CI configuration. Required review by the owning team, and no merge on a single quick approval.
The CODEOWNERS file enforces the high-risk tier. It routes changes in sensitive paths to the designated owners regardless of who or what wrote the code:
# .github/CODEOWNERS
# Changes to these paths always need review from the named owners,
# no matter how the code was written.
/auth/ @example-org/security-team
/payments/ @example-org/payments-team
/.github/ @example-org/platform-team
/docs/policies/ @example-org/engineering-leadsCODEOWNERS only blocks merging when branch protection has "Require review from Code Owners" turned on. The file alone is a suggestion. The next chapter covers that setting.
Handling large diffs
Large AI-generated diffs are the hardest case. Reviewers tend to skim, and skimming is where defects pass through. Set a team expectation rather than relying on individual discipline.
- Ask authors to keep pull requests small and single-purpose, ideally one logical change each.
- Allow reviewers to decline a pull request that is too large to review well. The reply should ask for a split, not just reject.
- Prefer stacked or sequential pull requests: first the refactor, then the behavior change.
- For unavoidable large changes, such as a generated migration, require a written walkthrough in the description and a second reviewer.
A reviewer who approves code they did not fully understand has still shared responsibility for it. The policy should say that reviewing carefully is part of the job, and that "I could not review this properly" is an acceptable and expected answer.
Reviewer etiquette and shared accountability
Reviewers should address the author, not the tool. "The AI did this" is never a valid response to a review comment. If the author cannot defend or fix a section, the section is not ready.
Keep comments on the code and its behavior. Do not ask authors to prove how they wrote it. Disclosure is covered separately, and it is meant to help reviewers focus, not to punish tool use.
Responsibility is layered:
- The author is accountable for correctness, security, and policy compliance.
- The reviewer is accountable for a careful check within the scope they accepted.
- The code owner is accountable for the sensitive area the change touches.
Where the checks happen
Human review is one layer among several. The diagram shows how a pull request moves through them.
Automated checks run first so human attention goes to what machines cannot judge: design fit, intent, and risk. The CI workflow below runs the same tests for every pull request, whoever wrote the code:
# .github/workflows/ci.yml
name: ci
on:
pull_request:
push:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm testEdge cases to decide in your policy
- Author used AI but did not disclose. The review should not change tone. Judge the code. Handle the missed disclosure as a process matter, not an accusation.
- Reviewer used AI to review. Using a tool to get a first pass is reasonable, but the reviewer still owns the approval. The same data rules apply: do not paste restricted code into unapproved tools.
- Bot-authored pull requests. Dependency updates and agent-opened pull requests need a named human who is accountable for merging them.
- Urgent fixes. Define a fast path, such as one reviewer instead of two, but do not skip review entirely. The incident chapter covers exceptions.
- Disagreement over depth. Let the reviewer's judgment win on whether a change is understood well enough. The cost of asking for more is smaller than the cost of a missed defect.
Summary of reviewer expectations
- Expect the author to have read and tested the change, and send it back if not.
- Check the tests and the behavior before the style.
- Verify new dependencies and unfamiliar API calls.
- Scale scrutiny by risk, and route sensitive paths to code owners.
- Ask for smaller pull requests when the diff is too big to review well.
- Direct feedback to the author, who owns the change.
Exercise
A teammate opens a 700-line pull request that adds a new payments export feature. The description says only "Added export." The tests check that the export function returns a list. Name three actions the reviewer should take, and say which team must be involved.
Show answer
First, return the pull request and ask for a real description and a completed template, including how the author verified it, because the author must explain the change before review starts. Second, ask for a split into smaller pull requests, or a written walkthrough and a second reviewer if it cannot be split. Third, require stronger tests, since a test that only checks for a list proves little. Check it by changing the export logic and seeing whether any test fails. Also verify any new dependencies. Because the change touches /payments/, CODEOWNERS requires review from the payments team, and branch protection must enforce that review.
Exercise
Why does the policy base review depth on the area of the code a change touches instead of on whether AI was used?
Show answer
Risk comes from what the code can affect, such as authentication or payments, not from who wrote it. A human-written change to the auth module can be as dangerous as a generated one. Basing depth on the area keeps the rule simple, applies equally to all authors, and does not depend on disclosure being accurate.