Evaluating Code Review and Bug Localization Quality in LLM Agents
Evaluating Code Review and Bug Localization Quality in LLM Agents
Code review is not a single task. It is a bundle of at least five distinct sub-skills: defect detection, root-cause attribution, severity ranking, actionable feedback generation, and non-regression awareness. Most evaluation frameworks for LLM agents collapse these into a single pass/fail signal, which obscures where a model actually fails and why. Evaluating code review and bug localization quality in LLM agents demands a decomposed methodology, a reliable verifier for each sub-task, and empirical difficulty calibration against the models being tested. This post gives you that methodology.
What does evaluating code review and bug localization quality actually measure?
Evaluating code review and bug localization quality in LLM agents measures the precision, recall, and localization accuracy of a model's defect-finding behavior, not merely whether it produces review-shaped text. A model that outputs plausible-sounding feedback without identifying the correct line, function, or causal chain is not performing code review. It is performing code-review mimicry, and the two are easy to conflate when evaluation is shallow.
Answer Capsule: To evaluate code review and bug localization quality in LLM agents, decompose the task into sub-skills (defect detection, localization, severity, explanation), assign a verifiable ground-truth signal to each, and measure precision and recall at the statement or hunk level. Aggregate pass rates mask failure modes that matter for post-training decisions.
How to decompose code review into evaluable sub-tasks
Each sub-task requires its own verifier. Without decomposition, a model that correctly identifies a bug class but localizes it to the wrong function scores identically to a model that gets both right, which produces a misleading aggregate signal.
The five sub-tasks and their verifier types are:
Defect detection: Binary. Does the model flag the seeded or known defect? Verifier: exact match against a ground-truth defect list. Metric: recall at the bug level.
Localization: Ordinal. Does the model identify the correct file, function, and line range? Verifier: overlap coefficient between predicted span and ground-truth span. Metric: token-level or hunk-level F1.
Root-cause attribution: Categorical. Does the model name the correct causal mechanism (e.g., off-by-one, use-after-free, race condition)? Verifier: expert rubric or constrained taxonomy match. Metric: precision over a fixed defect taxonomy.
Severity ranking: Ordinal. Does the model assign a severity consistent with the ground-truth (e.g., CVSS-aligned for security bugs)? Verifier: rank correlation against expert-assigned severity. Metric: Spearman rho.
Feedback actionability: Qualitative. Is the suggested fix correct and non-regressive? Verifier: static analysis or test suite execution on the proposed patch. Metric: patch pass rate against the existing test suite.
Running all five verifiers independently lets you build a failure profile rather than a single score. A model may achieve high defect recall but low localization F1, which indicates it detects bug classes by pattern but cannot pinpoint the responsible code unit. That failure mode has a different remediation path than low recall with high localization precision.
Designing the task corpus: seeded bugs versus real defects
Task corpus design is the most consequential decision in this evaluation. Two approaches exist: seeded bugs in synthetic or modified codebases, and real defects drawn from version-controlled history (e.g., commits that fix a known CVE or a closed issue).
Criterion | Seeded bugs | Real historical defects |
|---|---|---|
Ground-truth verifiability | Exact; you control the defect | Partial; fix commit is ground truth, but may be incomplete |
Contamination risk | Low if tasks are original and unpublished | High; public repos are in pretraining data |
Ecological validity | Depends on seeding realism | High; reflects actual defect distributions |
Difficulty calibration | Controllable by defect class and context size | Uncontrolled; must be post-hoc stratified |
Verifier complexity | Low to medium | Medium to high; requires repo setup and test harness |
For evals intended to track model progress over time, seeded bugs in original, unpublished codebases are preferable. Public defect datasets (e.g., Defects4J, SWE-bench) are valuable for baseline comparisons but carry contamination risk for any model trained after their publication date. For post-training data, real defects with verified fix commits provide higher-fidelity reward signals, provided the verifier can execute the test suite reliably.
The SWE-bench benchmark (Jimenez et al., 2024) operationalizes the real-defect approach at scale, using GitHub issues and their corresponding fix commits as task instances. Its verifier is test-suite execution, which is programmatic and unambiguous. The limitation is that test coverage in the source repos is uneven, so a passing patch may still be semantically incorrect in uncovered paths.
Localization metrics: why hunk-level F1 is the right unit
Localization accuracy should be measured at the diff hunk level, not the file level. File-level localization is too coarse; a model that flags the correct file in a 10,000-line codebase has done almost nothing useful. Line-level localization is too granular for multi-line defects and produces unstable metrics when ground-truth spans vary by one or two lines across annotators.
The recommended unit is the diff hunk: a contiguous block of changed lines as produced by a standard unified diff. Hunk-level F1 is computed as follows:
Precision: (predicted hunks that overlap a ground-truth hunk) / (total predicted hunks)
Recall: (ground-truth hunks overlapped by at least one prediction) / (total ground-truth hunks)
F1: harmonic mean of precision and recall
Overlap is defined as any non-zero intersection of line ranges. A stricter variant requires the predicted hunk to contain the ground-truth hunk entirely, which penalizes over-broad localization. For security-critical evals, the stricter variant is appropriate because an agent that flags an entire module rather than the vulnerable function cannot be trusted to generate a targeted patch.
For error localization in multi-step reasoning traces, the first-wrong-step framework provides a complementary approach. See the post on error localization labeling and first wrong step for how this transfers to process-level annotation.
Worked example: evaluating a bug localization agent on a seeded off-by-one defect
Illustrative example. All code, line numbers and scores are constructed for demonstration.
Consider a Python function that iterates over a list using range(len(items)) but accesses items[i+1] without a bounds check. The seeded defect spans lines 42-44 of processor.py. The ground-truth hunk is three lines.
An LLM agent under evaluation produces the following output: it flags processor.py as the affected file, identifies lines 40-50 as the relevant region, and attributes the defect class as "index out of bounds." It proposes replacing the loop with range(len(items) - 1).
Scoring:
Defect detection recall: 1.0 (the bug is flagged)
Localization hunk F1: Predicted span (40-50, 11 lines) overlaps ground truth (42-44, 3 lines). Overlap = 3 lines. Precision = 3/11 = 0.27. Recall = 3/3 = 1.0. F1 = 0.43. The model found the right area but was imprecise.
Root-cause attribution: Correct (off-by-one / index out of bounds). Score = 1.0.
Patch correctness: The proposed fix is run against the test suite. Two of five tests pass. Score = 0.40. The fix prevents the crash but changes loop semantics, causing two tests to fail.
Aggregate pass/fail would mark this as a success. The decomposed profile reveals a localization precision problem and a patch correctness problem that aggregate scoring hides. This failure profile informs which training signal to prioritize: process reward data for localization, or execution-verified SFT for patch generation.
Common failure modes in code review and bug localization evals
1. Defect class imbalance in the task corpus. If 70% of seeded bugs are null-pointer or off-by-one errors, aggregate recall is dominated by the most common class. Detection: compute recall stratified by defect class. Fix: stratify the corpus by defect class and weight metrics accordingly, or report per-class recall separately.
2. Contamination from public defect datasets. Models trained on data scraped from GitHub will have seen many Defects4J and SWE-bench instances. Detection: measure pass@1 on held-out, original tasks versus public benchmarks; a large gap suggests contamination. Fix: use original, expert-authored tasks that have not been published. Chiron Data Labs builds tasks of this kind to preserve difficulty headroom against frontier models.
3. Verifier brittleness from flaky test suites. Test-suite execution verifiers produce noisy signals when tests are environment-dependent or order-dependent. Detection: run the verifier three times on the same patch and measure variance; variance above 5% indicates flakiness. Fix: isolate tests in a containerized environment with a fixed dependency manifest and a deterministic execution order.
4. Reward hacking on feedback verbosity. When feedback actionability is scored by an LLM judge rather than test execution, verbose but incorrect feedback scores higher than terse but correct feedback. Detection: compare LLM-judge scores to patch pass rates; low correlation indicates judge miscalibration. Fix: anchor the judge rubric to executable criteria, or replace the judge with a programmatic verifier where possible. For more on this failure mode, see the post on evaluating domain-specific reward models with expert judgments.
5. Localization evaluated at file level only. File-level metrics inflate apparent performance. A model that identifies the correct file in a 50-file repo scores 1.0 on file-level recall regardless of whether it can find the responsible function. Detection: compare file-level recall to hunk-level F1; a large gap confirms the problem. Fix: adopt hunk-level F1 as the primary localization metric.
6. No stratification by code context size. Bug localization difficulty scales with context window size and code complexity. A task with a 200-line file is not comparable to one with a 5,000-line file. Detection: plot performance against file length and cyclomatic complexity; if performance degrades monotonically, the eval is measuring context-handling as much as localization. Fix: stratify tasks by context size and report results per stratum.
Where this approach breaks down
Test-suite execution verifiers are only as good as the test suite. In domains with low test coverage, a passing patch may introduce a latent defect in an untested path. This is not a solvable problem within the eval framework itself; it is a property of the codebase. Evals built on such codebases should be treated as lower-confidence signals and supplemented with expert review of proposed patches.
Hunk-level F1 also assumes that defects are spatially contiguous in the diff. Distributed bugs, where the defect involves an interaction between two functions in different files, do not map cleanly to a single hunk. Multi-hunk localization requires a more complex matching algorithm and is an open problem in eval design. For now, distributed bugs should be flagged as a separate task class and scored separately.
Difficulty calibration drifts as models improve. A task corpus that challenges frontier models today may be saturated within six to twelve months. Pass@k against the current frontier is the correct calibration signal, and it must be re-run periodically. Difficulty is a property of the model-task pair, not of the task alone.
FAQ
What is the right sample size for a code review eval?
The minimum sample size depends on the effect size you want to detect and the metric variance. For hunk-level F1, variance is typically high because localization scores are skewed. A practical starting point is 200 task instances per defect class for a 0.05 significance level at 80% power. Fewer tasks are acceptable for exploratory evals, but confidence intervals should be reported explicitly.
Can LLM-as-judge replace test-suite execution for patch correctness?
For patch correctness, no. LLM judges cannot reliably determine whether a patch is semantically correct without executing it. They can evaluate feedback quality and explanation clarity, where execution is not possible. For correctness, use a programmatic verifier: test execution, static analysis, or a symbolic checker. Reserve LLM judges for sub-tasks where no programmatic verifier exists.
How do I handle multi-file bugs in localization evals?
Score multi-file bugs separately from single-file bugs. For multi-file cases, compute hunk-level F1 across all files jointly, treating the union of ground-truth hunks as the positive set. Report multi-file and single-file F1 separately; pooling them obscures the harder sub-task. Multi-file localization is a distinct capability and should be treated as such in task stratification.
Is SWE-bench sufficient for evaluating code review quality?
SWE-bench (Jimenez et al., 2024) evaluates patch generation and test-suite pass rates, not the full code review bundle. It does not measure localization precision, severity ranking, or feedback actionability. It is a strong benchmark for end-to-end agent capability, but it does not decompose failure modes. Use SWE-bench for overall capability tracking and a decomposed eval for post-training signal design.
How do I calibrate task difficulty empirically?
Run pass@k (with k = 1, 5, 10) against two or more frontier models on the candidate task set. Tasks where all models score pass@1 above 0.85 are too easy for eval or training use. Tasks where all models score pass@1 below 0.05 may be unsolvable rather than hard; expert review is needed to distinguish the two. Target the 0.15 to 0.70 pass@1 range for training tasks and 0.05 to 0.50 for evals.
What this means in practice
Evaluating code review and bug localization quality in LLM agents is not a single benchmark run. It is a pipeline: decompose the task, assign a verifier to each sub-task, build a stratified corpus of original tasks, measure hunk-level F1 and per-class recall, and re-calibrate difficulty as frontier models improve. The failure profile that emerges from decomposed scoring is more actionable than any aggregate score, and it is the correct input to post-training decisions about where to invest in new training data or reward signal design.
For teams designing process reward models, the localization sub-task connects directly to step-level annotation. See the post on evaluating PRMs with held-out expert step judgments for how expert-labeled intermediate steps complement execution-based verifiers.
If you are building evals or RL environments for code review, bug localization, or adjacent engineering domains, get in touch with Chiron Data Labs.
Have questions or want personalised guidance? Contact us and we'll be happy to help.
Code review is not a single task. It is a bundle of at least five distinct sub-skills: defect detection, root-cause attribution, severity ranking, actionable feedback generation, and non-regression awareness. Most evaluation frameworks for LLM agents collapse these into a single pass/fail signal, which obscures where a model actually fails and why. Evaluating code review and bug localization quality in LLM agents demands a decomposed methodology, a reliable verifier for each sub-task, and empirical difficulty calibration against the models being tested. This post gives you that methodology.
What does evaluating code review and bug localization quality actually measure?
Evaluating code review and bug localization quality in LLM agents measures the precision, recall, and localization accuracy of a model's defect-finding behavior, not merely whether it produces review-shaped text. A model that outputs plausible-sounding feedback without identifying the correct line, function, or causal chain is not performing code review. It is performing code-review mimicry, and the two are easy to conflate when evaluation is shallow.
Answer Capsule: To evaluate code review and bug localization quality in LLM agents, decompose the task into sub-skills (defect detection, localization, severity, explanation), assign a verifiable ground-truth signal to each, and measure precision and recall at the statement or hunk level. Aggregate pass rates mask failure modes that matter for post-training decisions.
How to decompose code review into evaluable sub-tasks
Each sub-task requires its own verifier. Without decomposition, a model that correctly identifies a bug class but localizes it to the wrong function scores identically to a model that gets both right, which produces a misleading aggregate signal.
The five sub-tasks and their verifier types are:
Defect detection: Binary. Does the model flag the seeded or known defect? Verifier: exact match against a ground-truth defect list. Metric: recall at the bug level.
Localization: Ordinal. Does the model identify the correct file, function, and line range? Verifier: overlap coefficient between predicted span and ground-truth span. Metric: token-level or hunk-level F1.
Root-cause attribution: Categorical. Does the model name the correct causal mechanism (e.g., off-by-one, use-after-free, race condition)? Verifier: expert rubric or constrained taxonomy match. Metric: precision over a fixed defect taxonomy.
Severity ranking: Ordinal. Does the model assign a severity consistent with the ground-truth (e.g., CVSS-aligned for security bugs)? Verifier: rank correlation against expert-assigned severity. Metric: Spearman rho.
Feedback actionability: Qualitative. Is the suggested fix correct and non-regressive? Verifier: static analysis or test suite execution on the proposed patch. Metric: patch pass rate against the existing test suite.
Running all five verifiers independently lets you build a failure profile rather than a single score. A model may achieve high defect recall but low localization F1, which indicates it detects bug classes by pattern but cannot pinpoint the responsible code unit. That failure mode has a different remediation path than low recall with high localization precision.
Designing the task corpus: seeded bugs versus real defects
Task corpus design is the most consequential decision in this evaluation. Two approaches exist: seeded bugs in synthetic or modified codebases, and real defects drawn from version-controlled history (e.g., commits that fix a known CVE or a closed issue).
Criterion | Seeded bugs | Real historical defects |
|---|---|---|
Ground-truth verifiability | Exact; you control the defect | Partial; fix commit is ground truth, but may be incomplete |
Contamination risk | Low if tasks are original and unpublished | High; public repos are in pretraining data |
Ecological validity | Depends on seeding realism | High; reflects actual defect distributions |
Difficulty calibration | Controllable by defect class and context size | Uncontrolled; must be post-hoc stratified |
Verifier complexity | Low to medium | Medium to high; requires repo setup and test harness |
For evals intended to track model progress over time, seeded bugs in original, unpublished codebases are preferable. Public defect datasets (e.g., Defects4J, SWE-bench) are valuable for baseline comparisons but carry contamination risk for any model trained after their publication date. For post-training data, real defects with verified fix commits provide higher-fidelity reward signals, provided the verifier can execute the test suite reliably.
The SWE-bench benchmark (Jimenez et al., 2024) operationalizes the real-defect approach at scale, using GitHub issues and their corresponding fix commits as task instances. Its verifier is test-suite execution, which is programmatic and unambiguous. The limitation is that test coverage in the source repos is uneven, so a passing patch may still be semantically incorrect in uncovered paths.
Localization metrics: why hunk-level F1 is the right unit
Localization accuracy should be measured at the diff hunk level, not the file level. File-level localization is too coarse; a model that flags the correct file in a 10,000-line codebase has done almost nothing useful. Line-level localization is too granular for multi-line defects and produces unstable metrics when ground-truth spans vary by one or two lines across annotators.
The recommended unit is the diff hunk: a contiguous block of changed lines as produced by a standard unified diff. Hunk-level F1 is computed as follows:
Precision: (predicted hunks that overlap a ground-truth hunk) / (total predicted hunks)
Recall: (ground-truth hunks overlapped by at least one prediction) / (total ground-truth hunks)
F1: harmonic mean of precision and recall
Overlap is defined as any non-zero intersection of line ranges. A stricter variant requires the predicted hunk to contain the ground-truth hunk entirely, which penalizes over-broad localization. For security-critical evals, the stricter variant is appropriate because an agent that flags an entire module rather than the vulnerable function cannot be trusted to generate a targeted patch.
For error localization in multi-step reasoning traces, the first-wrong-step framework provides a complementary approach. See the post on error localization labeling and first wrong step for how this transfers to process-level annotation.
Worked example: evaluating a bug localization agent on a seeded off-by-one defect
Illustrative example. All code, line numbers and scores are constructed for demonstration.
Consider a Python function that iterates over a list using range(len(items)) but accesses items[i+1] without a bounds check. The seeded defect spans lines 42-44 of processor.py. The ground-truth hunk is three lines.
An LLM agent under evaluation produces the following output: it flags processor.py as the affected file, identifies lines 40-50 as the relevant region, and attributes the defect class as "index out of bounds." It proposes replacing the loop with range(len(items) - 1).
Scoring:
Defect detection recall: 1.0 (the bug is flagged)
Localization hunk F1: Predicted span (40-50, 11 lines) overlaps ground truth (42-44, 3 lines). Overlap = 3 lines. Precision = 3/11 = 0.27. Recall = 3/3 = 1.0. F1 = 0.43. The model found the right area but was imprecise.
Root-cause attribution: Correct (off-by-one / index out of bounds). Score = 1.0.
Patch correctness: The proposed fix is run against the test suite. Two of five tests pass. Score = 0.40. The fix prevents the crash but changes loop semantics, causing two tests to fail.
Aggregate pass/fail would mark this as a success. The decomposed profile reveals a localization precision problem and a patch correctness problem that aggregate scoring hides. This failure profile informs which training signal to prioritize: process reward data for localization, or execution-verified SFT for patch generation.
Common failure modes in code review and bug localization evals
1. Defect class imbalance in the task corpus. If 70% of seeded bugs are null-pointer or off-by-one errors, aggregate recall is dominated by the most common class. Detection: compute recall stratified by defect class. Fix: stratify the corpus by defect class and weight metrics accordingly, or report per-class recall separately.
2. Contamination from public defect datasets. Models trained on data scraped from GitHub will have seen many Defects4J and SWE-bench instances. Detection: measure pass@1 on held-out, original tasks versus public benchmarks; a large gap suggests contamination. Fix: use original, expert-authored tasks that have not been published. Chiron Data Labs builds tasks of this kind to preserve difficulty headroom against frontier models.
3. Verifier brittleness from flaky test suites. Test-suite execution verifiers produce noisy signals when tests are environment-dependent or order-dependent. Detection: run the verifier three times on the same patch and measure variance; variance above 5% indicates flakiness. Fix: isolate tests in a containerized environment with a fixed dependency manifest and a deterministic execution order.
4. Reward hacking on feedback verbosity. When feedback actionability is scored by an LLM judge rather than test execution, verbose but incorrect feedback scores higher than terse but correct feedback. Detection: compare LLM-judge scores to patch pass rates; low correlation indicates judge miscalibration. Fix: anchor the judge rubric to executable criteria, or replace the judge with a programmatic verifier where possible. For more on this failure mode, see the post on evaluating domain-specific reward models with expert judgments.
5. Localization evaluated at file level only. File-level metrics inflate apparent performance. A model that identifies the correct file in a 50-file repo scores 1.0 on file-level recall regardless of whether it can find the responsible function. Detection: compare file-level recall to hunk-level F1; a large gap confirms the problem. Fix: adopt hunk-level F1 as the primary localization metric.
6. No stratification by code context size. Bug localization difficulty scales with context window size and code complexity. A task with a 200-line file is not comparable to one with a 5,000-line file. Detection: plot performance against file length and cyclomatic complexity; if performance degrades monotonically, the eval is measuring context-handling as much as localization. Fix: stratify tasks by context size and report results per stratum.
Where this approach breaks down
Test-suite execution verifiers are only as good as the test suite. In domains with low test coverage, a passing patch may introduce a latent defect in an untested path. This is not a solvable problem within the eval framework itself; it is a property of the codebase. Evals built on such codebases should be treated as lower-confidence signals and supplemented with expert review of proposed patches.
Hunk-level F1 also assumes that defects are spatially contiguous in the diff. Distributed bugs, where the defect involves an interaction between two functions in different files, do not map cleanly to a single hunk. Multi-hunk localization requires a more complex matching algorithm and is an open problem in eval design. For now, distributed bugs should be flagged as a separate task class and scored separately.
Difficulty calibration drifts as models improve. A task corpus that challenges frontier models today may be saturated within six to twelve months. Pass@k against the current frontier is the correct calibration signal, and it must be re-run periodically. Difficulty is a property of the model-task pair, not of the task alone.
FAQ
What is the right sample size for a code review eval?
The minimum sample size depends on the effect size you want to detect and the metric variance. For hunk-level F1, variance is typically high because localization scores are skewed. A practical starting point is 200 task instances per defect class for a 0.05 significance level at 80% power. Fewer tasks are acceptable for exploratory evals, but confidence intervals should be reported explicitly.
Can LLM-as-judge replace test-suite execution for patch correctness?
For patch correctness, no. LLM judges cannot reliably determine whether a patch is semantically correct without executing it. They can evaluate feedback quality and explanation clarity, where execution is not possible. For correctness, use a programmatic verifier: test execution, static analysis, or a symbolic checker. Reserve LLM judges for sub-tasks where no programmatic verifier exists.
How do I handle multi-file bugs in localization evals?
Score multi-file bugs separately from single-file bugs. For multi-file cases, compute hunk-level F1 across all files jointly, treating the union of ground-truth hunks as the positive set. Report multi-file and single-file F1 separately; pooling them obscures the harder sub-task. Multi-file localization is a distinct capability and should be treated as such in task stratification.
Is SWE-bench sufficient for evaluating code review quality?
SWE-bench (Jimenez et al., 2024) evaluates patch generation and test-suite pass rates, not the full code review bundle. It does not measure localization precision, severity ranking, or feedback actionability. It is a strong benchmark for end-to-end agent capability, but it does not decompose failure modes. Use SWE-bench for overall capability tracking and a decomposed eval for post-training signal design.
How do I calibrate task difficulty empirically?
Run pass@k (with k = 1, 5, 10) against two or more frontier models on the candidate task set. Tasks where all models score pass@1 above 0.85 are too easy for eval or training use. Tasks where all models score pass@1 below 0.05 may be unsolvable rather than hard; expert review is needed to distinguish the two. Target the 0.15 to 0.70 pass@1 range for training tasks and 0.05 to 0.50 for evals.
What this means in practice
Evaluating code review and bug localization quality in LLM agents is not a single benchmark run. It is a pipeline: decompose the task, assign a verifier to each sub-task, build a stratified corpus of original tasks, measure hunk-level F1 and per-class recall, and re-calibrate difficulty as frontier models improve. The failure profile that emerges from decomposed scoring is more actionable than any aggregate score, and it is the correct input to post-training decisions about where to invest in new training data or reward signal design.
For teams designing process reward models, the localization sub-task connects directly to step-level annotation. See the post on evaluating PRMs with held-out expert step judgments for how expert-labeled intermediate steps complement execution-based verifiers.
If you are building evals or RL environments for code review, bug localization, or adjacent engineering domains, get in touch with Chiron Data Labs.
Have questions or want personalised guidance? Contact us and we'll be happy to help.