Surgical Code Review for Agents
Uniform whole-branch code review wastes most of an agent's context window on CSS and already-verified tests. Deterministic, fail-closed per-file triage cuts review cost by 41.4% while preserving defect recall.
Whole-branch code review is one of the highest-leverage safeguards in an automated software pipeline. It catches the bugs that local unit tests miss: cross-file integration seams, broken authentication guards, subtle contract drift, and unreviewed edits introduced during late-stage repairs.
The problem is how most agent review stages allocate attention.
Under a uniform reading rule—inspect every changed hunk of every non-generated file—large UI branches create a structural mismatch. On an 18-file or 35-file interface redesign, pure styling, layout markup, and already-reviewed test files consume the bulk of the model's reading budget. Past 30 files or 8,000 lines, our runtime had to split the review into multiple parallel slice sessions plus a full synthesis pass. The reviewer spent most of its context window re-reading Tailwind classes instead of interrogating the two files that actually touched money or permissions.
Deterministic Triage Before the Model Wakes Up
To fix this without weakening verification, we inserted a zero-LLM, deterministic classifier ahead of the final reviewer. Before a single token is spent, final-review-triage sorts every changed path between base and HEAD into one of six modes:
fullandhunks(kept inreviewed_paths): Sensitive paths (auth, tenant, schema, secrets), sensitive diff patterns (dangerouslySetInnerHTML,eval, SQL), exported contract changes, cross-step seams, UI components containing hidden logic (hooks,fetch, storage, inline handlers), and any file whose git blob SHA drifted after an accepted step review.visual-covered(delegated tocovered_by): Pure presentation or CSS files with zero hidden-logic signals and fresh, passing visual parity evidence matchingHEAD.step-verified(delegated tocovered_by): Low-risk tests, styles, or docs whose exact git blob SHA atHEADmatches an accepted step review.mechanicalandgenerated: PureR100renames, safe whitespace-only diffs, and build artifacts.
The critical safeguard is fail-closed one-way escalation. Every path still requires 100% pairwise-disjoint accounting in the final receipt. The reviewer is free to escalate any delegated file into full inspection if a seam points there, but the runtime runs the triage classifier itself and rejects any attempt to demote a flagged full or hunks file into covered_by.
What the Benchmark Showed
We evaluated surgical triage against uniform whole-branch review across 18 sandboxed runs (three scenarios, three repeats per arm, interleaved on deepseek-flash). Each scenario was an 18-file UI redesign mixing CSS, presentation components, step-reviewed tests, and targeted risk surfaces.
| Metric (9 Paired Runs) | Uniform Baseline | Surgical Triage | Delta |
|---|---|---|---|
| Audited delivery rate | 9/9 | 9/9 | 0.0% |
| Total cost (USD) | $0.3137 | $0.1838 | -41.4% |
| p50 wall time | 116.72s | 95.77s | -17.9% |
| Model calls per cell (mean) | 23.44 | 17.44 | -25.6% |
| Output tokens per cell (p50) | 14,163 | 9,852 | -30.4% |
| Mean files read by LLM | 17.1 / 18 | 1.67 / 18 | -90.2% |
Defect detection did not degrade; if anything, focus improved. On a billing redesign hiding stored XSS (dangerouslySetInnerHTML) inside a React component and an || vs. && privilege-escalation bug in billingGuard.ts, surgical triage caught both defects three out of three times and surfaced slightly more concrete issues (4.7 vs. 4.0 mean findings). On a settings redesign with an unreviewed post-step commit that dropped confirmationToken validation, blob-SHA drift flagged the regression deterministically while cutting cost by 49.7% and tool calls by 50.4%. On a clean onboarding refresh, it produced zero false positives and cut cost by 42.8%.
A dry run against five real merged Phoenix LiveView pull requests confirmed the production upside: zero-LLM triage delegated 31% to 84% of diff lines while keeping 100% of authentication, LiveView, and router code under full review. On a 35-file workbench PR, delegating seven verified files brought the active review set down to 28 paths—eliminating multi-slice overhead entirely.
Good review is not about reading every line equally. It is about using deterministic proof to clear the noise so the model's full attention lands where bugs actually hide.
Join the PathGuided Closed Beta
Onboard your repositories with local-to-cloud spec execution, split-tier model routing, and commit-bound Work Tours.