Skip to content
Completion depends on the acceptance rate; review depends on the miss rate

Completion depends on the acceptance rate; review depends on the miss rate

Adding “automatic pre-commit review” to a coding assistant is most commonly done by taking the completion model and swapping in a new prompt. After running it in production for a while, most of the comment list is naming-style and blank-line suggestions, and the one null pointer that would actually take down the service was never raised once. The team’s first reaction is that the prompt is badly written; they revise it a few times, the style nitpicking drops, and the misses don’t decrease at all.

The problem isn’t the prompt. Completion and review both look like “processing code,” but they’re actually two tasks in opposite directions: one samples in a space with countless correct answers, the other makes a verdict in a space with only “pass” and “fail.” Treating them as the same capability and measuring them with the same metrics is the root cause of why this kind of feature never gets deep.

The inputs and outputs of the two tasks are further apart than you’d think

The typical shape of completion: a few thousand tokens before the cursor, a short stretch after it, occasionally a bit of cross-file context, output of a few dozen tokens. The user presses Tab to accept, and it disappears if they don’t. In this interaction errors are reversible, and the cost of reverting is near zero, so the completion model can guess boldly—the worst cost of a wrong guess is one more Esc press.

Review isn’t like that. The input is a diff, plus the callers of the changed function, type definitions, and related tests. The output has to contain three things: whether this change has a problem, which line the problem is on, and how severe it is. The user won’t verify immediately—especially when the problem is a concurrency race or a boundary condition, verification waits until production. Errors also can’t be reverted; rolling back after the code has merged into main costs hundreds of times what completion does.

Dimension Completion Review
Training signal Unlabeled code, self-supervised Defect, fix, comment triples
Output space Open, many correct ways to write it Converged, verdict plus localization
Latency budget Hundreds of milliseconds Minutes, can be async
Cost of error User doesn’t accept Rollback after entering main
Primary metrics Acceptance rate, retention Miss rate, false-positive rate, usefulness rate

The latency row is often ignored. Completion requires a result within hundreds of milliseconds; review runs asynchronously when a PR is submitted, and a few minutes is acceptable. This gap means the two shouldn’t share the same deployment at all: completion uses a small model plus local caching, review uses a larger model plus cross-file retrieval—a far more reasonable configuration.

flowchart LR
    subgraph A[补全链路]
        direction LR
        A1[光标前后文] --> A2[小模型 低延迟]
        A2 --> A3[接受率与留存]
    end
    subgraph B[评审链路]
        direction LR
        B1[diff 与跨文件上下文] --> B2[大模型 异步运行]
        B2 --> B3[漏报率误报率有用率]
    end

Generation prefers common patterns, and defects hide precisely in common patterns

This is the most concrete layer of “generation-discrimination asymmetry.”

Autoregressive models optimize likelihood; they give high scores to code that “reads naturally.” And a large share of real defects are precisely the boundary failures of the most common patterns: a loop that runs one time too few, a collection that might be empty, an exception swallowed by a broad catch, a time zone not considered, a double-checked lock missing volatile. This code is utterly normal in syntax and style, and the model assigns it high probability because that’s how it’s written in the training set.

So using the completion model’s token logprob to score code often points in the wrong direction. A common approach is to treat each line’s average log probability as a risk score—the lower, the more suspicious. What comes out is a red flag on oddly formatted but logically correct code, and a green light all the way for the neatly written passage that just missed a null check. The correlation with human judgment basically doesn’t line up.

What a discriminative model needs is called calibration: when it says “there’s a 70% chance this is a problem,” it should actually be 70%. This requires dedicated training signals, usually data like “point out the problem, give a fix, verify the fix with tests,” not predicting the next token. Having the model write a fix first and then judge generally yields higher recall than having it judge directly, at the cost of an extra round of generation and a few hundred milliseconds to a few seconds of latency. Review is async, so I’d rather pay that cost.

Review data costs an order of magnitude more than completion data

Completion’s training data is free: open-source code, internal repos, poke a hole and you can train. Review has no such convenience; it needs triples like (defective code, defect location, correct version).

In reality there are only two kinds of sources available. One is review comments on PRs, with line numbers and reasons—high quality but sparse, and carrying strong individual reviewer preferences; some love to nitpick naming, others only look at logic. The other is the few lines in the same file that get fixed by a follow-up commit shortly after merge—weak labeling, cheap, large volume, but noisy: refactors, requirement changes, and formatting all get counted in.

Both kinds of data share a trap: treating “merged” as “defect-free.” A PR being merged doesn’t mean it has no problems, only that nobody caught them. If you use merge records as negatives, the model learns “code nobody commented on is clean,” and what gets missed is precisely the part nobody caught. This bias reinforces itself: the weaker the model, the dirtier the negatives; the dirtier the negatives, the weaker the model.

The scale threshold for human labeling is roughly a few hundred examples to see a trend; to compare two models’ relative performance, anything under a few thousand is unreliable. When the gap is within five points, suspect labeling consistency first—don’t rush to swap models.

A minimal usable eval set looks like this:

YAML7 lines
1
2
3
4
5
6
7
cases:
- id: pr-1043-null-check
expect: { verdict: block, lines: [42, 43], severity: major }
- id: pr-1102-clean-refactor
expect: { verdict: pass, false_positive: 0 }
- id: pr-1108-style-only
expect: { verdict: pass, note: 只允许 nit 级 }

The third kind of sample is the easiest to overlook. Testing only with “PRs that have bugs” is like examining only half the material.

Test only recall, and the model quickly learns to report everything

This is the most typical way a review model degrades, and it looks beautiful on the metrics.

If you only count “how many injected defects were caught,” a model that says “there’s a problem here” every time gets near-perfect recall. Its false-positive rate is likewise 100%, but the dashboard only shows recall.

So evaluation must be paired: recall on injected defects, plus the number of false positives on clean PRs. For the latter I’d recommend “average false positives per PR”—more intuitive than a percentage, because what developers perceive in the product is “this feature picks three faults every single time.” Three is roughly the threshold where it gets turned off.

Localization must be tested separately. A model that only judges “this PR has a problem” but can’t point to a line is nearly useless in the product—developers need to jump over and look. Localization can be measured as “whether it hits within N lines of the changed line,” with N anywhere from 3 to 5 depending on the diff size distribution.

Severity must also be scored separately. Mixing nits and blockers into one accuracy number is fooling yourself: when the model downgrades a blocker to a nit, you lose an interception; when it upgrades a nit to a blocker, you lose trust. These two kinds of error are not the same thing in the product.

The only meaningful online metric is the share of comments that get adopted and actually change the code. Not the comment count—comment count only reflects how talkative it is.

What rules can test, don’t hand to the model

This boundary affects the experience more than model selection does.

Null pointers, unreleased resources, type mismatches, obvious out-of-bounds—anything static analysis and type checking can cover, hand to rules. Rules are cheap, deterministic, zero false positives, and explain themselves clearly. The model’s strength is where rules can’t be written: names that don’t match semantics, whether the error-handling strategy is reasonable, whether this abstraction is redundant, comments that don’t match the implementation, this change conflicting with the conventions of surrounding modules.

My judgment is that the review model should be positioned as “a senior engineer’s second pass,” not a gatekeeper. The gatekeeper is CI. Making it the gatekeeper means handing irreversible errors to a probabilistic system.

Architectural questions—such as whether a module should exist at all, or whether a dependency direction is correct—are ones current models basically cannot judge usefully; forcing them just produces noise. I haven’t seen a reliable approach for this part, so I’d rather leave it blank.

The same base model works, but evaluation cannot be shared

Back to the original question: are these two capabilities?

My answer: the capabilities overlap, but evaluation must be separate. The same base model can do both, but post-training data, context assembly, thresholds, and metrics—all four must be separated.

Context assembly carries more weight than many people assume. Review requires cross-file recall of callers and type definitions; if that part is done poorly, swapping in a stronger model won’t make up for it. Completion requires low latency and local caching, and has little to do with retrieval. The bottlenecks of the two pipelines lie in different places, so comparing their model versions with a single score is meaningless to begin with.

One criterion can decide whether a feature needs its own evaluation:

  • Whether the output space is convergent—a verdict plus location, or free text
  • Whether errors are retractable—the user declines to accept, or it lands in main and must be rolled back
  • Whether there are verifiable feedback labels, such as PR comments or follow-up fix commits

If all three point to the discriminative side, build a separate evaluation set and don’t use completion’s acceptance rate as a proxy metric.

Next time you upgrade the model, run the review evaluation set first before deciding whether to switch. The two curves often diverge: completion gains a few points while review doesn’t move at all, or false positives increase because the new model is more “willing to write.”

About this Post

This post is written by Lu's Blog, licensed under CC BY-NC 4.0.

#Code Review #Generation and Discrimination #Model Evaluation

Comments