I planted 15 bad pull requests to test my AI code reviewer. Here is what broke.
An AI code reviewer told me "Merge After Fixes." My tests said the PR was broken. That gap is why I built CodeGuard AI, a self-hosted pull-request reviewer for Java and Spring Boot. The idea is simple: an AI opinion is
An AI code reviewer told me "Merge After Fixes."
My tests said the PR was broken.
That gap is why I built CodeGuard AI, a self-hosted pull-request reviewer for Java and Spring Boot. The idea is simple: an AI opinion is not evidence.
- Every finding is labeled: verified by rule, rule-based heuristic, AI finding with the code located, or AI inference.
- An unverified AI claim cannot score above 60/100, however confident the model sounds.
- The merge verdict comes from a policy you configure, not from the model.
- With sandbox validation on, it runs the project's tests in Docker on the PR head and the base branch, so a failure is labeled "new in this PR" or "already there."
This post is not a sales pitch. It is about what happened when I stopped adding features and tried to break it.
The lab
I wrote 15 pull requests against a small Java project: SQL injection, command injection, path traversal, SSRF, XXE, a broken build, fake tests, and a few pieces of safe code that must not be flagged (a prepared statement, a path guard, a hardened XML parser). Then I ran every one through the real app, with a real AI provider and real Docker.
It found more problems in my own work than months of reading my own code. Here are five.
1. The AI contradicted its own verdict
The policy said Do Not Merge. The AI's summary, written before the policy ran, still said "Safe to Merge." Both were technically correct. Together they were useless.
The fix was a small reconciler: when the final recommendation is stricter than the AI's, the summary gets a line saying so and why.
CodeGuard decision: Do Not Merge. 5 finding(s) meet the blocking policy
(severity >= High, confidence >= 80, VERIFIED, category in [Security, Bug, Team Rule]).
The AI's own summary, written before the policy check and not a verdict: ...
Lesson: when a model and a rule engine both speak, the user needs to know who has the last word.
2. A regex silently skipped a bad test
One rule flags tests that assert a value the test itself stubbed:
PriceService prices = mock(PriceService.class);
when(prices.total(10.0, 2)).thenReturn(20.0);
assertEquals(20.0, prices.total(10.0, 2)); // can never fail
The analyzer first collects fields and locals that are mocks. To avoid counting a mock that is later reassigned to a real object, it used a "shadow" pattern roughly like this:
"\\s*=\\s*(?!(?:Mockito\\.)?mock\\s*\\()" // assigned to something that is not a mock
Look at = mock(. The greedy \s* can backtrack and give back the space, so the lookahead then sees mock( (with a leading space), which is not mock(, and the negative lookahead passes. The mock was classed as shadowed and dropped. The tautology went unflagged.
The fix is one character:
"\\s*=\\s*+(?!(?:Mockito\\.)?mock\\s*\\()" // possessive: no backtracking
I only found this because I had planted that exact test and it did not fire. A happy-path demo would never have shown it.
3. Every review re-downloaded Maven
Most of a four-minute review was the sandbox downloading dependencies, because each review starts a fresh docker run --rm. I added an opt-in named volume:
codeguard.validation.dependency-cache-volume=codeguard-deps
which becomes -v codeguard-deps-maven:/root/.m2 for maven: images (and the Gradle equivalent). Typical review time dropped to roughly one to two minutes.
It is opt-in on purpose: a shared cache means code in one PR could influence the dependencies of a later run. That is a trust decision for the person running it, not for me.
4. A 422 with no explanation
A review failed with a generic message. The log showed a 413 from the AI provider: on Groq's free tier, input tokens plus the reserved output tokens count against a per-minute cap. A big diff plus a 4,500-token reservation blew past 8,000.
Two fixes: the real cause now appears in the review message, and the docs explain the limit and the knobs (a smaller input budget, another model, or a paid tier). Errors that name their cause are a feature.
5. "Build failed" is not an answer
When a PR does not compile, the finding now quotes the compiler output, parsed from Maven's [ERROR] lines: file, line, and the missing symbol.
src/main/java/com/lab/CheckoutService.java:12: cannot find symbol (symbol: variable taxRate)
Keeping it fixed: a benchmark with a gate
Fixing five bugs is easy to undo by accident, so I added a frozen benchmark: 73 cases, split into a development set, a held-out set and a set of known gaps. A JUnit test replays the real pipeline (diff parser, deterministic checks, security flow analysis, test-quality rules, ranker, merge policy) with no AI and no Docker, and fails the build if a rule regresses or a compliant case gets blocked.
When I added the new security cases, it immediately caught a false positive of mine: "SELECT COUNT(*) FROM " + TABLE was flagged as SQL concatenation even though only a constant was joined. Fixed the same day, with a test.
Honest limits
- The analysis is static and name-based, so it can miss indirect cases.
- The benchmark uses planted cases. It proves the rules behave as designed. It does not measure accuracy on real-world code.
- AI findings and fixes are advisory.
- It is a source-code product you run yourself, not a hosted service.
What I would tell anyone building a dev tool
- Plant known-bad cases and known-good ones. False alarms get a tool muted.
- Test through the real app at least once. My unit tests passed while the product contradicted itself.
- Freeze a benchmark and make the build fail on regression, so improvement cannot quietly undo itself.
- Make failures explain themselves.
CodeGuard AI is self-hosted Java 21 and Spring Boot with full source. There is a public preview (README, screenshots, one real module with tests) on GitHub: https://github.com/ISabiTech16/CodeGuard-AI
If you review Java PRs: what would you want an AI reviewer to prove before you trusted it?
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.