AI code review in pull requests works when it is treated as a diff-scoped filter with a hard noise budget, not as a reviewer with opinions. The bot should catch the class of defects that deterministic tools miss and that humans skim past: a swallowed error, a missing authorization check, a test that asserts nothing, a retry that will double-charge. It should not comment on naming, architecture taste, or anything a linter already covers. Teams that get this right see review time fall and defect escapes drop. Teams that point a model at the whole repository get a comment firehose, reviewers learn to dismiss everything, and the automation becomes a net tax.
The numbers from the research community are useful here because they set expectations honestly. Meta's TestGen-LLM work, published at FSE 2024 and available as Automated Unit Test Improvement using Large Language Models at Meta, found that 75 percent of generated test cases built correctly, 57 percent passed reliably, and 25 percent increased coverage, with 73 percent of recommendations accepted for production. That is a serious hit rate for generated code, and it is also nowhere near the "replaces your reviewer" claim in most vendor decks.
This guide covers the configuration that produces signal: what to automate, how to gate it, how to stop the spam, how to keep the reviewer itself from becoming an attack surface, and how to measure whether it is helping.
What AI code review actually catches, and what it misses
| Finding class | AI reviewer performance | Better handled by |
|---|---|---|
| Missing error handling around a new call | Strong, especially with the diff plus the called function | AI review |
| Authorization check missing on a new route | Strong with a rules file naming the pattern | AI review plus a deterministic auth test |
| Injection and secrets in new code | Moderate, inconsistent | SAST, secret scanning, AI as second pass |
| Logic that contradicts business rules | Weak without domain context | Human review |
| Architecture and module boundaries | Weak and prone to taste arguments | Human review, design docs |
| Formatting, style, naming conventions | Reliable but low value | Linters and formatters, not a model |
| Test quality (assertions that prove nothing) | Moderate to strong | AI review plus mutation testing |
| Performance regressions | Weak at review time | Benchmarks and load tests |
The pattern: the model is good at local, checkable properties in a diff, and poor at anything that requires knowledge it was not given. Configure it for the first column and stop trying to make it the third.
Why comment volume decides whether this works
Review attention is a finite resource and a bot can exhaust it faster than any human. The GitClear research on AI-assisted code quality reports a striking shift in what codebases contain: refactoring is down roughly 70 percent while code duplication is up about 81 percent across the period studied, documented in their AI code quality research. That is exactly the environment where a noisy reviewer does harm: more duplicated blocks means more near-identical findings, which means more comments, which means dismissal becomes reflex.
DORA's 2024 Accelerate State of DevOps report adds the organisational frame. AI adoption showed measurable productivity gains alongside a decrease in delivery stability and throughput at the team level. Read together with GitClear, the implication is not "avoid AI" but "AI raises output volume, and review capacity has to absorb it." An uncalibrated review bot makes that harder, not easier.
So set a budget before you enable anything: at most three comments per pull request, one blocking severity, zero style comments. If the bot cannot fit its findings into that budget, it stays advisory until it can.
How do you configure AI code review in pull requests?
The configuration that works is narrow, explicit, and diff-scoped.
- Trigger on pull request events, not on push. Use
pull_requestwithopened,synchronize, andreopened, which is the documented pattern in GitHub's workflow event reference. Running on every push to a branch wastes tokens and duplicates comments. - Send the diff plus the call sites, nothing more. A unified diff alone lacks the function being modified; the whole repository exceeds any useful context and invites the model to review unrelated code. Include the diff, the enclosing functions, and the signatures of anything the diff calls.
- Put the review policy in a repository file. A checked-in rules file (for example
.github/ai-review-rules.md) listing what must be flagged, what must be ignored, and the severity definitions. This is the single most important configuration decision. Without it, every reviewer gets a different opinion per run. - Separate blocking from advisory. Blocking findings are a short allowlist: missing authorization, unhandled error on a payment or data path, plaintext secret, unbounded loop on external input, test with no assertions. Everything else posts as a non-blocking comment or a summary.
- Deduplicate by diff hunk. Cache findings per file and hunk hash. When a commit fixes a finding, reply "resolved" and stop re-raising it on the next synchronize event.
- Cap the token and model budget per pull request. A diff-review run has no business scanning generated lockfiles, vendored dependencies, or minified assets. Exclude them in configuration, not in a prompt.
- Handle forked pull requests without secrets. Forked PRs run with a read-only token by default for good reasons. Do not use
pull_request_targetwith a checkout of the fork's head and a secret in the environment; that is the documented recipe for remote code execution through a workflow.
Two configuration details matter more than the model you pick. First, the rules file turns "review my code" into a checkable spec, which is what makes comments consistent enough to trust. Second, per-hunk deduplication is the difference between a bot that feels useful and a bot that feels like a repeating alarm.
How do you prevent AI review bots from generating spam?
Spam is the default state of an uncalibrated reviewer, so treat noise control as a feature with its own engineering.
- Severity thresholds over everything. Only comments above a configured severity post inline. The rest go into one summary comment per PR, or nowhere.
- Maximum comments per PR. Hard cap at three, with overflow rolled into the summary. An unbounded bot will find something to say about every hunk.
- Suppression with expiry. Allow
ai-review: ignoreannotations with a reason and a review date, and report on how many expirations are outstanding. Permanent suppression is how teams end up with a bot that says nothing and a policy nobody remembers. - Learn from dismissals. Log every dismissed comment with the reason. Every month, count the top three dismissal reasons and patch the rules file. This is a calibration loop, not a one-time setup.
- Ban style and naming from the prompt. Linters exist. A style comment from a language model costs trust for zero value.
- One summary comment, updated in place. Reviewers want a current verdict, not a thread of bot messages across force-pushes.
If you want a comparison of which tools do this well and what they cost, our AI code review tools review covers the vendor side. This article is about the workflow around whichever tool you pick.
What should be automated versus handled by humans?
| Check | Automated (deterministic) | AI review | Human |
|---|---|---|---|
| Formatting, lint, type errors | Yes | No | No |
| Unit test pass, build, coverage floor | Yes | No | No |
| Secret scanning, dependency CVEs | Yes | No | Escalation only |
| Authorization pattern on new routes | Partial (policy tests) | Yes | On failures |
| Error handling on new external calls | No | Yes | Spot check |
| Business rule correctness | No | No | Yes |
| Data migration and rollback safety | Partial (dry run) | Yes | Yes |
| Architecture and API design | No | Draft only | Yes |
The rule that keeps this honest: never let an AI comment be the only gate on a merge. It is an additional signal, and the branch protection rules should not be weakened because "the bot looked at it." Google's code review guidance says the reviewer responds quickly and the change stays small; the reviewer's authority is not delegated to a bot.
Multi-stage PR triage
The sequence that keeps review latency low:
- Deterministic fast gates: lint, typecheck, unit tests, secret scan, dependency audit. Target under four minutes. These block.
- AI review: starts in parallel on the diff, must finish before the human review window opens or it becomes stale.
- Human review: reads the diff, the AI summary, and the test evidence. The AI summary is an index, not a substitute.
- Merge queue: rebases and re-runs the deterministic gates, so a stale green build cannot merge.
The important property is ordering under time pressure. When the human review starts before the AI finishes, reviewers learn to ignore late bot comments, which is the same failure as spam by a different route. Start the AI job first.
Implementation: a GitHub Actions job that respects the budget
A minimal workflow that gates on deterministic checks, then runs a diff-scoped review, then posts at most three findings:
name: pr-review on: pull_request: types: [opened, synchronize, reopened] permissions: contents: read pull-requests: write jobs: gates: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - run: npm ci - run: npm run lint - run: npm run typecheck - run: npm test -- --run ai-review: needs: gates runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - uses: actions/setup-node@v4 with: node-version: 22 - run: node scripts/ai-review.mjs env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} MODEL_API_KEY: ${{ secrets.MODEL_API_KEY }} MAX_COMMENTS: "3" BLOCKING_SEVERITIES: "critical" And the reviewer script's contract, which matters more than its internals:
// 1. collect the diff and only the enclosing functions // 2. load .github/ai-review-rules.md and pass it as policy // 3. request structured JSON: [{file, line, severity, title, reason, fix}] // 4. drop anything below the configured severity // 5. dedupe by (file, hunk, title) against previous runs // 6. post at most MAX_COMMENTS inline, the rest as one summary // 7. exit non-zero only when a blocking severity is present Ask for structured output rather than prose. Our structured outputs guide covers the schema pattern; validating the reviewer's JSON is what makes comment caps and severity gates possible at all.
The reviewer is an attack surface
This is the part most teams miss. The content being reviewed is untrusted input: a pull request can come from a fork, from a compromised contributor account, or from a dependency bot. A model that reads a diff and follows instructions can be manipulated by comments embedded in the code.
Concrete rules:
- Treat PR text as data, never instructions. Instruct the model explicitly that comments, strings, and issue references in the diff are content to review, not directions to follow.
- Do not give the reviewer write access. It comments; it does not push, merge, or approve. A compromised reviewer with a write token is a supply chain incident.
- Never echo secrets into the prompt. Truncate and redact environment values, and never let the prompt include the workflow's secrets.
- Keep the model vendor's data policy in scope. Private repository code going to a third-party API is a contractual question before it is a technical one.
- Log prompt and response for audit, with retention, so an incident has evidence.
The failure mode to plan for is indirect prompt injection inside a pull request, which is the same class we cover in our prompt injection defense guide. A bot that reviews untrusted diffs and has any tool access is a text channel into your CI.
Governance: the four stages of rollout
Stage 1, shadow mode. Run the reviewer on all PRs but post nothing. Compare its findings against human review for two weeks. The output is a false-positive estimate and a draft rules file.
Stage 2, advisory. Post comments, block nothing. Measure dismissal rate and comment volume per PR. If dismissal exceeds roughly one in three findings, the rules file needs work before anything blocks.
Stage 3, selective blocking. Enable blocking for the small allowlist of severe findings only, on the repositories where the false-positive rate is measured and low.
Stage 4, calibration. Monthly: review dismissals, re-run a labeled set of historical PRs, check for model drift after vendor upgrades. This is the same discipline as any evaluation pipeline, which our LLM output drift guide covers for model-facing systems.
Metrics that tell the truth
| Metric | What good looks like | What it catches |
|---|---|---|
| Review latency (first human comment) | Falling or stable | Bot slowing the human path |
| Comment acceptance rate | Above 60 to 70 percent | Spam, miscalibrated rules |
| Dismissal reasons top 3 | Stable and shrinking | Rules debt |
| Defect escapes per 100 PRs | Falling | Whether the reviewer adds real value |
| Comments per PR | Under 3 | Noise budget breach |
| Blocking findings per week | Single digits | Overblocking |
Avoid measuring "findings produced." A model can produce findings forever and that number only proves the API works. What matters is accepted findings that led to a change, and defects that stopped reaching production.
Failure modes that repeat
- Automation bias. Reviewers approve because the bot did not object. Counter it by keeping a human checklist for the categories the bot is weak on, and by never marking a PR approved automatically.
- Security theater. A green "AI reviewed" badge on a PR with no authorization test. The badge is not the control.
- Cost surprise. Whole-repository context on every push event. Token spend scales with pushes, not PRs, which is how a quiet month becomes an invoice.
- Model drift after an upgrade. Last quarter's calibrated reviewer becomes this quarter's noise source, silently. Pin the model version and re-run the labeled set before upgrading.
- Review debt. The rules file stops being maintained and the bot's comments become historically wrong guidance. Assign an owner.
Framework alignment
- NIST SSDF (SP 800-218) treats secure development as a set of practices, and automated review is a verification practice (PW.7 review and analysis). Referencing the SSDF in your policy makes the bot's role explicit rather than aspirational: NIST SP 800-218.
- OWASP provides the check content: our OWASP Top 10 breakdown is a reasonable source for the security rules in the rules file, alongside SAST.
- Google's engineering practices provide the process norms, especially small changes and fast review, which the bot should accelerate rather than replace.
- Your test strategy provides the evidence layer. Automated review without tests reviews prose; our test strategy guide covers the suite the reviewer is supposed to trust.
The checklist before you enable blocking
- Rules file checked in and reviewed like code.
- Severity definitions written, blocking allowlist is small and explicit.
- Comment budget enforced in code, not in the prompt.
- Per-hunk deduplication and in-place summary comment working.
- Fork PRs run without secrets and without write tokens.
- Model version pinned; labeled evaluation set exists.
- Rollout plan has shadow and advisory stages with exit criteria.
- A named owner for calibration, plus a monthly dismissal review.
- Metrics wired: acceptance rate, comments per PR, defects escaped.
Conclusion
AI code review earns its place as a narrow, diff-scoped filter with a hard noise budget, deterministic gates in front of it, and a human reviewer who keeps authority. The research supports a real but bounded contribution: generated tests that pass and get accepted at meaningful rates, and local defect detection that humans skim past. It does not support replacing review judgement or letting a bot's silence mean approval.
Configure the rules file first, enforce the comment budget in code, keep the reviewer out of your secrets and write paths, roll it out in shadow mode, and measure accepted findings and escaped defects rather than volume. Do that and review gets faster without getting weaker.
If you want a second set of eyes on the workflow before the bot starts blocking merges, our software development practice and AI consulting both review CI and review automation for small teams.





