Agent-Assisted Code Review · ~7 min
A raw diff is a flat wall of hunks. Label each one by what it touches, and review attention flows to where structure says it matters.
Tiered review (last lesson) routes whole PRs by risk. This lesson goes one level finer: it routes hunks. A two-stage LLM pipeline assigns each hunk a change type, then resolves how the hunks relate to one another — turning a flat patch into a labeled structure you can prioritize.
Structure-aware diff labeling assigns a change type to each hunk in a patch. The paper behind this pattern uses a fixed 12-type taxonomy — documentation, testing, output handling, retype, code move, style change, logging, rename, error handling, logic change, internal interface change, external interface change.
The labeler runs per-hunk, few-shot, against that fixed label set, giving each hunk roughly 5 lines of local context. Three modes — per-hunk, per-file, per-patch — trade context length for token cost. Because it is few-shot rather than AST-based, one prompt classifies Java and Python diffs with comparable accuracy: the legitimate win is polyglot coverage and a taxonomy you can extend without rewriting per-language rules.
A per-hunk labeler can name change types but cannot link them. Four hunks each labeled rename is far less
useful than knowing they all consume one renamed declaration. That linkage only exists in the whole-patch view.
So Stage 2 is the Refiner: a single whole-patch inference that captures cross-hunk relationships. It
assigns a parent field (parent=0 for the declaration, parent=N for usages),
extracts attributes like old/new names and types, and corrects misclassifications only visible across the full patch.
This is an LLM classifier, and it is qualified. Performance varies substantially across label types, and the trade is determinism and cost for coverage and customizability.
| Legitimate win | Legitimate trade-off |
|---|---|
| Polyglot — one prompt, many languages | Non-deterministic output (~84% recall / 81% precision) |
| Extend the taxonomy with few-shot, no retraining | Per-category accuracy is uneven |
| No per-language AST tooling to maintain | Whole-patch Refiner blows out on very large diffs |
Under-represented labels — external interface, error handling, logging — score worse than rename or logic-change. A workflow that depends on exactly those categories is precisely where the paper recommends a hybrid: LLM labeling for most types, deterministic static analysis (a RefactoringMiner-class tool) for the few critical ones. Treat the labeler as a supplement, not a replacement.
Cost is non-uniform too: the best model in the benchmark (Gemini-3-Pro-Preview) consumed up to 7.5× the output tokens of the second-best (Claude Sonnet 4.5). Skip the whole approach when a single-language project already has mature static tooling, when CI demands deterministic audit trails, or when per-PR token cost dominates the budget.
Retrieval practice — recall, don't peek
Question 1Structure-aware diff labeling assigns a change type to each…
Question 2The Refiner stage exists primarily to…
Question 3The legitimate wins of the LLM labeler over per-language static analysis are…
Question 4For the critical, weakest-scoring label types, the paper recommends…
Question 5 · spaced recall from an earlier lessonIn tiered review, you set review depth by…