Shipping reliable AI apps, part 11 of 11
How AI Code Review Works, and the Bugs It Still Misses
Why AI code reviewers raise false alarms and miss real bugs, and the finder plus separate verifier setup, with a failing test as proof, that makes their comments worth reading.
After this video
You can set up AI code review so only findings a separate verifier confirmed with a failing test reach your pull request.
The short version
An AI reviewer reads your diff and some context and guesses where the bugs are; it doesn't run the code, so it misses bugs that live outside the diff and flags problems that aren't there. The fix Cloudflare built its security harness on: the agent that finds a bug never confirms it. A fresh verifier tries to disprove each finding, sorts it into confirmed, needs validation or rejected, and a confirmed finding needs a test that fails on the unchanged code. A single run still misses about half of what repeated runs find, so write your business rules down and keep a person on the merge.
The fix first
Separate finding from checking. A second agent with a fresh context tries to prove each finding wrong, and only survivors reach the pull request. In Cloudflare's harness about 12,000 of 20,799 raw findings survived validation.
What a reviewer reads
A reviewer gets the diff, surrounding code and your rules, and a model writes comments. It reads code, it doesn't run it, so bugs that need two files and a timing problem are easy to miss.
The price cache. A diff wraps the price lookup in a shared cache helper; the helper keys on the first argument only, so a euro customer gets the cached dollar price.
False alarms
When unsure, models tend to guess with confidence, because training rewards a guess over admitting doubt. Make every finding carry evidence: file, line and the input that triggers it, and check cheap facts with plain code.
The safe query. A query with a $1 placeholder sends the input separately, so the flagged SQL injection isn't there.
The verifier
Models rarely fix their own answers without outside feedback and favour their own text, so the verifier is a separate call that sees only the finding and the code, and answers confirmed, needs_validation or rejected.
Proof by test
A confirmed finding ships with a test that runs against the unchanged code: it fails before the fix and passes after. Unchanged, because agents have been seen editing source to make their own exploit work.
The currency test. Ask for product 42 in dollars, then in euros, expect two prices: the unchanged code fails; a cache key built from every argument passes.
What it misses
One run found about half the bugs several runs found, mostly the simpler ones, and no one can state a miss rate. Run the finder twice on risky changes, write business rules in an instructions file, and keep careful human review.
The code
type Finding = { file: string; line: number; claim: string; trigger: string };
type Verdict = "confirmed" | "needs_validation" | "rejected";
async function verify(f: Finding, code: string): Promise<Verdict> {
const prompt = `You did not write this finding. Try to disprove it.
Finding: ${JSON.stringify(f)}
Code:
${code}
Answer with one word: confirmed, needs_validation or rejected.`;
const answer = (await callModel(prompt)).trim();
return (["confirmed", "needs_validation", "rejected"].includes(answer)
? answer : "needs_validation") as Verdict;
}it("caches prices per currency", async () => {
const usd = await getPrice(42, "USD");
const eur = await getPrice(42, "EUR");
expect(eur).not.toBe(usd); // unchanged code: both are the dollar price
});Check yourself
Why should the agent that found a bug not be the one that confirms it?
Models rarely correct their own answers without outside feedback and score their own work higher; a hunter grading its own homework validates everything.
What turns a confirmed finding from an opinion into proof?
A test that runs against the unchanged code and fails, then passes after the fix.
Why can an AI reviewer miss the currency bug in the price-cache pull request?
It reads code without running it, and the bug lives in the shared cache helper outside the diff, which builds its key from the first argument only.
Sources
Every claim in this video was checked against these pages. Open one to see the claims it backs and the exact words they rest on.
blog.cloudflare.com/build-your-own-vulnerability-harness
- In Cloudflare's experience, an AI hunter agent that grades its own findings confirms nearly everything it reports.
If a Hunter is allowed to grade its own homework, it will confidently validate everything it outputs.
- Cloudflare's validator agent cannot file findings of its own; its only job is to disprove the hunter's finding.
This Validator cannot log findings of its own
- Cloudflare's discovery harness produced 20,799 raw candidate findings, of which about 12,057 survived independent validation.
Out of 20,799 raw candidates generated by VDH, only about 12,057 survived validation.
- About four in ten of Cloudflare's raw findings were removed at validation.
1 - 12057/20799 = 0.42, about 4 in 10
- Every finding Cloudflare confirms must ship with a proof-of-concept test that runs against the original, unchanged code.
Every confirmed finding ships with a PoC written as a test that runs against the original, untouched codebase.
- Cloudflare saw agents edit the source code so their own exploit works, then report the bug they had created.
The agent will edit the source code so its own exploit works, then triumphantly report the bug it just created.
- A Cloudflare hunter must state the threat model (who the attacker is, what boundary breaks) before it can file a finding.
A Hunter has to state the threat model before it's allowed to file anything.
- Cloudflare uses one model for discovery and a different model for validation, so the models check each other.
We use one model for VDH, but we use a completely different model for VVS, so the models are effectively double-checking each other.
- One run of Cloudflare's skill found only about half the bugs that multiple runs found together.
a single run finds only about half the bugs you'd catch across multiple runs.
- The bugs a single run found skewed toward the simpler, less subtle ones.
In our experience the ones it did find skewed toward the simpler and less subtle.
- Cloudflare does not claim a false-negative rate, because there is no labelled list of every real bug in a codebase.
We don't claim a false-negative rate for our system. There's no labeled set of every real bug in a codebase
- Cloudflare runs its big scans as a periodic backlog sweep, not as a check on every pull request.
It's also why, for us, the big scans are a periodic backlog sweep and not a per-PR check.
- Cloudflare's worst full scan of one repository took just over 14 hours.
the worst run took just over 14 hours.
- For per-PR checks, Cloudflare says cheaper, smaller harnesses are the right tool.
Cheaper, smaller harnesses are the right tool for that job.
- Before a finding survives, plain deterministic code (not a model) checks that the files and paths it cites actually exist.
mechanically verifies that the cited files and paths actually exist
- Agents hold one hypothesis at a time and fill their context window after covering a small part of a real repository.
agents only hold one hypothesis at a time, fill their context window after covering a sliver of a real repo
- Cloudflare's fixer never merges code itself; a human reviews the branch.
The Fixer never merges code on its own; a human must review the branch.
- Reading source code isn't enough to know how it behaves under stress; Cloudflare's hunters compile and run code to check.
Reading source code isn't enough to understand how it behaves under stress
- Cloudflare's fixer needs a clean fail-to-pass flip on the target test before a patch clears the gate.
it requires a clean fail→pass flip on the target test to clear the gate.
- Cloudflare's harness has a fixer agent that writes patches and runs the regression test before and after.
Fixing Generates patches, runs regression tests
- In Cloudflare's experience, an AI hunter agent that grades its own findings confirms nearly everything it reports.
raw.githubusercontent.com/…/README.md
- The security-audit skill's rule: the agent that checks a finding is never the agent that found it.
The agent that checks a finding is never the agent that found it.
- The skill gives every candidate finding to a fresh verifier that tries to disprove it.
give every unique candidate to a fresh verifier that tries to disprove it.
- The skill sorts findings into three verdicts: confirmed, needs_validation and rejected.
write `confirmed`, `needs_validation`, and `rejected` records to `findings.json`
- Cloudflare's open-source security-audit skill is the skill that seeded its vulnerability discovery harness.
This is the skill that seeded Cloudflare's vulnerability discovery harness
- Cloudflare's security-audit skill is a set of instructions for a coding agent that turns it into a security auditor.
A coding-agent skill that turns your agent into a security auditor.
- The security-audit skill's rule: the agent that checks a finding is never the agent that found it.
docs.github.com/…/code-review
- GitHub says Copilot code review can hallucinate: flag problems that don't exist or that come from misunderstanding the code.
it may highlight problems in reviewed code that do not exist or are based on misunderstandings of the code.
- GitHub says Copilot may not find all problems, especially in large or complex changes.
Copilot may not identify all of the problems that are present in code, especially where changes are large or complex.
- GitHub says Copilot code review should be supplemented with careful human review.
Copilot code review should be supplemented with careful human code review.
- GitHub: code Copilot generates may look valid but not actually be correct.
The code generated may appear to be valid but may not actually be semantically or syntactically correct
- GitHub says Copilot code review can hallucinate: flag problems that don't exist or that come from misunderstanding the code.
docs.github.com/…/code-review
- Copilot code review can analyse the whole repository to understand the context of a change, not only the diff.
This capability analyzes your entire repository to better understand the context of code changes.
- GitHub estimates an average Copilot review costs $0.25 (Lite), $1.50 (Balanced) and $10 (Max).
On average, a review costs an estimated $0.25 USD with Lite, $1.50 USD with Balanced, and $10 USD with Max.
- Repository-wide review rules for Copilot go in .github/copilot-instructions.md.
Use .github/copilot-instructions.md for repository-wide rules specific to Copilot
- GitHub: Copilot is not guaranteed to spot all problems in a pull request.
Copilot is not guaranteed to spot all problems or issues in a pull request.
- Copilot code review can analyse the whole repository to understand the context of a change, not only the diff.
arxiv.org/…/2310.01798
- Research (ICLR 2024): models struggle to correct their own answers without outside feedback, and sometimes get worse after trying.
our research indicates that LLMs struggle to self-correct their responses without external feedback, and at times, their performance even degrades after self-correction.
- Research (ICLR 2024): models struggle to correct their own answers without outside feedback, and sometimes get worse after trying.
arxiv.org/…/2404.13076
- Research: a model used as a judge scores its own outputs higher than others' that humans rate as equally good (self-preference).
One such bias is self-preference, where an LLM evaluator scores its own outputs higher than others' while human annotators consider them of equal quality.
- Research: a model used as a judge scores its own outputs higher than others' that humans rate as equally good (self-preference).
arxiv.org/…/2211.03622
- A user study (CCS 2023) found participants with an AI code assistant wrote significantly less secure code than those without.
participants who had access to an AI assistant based on OpenAI's codex-davinci-002 model wrote significantly less secure code than those without access.
- In the same study, participants with the AI assistant were more likely to believe their code was secure.
participants with access to an AI assistant were more likely to believe they wrote secure code than those without access to the AI assistant.
- A user study (CCS 2023) found participants with an AI code assistant wrote significantly less secure code than those without.
arxiv.org/…/2509.04664
- Models hallucinate because training and evaluation reward guessing over admitting uncertainty (OpenAI researchers, 2025).
We argue that language models hallucinate because the training and evaluation procedures reward guessing over acknowledging uncertainty
- Like students facing a hard exam question, models sometimes guess when unsure, giving plausible but wrong statements instead of admitting it.
Like students facing hard exam questions, large language models sometimes guess when uncertain, producing plausible yet incorrect statements instead of admitting uncertainty.
- Models are optimised to be good test-takers, and guessing when unsure improves test scores.
language models are optimized to be good test-takers, and guessing when uncertain improves test performance.
- Models hallucinate because training and evaluation reward guessing over admitting uncertainty (OpenAI researchers, 2025).
docs.anthropic.com/…/model-ids-and-versions
- On the Claude API, an alias like claude-sonnet-4-5 points to the most recent dated snapshot, so the model behind it can change.
An alias such as claude-sonnet-4-5 is a convenience pointer that resolves to the most recent dated snapshot for that minor version.
- A full Claude model ID names one pinned version of the model.
Each Claude model ID identifies a pinned version of the model.
- On the Claude API, an alias like claude-sonnet-4-5 points to the most recent dated snapshot, so the model behind it can change.
docs.claude.com/…/claude-4-best-practices
- Anthropic's prompting guide lists literal instruction following among the things to re-check when prompts move from earlier model generations.
literal instruction following, and design and frontend defaults.
- Anthropic: to get more than the task strictly requires, ask for it explicitly instead of relying on the model to infer it.
If you want Claude to do more than the task strictly requires, explicitly request it rather than relying on the model to infer this from vague prompts.
- Anthropic's prompting guide lists literal instruction following among the things to re-check when prompts move from earlier model generations.
node-postgres.com/…/queries
- With a parameterized query, node-postgres sends the query text unaltered and the parameters separately, avoiding the SQL injection that string concatenation causes.
node-postgres supports parameterized queries, passing your query text unaltered as well as your parameters to the postgresql server where the parameters are safely substituted into the query
- With a parameterized query, node-postgres sends the query text unaltered and the parameters separately, avoiding the SQL injection that string concatenation causes.
docs.stripe.com/…/idempotent_requests
- An idempotency key lets you safely retry a request without performing the same operation twice (Stripe).
the api supports idempotency for safely retrying requests without accidentally performing the same operation twice.
- Retries with the same idempotency key return the saved response of the first request (Stripe API v1).
retries with the same key return the saved response, including 500 errors.
- An idempotency key lets you safely retry a request without performing the same operation twice (Stripe).
docs.anthropic.com/…/model-deprecations
- Anthropic regularly retires older models as newer ones launch.
As safer and more capable models launch, Anthropic regularly retires older ones.
- A retired model is no longer available, and requests to it fail.
Retired: The model is no longer available for use. Requests to retired models fail.
- Anthropic regularly retires older models as newer ones launch.
Spotted a mistake? Say so in the video's comments. Fixes are listed on corrections.