Skip to main content
3Nsofts logo3Nsofts
Engineering Process

Before You Trust a Code Risk Score, Compare It with Diff Size

Use a simple baseline, point-in-time replay, repository-balanced sampling and held-out comparisons before turning code history into a predictive review score.

By Ehsan Azish · 3NSOFTS··8 min read

A code review tool can produce a convincing list of risky files without demonstrating that its ordering helps a reviewer. Before adding that score to a team's workflow, ask whether it improves on sorting changed files by size.

This article is for engineers evaluating a review-prioritization system. The goal is a comparison that can reject a product claim. Devscope's published negative result supplies a worked example.

Contents

Define the review decision

Start with the action the ranking is meant to influence. “Review three files first” is concrete. “Understand code quality” leaves the target ambiguous.

Then define the outcome. A later fix blaming a changed file is an observable proxy, with limitations. Fix-message classification and blame attribution can miss relevant defects or implicate lines for reasons unrelated to the original defect. Fixes that never appear in the repository are absent from the label set.

If you use a future observation window, distinguish a file that has completed the window without a labelled fix from one that has not had enough follow-up. A short observation window can turn unknown outcomes into apparent negatives.

Write these decisions down before inspecting the model's result. The Devscope methodology separates time-bounded features from later labels and records a final retest protocol. Reviewed methodology

Start with a baseline you might actually use

Diff size is a useful baseline because it is cheap, available at review time, and easy to explain. Your candidate must beat a meaningful alternative to justify its complexity.

Keep the candidate and baseline paired. For each eligible review unit, rank the same changed files and score both rankings against the same labels. Resolve ties deterministically. A candidate tested on one set of changes and a baseline tested on another creates a comparison that is difficult to interpret.

File-level Recall@3 measures how many labelled files are found among the first three, divided by the number of labelled files in that unit. If a unit has two labelled files and the top three include one, Recall@3 is 0.5. State how you handle units with no labelled files and units with three or fewer candidates.

This metric measures one review budget. It does not measure the time needed to read the selected files, the severity of the defect, or whether the reviewer would notice it. Effort-aware measures can complement it, but define which measure controls your product decision.

Reconstruct what was known at the time

A history feature can leak future evidence even when the model code never explicitly reads a “future” column.

Examples include a fix database built through today's date, ownership computed from the complete history, or co-change pairs calculated using commits that landed after the review unit. A historical replay must give each feature a clear cutoff.

For merged work, author timestamps can be misleading. A commit may have been written before it became visible on the target branch. Use the protocol's landing-time definition consistently. A strict cutoff also keeps the target change from contributing to its own historical features.

A review record should make these fields inspectable:

repository revision and review unit
target landing time / feature cutoff
candidate changed-file set
history-index revision and feature version
later-label observation window
candidate ranking and baseline ranking
paired metric values

Pinning a repository name alone is insufficient. Preserve revisions, sampling rules and raw paired units so that a rerun can answer the same question.

Keep repositories from dominating the sample

A large repository can contribute most of the available changes. A model that does well there may look broadly useful even when other repositories contribute very little evidence.

Devscope's final comparison capped each repository at 40 sampled units. It held ten repositories out of fitting, with seven yielding eligible units. In the held-out evaluation, one large repository had 811 eligible units but contributed only its capped 40. Published final result

A cap is a design choice, not a universal solution. Report how many repositories and units remain, and distinguish a repository-balanced estimate from a pooled unit average. Holding out entire repositories tests transfer to unfamiliar projects more directly than randomly splitting changes from the same project.

Read the interval and the gate together

Devscope's held-out repository-balanced difference in file-level Recall@3 was +0.0032. Its 95% interval was −0.0370 to +0.0512. The predefined gate required the entire interval to be above zero, so the gate failed.

That result did not establish an advantage. It also did not establish equivalence. The interval still contains both a decrease and an increase. Avoid turning an inconclusive superiority test into a universal conclusion that history has no value.

The full paired sample gave additional context: 1,060 units across 44 repositories, with 50 wins, 936 ties and 74 losses. Mean Recall@3 was approximately 0.668 for the candidate and 0.679 for size-only. These full-sample averages answer a different question from the held-out repository-balanced primary comparison.

The published protocol used repository-stratified paired bootstrapping. Preserve the pairing during resampling and account for repository grouping rather than treating every change as independent. Preselecting the gate helps prevent switching to whichever metric looks favorable after the run. Methodology and raw artifacts

Separate co-change from causation

Two files often changing together is a historical fact worth inspecting. It does not by itself show that changing one without the other creates a defect.

The developers may have changed both files because the work was larger. A frequently changed partner may have more opportunities to appear in future fixes. Comparing omitted-partner and included-partner groups without accounting for those differences does not isolate an omission's effect.

Devscope's separate co-change check did not support the proposed warning. The product now presents the relationship neutrally and asks an agent whether that context matters. This preserves the inspectable fact without giving it an unsupported predictive interpretation.

Decide what to ship

Treat a failed gate as a product input. You may still have a useful history browser, review checklist, coverage importer or report exporter. Describe those functions in terms a user can verify.

For Devscope, predictive ranking and the legacy risk tool were removed. Local MCP tools expose change context, fixes, ownership, co-change history and import blast radius. Coverage is imported evidence for the asserted revision; test-file counts are a separate observation.

Before adopting a code risk score, check:

  • Does it beat a simple paired baseline on the task you care about?
  • Were all features available at the historical decision time?
  • Were repositories held out, and is sample concentration reported?
  • Are label uncertainty, follow-up windows and eligibility rules explicit?
  • Was the metric and success gate fixed before viewing results?
  • Can you inspect the raw paired data and reproduce the summary?
  • Does the product's wording stay within that result?

The Devscope case study explains the engineering work and resulting product changes. The product page shows the current workflows.

References

Authoritative References