BlogAI & ML

How to Plant Realistic Bugs to Test AI Code Reviewers

To test AI code review tools, plant realistic bugs in real pull requests and prove each one. What makes a planted bug believable and what gives it away.

Nomos Insights
Updated 6 min read

AI tools are reviewing pull requests in a lot of companies now. How good are they really? To answer that, someone has to build pull requests with known bugs, write down the right answers in an answer key (the list of bugs a good reviewer should find) and see what the AI finds. That's what our engineers did on a recent code review benchmark project: they picked the pull requests, planted the bugs, wrote the answer key and proved every entry.

To test an AI code review tool, give it real pull requests with planted bugs you have proven by running the code, plus a few with no bugs, and score its review against a written answer key. The bugs have to feel real: slips the original author could have made, not obvious changes the diff hands over.

The short version of what we learned: a planted bug gets found almost every time if it shows up as a visible change in the diff (the line by line view of what the pull request changed).

Each task started from a real pull request in an open source project, in languages like Python, TypeScript, Go, JavaScript and Java. Most tasks had six to eight bugs, with at least one serious one. Deciding what counts as serious is its own skill, covered in our guide to rating bug severity in code review. Some had no bugs at all, to check that the AI doesn't invent problems. Those get their own post on clean pull requests and false alarms.

Key Takeaways
  • Each task started from a real pull request, with most tasks carrying six to eight bugs and at least one serious one.
  • A good planted bug is a slip the original author could have made. It fits the pull request and has one clear root cause.
  • A bug visible as a change in the diff was found in six to eight out of eight runs. A bug matching the old behavior was found in zero out of eight.
  • Every bug in the answer key was reproduced in a container. If we could not show it, it did not go in.

What makes a planted bug feel real?

A planted bug feels real when the original author of that pull request could have made the same slip. Making a bug is easy. Making a bug that feels like it belongs is the hard part, so that was our test for every one. Not a puzzle, not a trick. Just the kind of mistake that gets through a busy review.

A good planted bug:

  • Fits the purpose of the pull request.
  • Can be found using only the repository, the description and the diff.
  • Has a real consequence we can show by running the code.
  • Has one clear root cause.
  • Doesn't come with a helpful comment pointing at it.

What makes a planted bug look fake?

Patterns no real author would produce. Reviewers on our team got very good at spotting fake looking bugs, and the usual tells were:

  • All the bugs sitting in one file.
  • Every bug being a one character change.
  • Nearly all bugs being simple logic errors, with no design or cross file problems.
  • A pull request description that suddenly lists edge cases like a spec, which tells the model exactly where to look.

So we spread bugs across files and across types. Our plan had rough targets for each type: cross boundary problems, local logic errors, missing updates in related code, gaps between the spec and the tests, design problems, security issues and a few small style issues.

Why was our first attempt too easy?

On one early task, our engineers ran three fresh AI reviewer sessions against it as a quick dry run before the task went into the benchmark. All three found every bug. The reason was obvious once our reviewers looked at the diff. Every bug was a visible change from old behavior to new behavior in the diff, so an AI reviewer only had to compare the two.

That taught us something useful. A bug the model can see changing in the diff gets found almost every time. In one task, our engineers counted the results across eight runs: a changed line visible in the diff was found in six to eight of them. A bug that matched the old behavior exactly was found in zero out of eight. Moving a bug into a helper function didn't hide it at all. So when our engineers plant a bug now, they look at how it will show up in the diff, not only at whether it is wrong.

How do you prove a planted bug is real?

We reproduce it. For every bug in the answer key, our engineers built and ran the project in a container and showed the bug happening. If we couldn't show it, it didn't go in. That rule saved us more than once, because sometimes one planted bug hid another, and only running the code showed the second one could never be seen. The same rule runs the other way too. When a model reports a bug that is not in the key, a reviewer tests it before scoring, which we describe in our post on validating bugs missing from a benchmark answer key.

A code review benchmark is only as good as its bugs. Obvious bugs make every AI look great. Trick bugs make every AI look bad for the wrong reason. Realistic bugs, proven by running the code, are what give a fair picture. If you're building or buying an AI reviewer and want tasks like these, our team can help.

FAQ

What is a seeded defect? A bug added on purpose to a real code change so that an AI reviewer can be tested on whether it finds it.

How many bugs does a good code review task have? In our project, most tasks had six to eight bugs with at least one high severity bug. Some tasks were kept clean on purpose.

What makes AI reviewers miss bugs? In the runs our engineers checked, the misses were bugs that don't show up as a visible change in the diff, problems in secondary paths, unusual inputs, and things the code fails to do.

What is an AI code reviewer? A tool that reads a pull request and leaves review comments, the way a human reviewer would. Testing one means checking both the real bugs it finds and the problems it reports that are not there.


Need Code Review Tasks Built and Proven?

Our engineers build code review tasks for AI labs and model teams: realistic planted bugs, answer keys reproduced in a container, and clean pull requests that check for false alarms. We plan the work around your evaluation schedule.

Talk to Our Team
Filed underAI Code ReviewSeeded DefectsBenchmarksPull Requests