Pular para o conteúdo
← Back to Skalablog

Published article

Build an AI Code Review Agent That Catches Real Bugs

Software EngineeringClaude

Most first attempts at an AI code review agent look fine on day one and quietly fail on the rare catastrophic bug. The corrections that matter are a targeted prompt, a dataset of past incident pull requests, cross-model review and a codebase knowledge base, according to Greptile co-founder Daksh Gupta.

Start With a Sandbox, a Webhook and a Harness

A working AI code review agent starts as a sandbox plus a pull-request webhook: a GitHub or GitLab hook sends the pull request to an agent inside an isolated machine, and the agent posts comments back through the host's review API. Daksh Gupta, co-founder of the code review company Greptile, described this baseline and its failure modes in a 2026 AI Engineer talk.

The practical pieces are a sandbox vendor or a lightweight VM such as Firecracker, an agent harness, and API access to the git host. Gupta recommends a model-independent harness so the reviewer is not locked to one vendor, and names OpenCode as an open-source option.

The baseline does produce comments. A pull request opened in the morning gets feedback within about five minutes. What follows is the part most teams underestimate.

Why the First Version of an AI Code Review Agent Misses Bugs

The baseline agent misses many bugs because a generic review prompt has no model of which defect types actually hurt your codebase. Gupta lists four predictable failures: missed bugs, missing codebase context, runaway cost and nitpicky comments.

Cost is the surprise. Teams building review agents with coding agents report spending between $3 and $25 per pull request on review alone, according to Gupta's account of what companies tell him. Token spend accumulates quietly because a naive reviewer reads whole files repeatedly.

Nitpicks cause damage beyond annoyance. Review agents post comments to the pull request, and coding agents then read those comments and resolve them. Coding agents are not discerning, so a stream of pedantic remarks produces painfully defensive code. Gupta's phrase for the human cost is a boy who cries wolf: real problems get buried under stylistic complaints.

A further problem is instability. Rerunning the same agent on the same pull request surfaces new findings each time, which makes it hard to tell whether a prompt change improved the reviewer or simply changed its output volume.

Fix the Prompt Before Anything Else

Prompt optimization is the cheapest improvement available, and it should target two things: the specific bug types your codebase produces, and an explicit definition of what counts as a nitpick. Gupta calls this the lowest-hanging fruit because it needs no new infrastructure.

The evidence for which bug types matter should come from your own incidents. Mine past outages and postmortems, build a catalog of recurring defect classes, and have the prompt look for those classes by name. Tell the model directly which comments to suppress, such as demands for extra defensive layers or complaints about slightly awkward error handling.

Small prompt edits can swing comment volume sharply, which is the uncomfortable part. A reviewer can demonstrate that a bug exists but cannot demonstrate that no bug exists, so a quiet version of the agent may simply be missing findings. Gupta says Greptile's data science puts catastrophic bugs at roughly one in a thousand pull requests or lines of code, which means a silent regression can survive for months before an incident exposes it.

Build an Evaluation Set From Past Incident Pull Requests

A dataset of historical pull requests that caused incidents is the only reliable way to tune a review agent, because it converts an unmeasurable question into a replayable test. Companies that catalog postmortems already hold the raw material: a list of pull requests tied to outages.

Run every candidate version of the agent against that corpus and record how often it catches the known defect. This gives you a comparison between prompt changes instead of a guess based on how the comments read.

The dataset needs maintenance. Gupta estimates 80% to 90% of defects repeat earlier mistakes, while coding agents increasingly produce novel failure modes, so the corpus has to keep absorbing new incidents. One way to keep it current is to tie it to your own engineering culture and training programs, such as those run by Gustavo Dev Doido, where students are encouraged to document real production problems.

A second constraint is coverage. Unless a company has millions of pull requests, a single internal corpus will cover only a fraction of defect types, which is the structural advantage Gupta claims for Greptile's cross-company data.

Model Inversion: Review the Code With a Different Model

Model inversion means reviewing code with a different model family than the one that generated it, and Gupta reports a 10% higher catch rate when the reviewer is flipped. The mechanism he describes is correlated failure: the same model tends to miss the same defects during review that it introduced during generation.

The claim carries specific numbers. Gupta said in the 2026 talk that Claude models are roughly three times more likely than GPT models to produce off-by-one errors, while GPT models are significantly more likely to produce auth bypasses. He attributes both patterns to differences in post-training rather than to capability gaps.

Implementation is straightforward for most pull requests and awkward for the rest. Codex names branches in a codex/ format, and Claude writes a co-authored-by trailer in the commit or pull request description, so the generating agent is identifiable about 80% of the time. The remaining cases need heuristics, telemetry from developer machines, or an internal catalog of which agents engineers use.

The 10% figure sits on Greptile's own comparisons, so treat it as a vendor-reported measurement rather than an independent benchmark. Gupta's framing is that in incident terms a ten percent lift in catch rate is large.

Codebase Context and the Living Wiki

Codebase context is what lets a reviewer decide whether a suspicious line sits inside an authenticated path, and Greptile's answer is an indexed knowledge base it calls a living wiki. Gupta argues that grep, the standard text-search tool, is too imprecise and too expensive to serve as that index.

His cost argument is about token flow. Agent traces are dominated by repeated grep calls, file reads and cache writes, and the models that would benefit from that context carry explicit prices per million input and output tokens on their developer documentation. Imprecise retrieval therefore converts directly into spend.

A curated index looks different from a search hit. Gupta describes cataloging the codebase by function and storing, for each area, how it works, its flows, a diagram of those flows and every file involved. Auth bypass detection is his example: deciding whether a code path is privileged requires knowing the surrounding system, not reading one diff.

Autonomous Testing and the Production-Stack Sandbox

Autonomous testing runs the built application in a dependency-rich sandbox and has a vision-capable agent click through real user flows, which catches defects that reading the diff cannot reveal. Gupta's example is React code that looks correct in review yet renders a button hidden on an iPhone.

The prerequisites are harder than the model work. You need a reproducible dev box, pull-request branch dependencies installed so the app actually starts, and a documented map of application flows such as sign-up and sign-in. Gupta says a team of forward-deployed engineers helps Greptile customers with exactly this step, and calls it one of the trickier parts of the build.

He also argues vision models have improved enough that end-to-end QA is close to solved for teams that invest in this setup. That is a claim about the current generation of commercial models, and it depends on the sandbox and flow map existing first.

Route Cheap Models to the Long Tail of Subtasks

Routing cheaper models to non-critical subtasks is how a working review agent becomes affordable, because most tokens go to exploration rather than judgment. Gupta describes Greptile's current split as about 20% frontier-model calls for the critical tasks, with smaller models handling the rest.

The allocation he sketches is a useful default. A small model gathers context, a lightweight computer-use model exercises user flows, and a frontier model analyzes bugs and writes the first submission. Greptile operates about 20 distinct subtasks, each with its own model choices, maintained by a small research team.

Gupta estimates that a straightforward version of this routing captures 70% to 80% of the benefit. The risk is measurement: without the incident dataset from earlier, swapping in a weaker subagent degrades recall silently until something breaks in production.

A cheap model can also act as a reranker, deciding which retrieved context belongs in the expensive model's window. Gupta mentions the Decisions API as a possible place to run that selection step.

What a Build-Your-Own Agent Will Still Miss

A self-built AI code review agent can reach useful quality on internal code, but it inherits limits that come from data scale and from the pace of change in coding models. Gupta is explicit that Greptile's own advantage rests on testing across a very large cross-company corpus.

The comparison is unflattering to both sides in different ways.

ApproachTypical cost per PREvaluation signalMain weakness
Naive agent$3–$25 (reported)NoneMissed bugs, nitpicks
In-house, tunedLower after routingInternal incident PRsNarrow defect coverage
Vendor review agentVendor-setCross-company corpusLess tailored to your stack

Gupta's own recommendation is to buy when the problem is ordinary and build when needs are specialized enough that no vendor fits. That advice comes from someone selling the alternative, which is worth weighing, but the failure modes he describes are reproducible in any test harness.

Brazilian readers who want a structured path through the supporting stack, from TypeScript to the tooling around it, can look at Crazystack TypeScript and the Bootcamp do Dev Doido, both run out of the same Crazystack platform.

Frequently Asked Questions

  • How much does it cost to run an AI code review agent per pull request?

Gupta reports that teams running naive review agents spend about $3 to $25 per pull request, and that even a tuned setup can sit in the $3 to $20 range before model routing. Substituting smaller models for context gathering and file reads is the main lever on that figure.

  • Why does reviewing code with a different model catch more bugs?

Gupta argues that a model fails in the same patterns during review as during generation, so a same-model loop has blind spots. He reports that inverting the model raises the catch rate by about 10%, a figure measured by Greptile rather than by an independent study.

  • Can grep replace a codebase index for review agents?

Gupta says no, on two grounds: text search is imprecise about how code connects, and repeated file reads dominate token spend in agent traces. A curated index that maps each subsystem, its flows and its files gives the reviewer more targeted evidence per token.

  • How do you evaluate a review agent when bugs are rare?

Replay historical pull requests that caused incidents and measure how often each agent version flags the known defect. Gupta estimates catastrophic bugs appear in roughly one in a thousand pull requests, so a live QA process alone will not surface a recall regression fast enough.

  • Do you need computer vision to test pull requests end to end?

Vision-capable models let an agent click through the running app and notice problems that a diff review misses, such as a control hidden on a phone. The harder prerequisites are a reproducible dev box, installed branch dependencies and a documented flow map.

Turn This Talk Into Your Own Written Playbook

The review agent problem is a knowledge problem: incident catalogs, prompt definitions and codebase maps are things engineers carry in their heads and rarely write down. If your team has recorded talks, interviews or internal walkthroughs covering this kind of material, the same gap applies there.

Skala Blog takes a YouTube URL, transcribes the video and produces a structured article draft you can edit before publishing. That covers the step from spoken explanation to something searchable and quotable.

Source video