Someone on Hacker News described a review tool that cuts a diff into fragments and regroups them by execution path, so the reviewer reads a change in the order the code runs instead of the order the files sort in. It sounded like something my coding-agent review setup was missing, so I spent a session checking whether it would have found anything in the history of an iOS app I'm building (SwiftUI, with TCA for state). Mostly it wouldn't have, but one question that came out of it pointed straight at a bug review had missed, and that question fits in a single instruction for a reviewer.
How the reviewers read a diff today
I started out assuming the review skills read a change file by file, which is the thing regrouping is supposed to fix, but every reviewer agent (lint, approach, quality, security, state and lifecycle, and so on) gets the whole diff, split by concern rather than by file, and the diff is cut into areas only when it's too large for one pass. What none of them do is put code outside the diff in front of the reviewer when that code sits on a path the diff changes, like the code that sends an action into a reducer arm the diff edits, or the implementation behind a dependency the diff calls.
The bug to test it against
To judge an idea like this you need a bug that review missed and that a path-shaped view would plausibly have shown. Out of about 60 fix commits since August, the clearest one came from a refactor that split the app's dashboard screen into smaller features. During review, a broad card prune that was dropping valid dashboard cards got removed, and a narrower one replaced it, which pruned a single item's cards when that item was deleted. The new prune was routed through this arm of the app-level reducer:
case let .list(.itemDeleted(itemId)):
return .send(.dashboard(.itemRemoved(itemId)))
Read on its own, that hunk is fine, but nothing in production sent ListFeature.Action.itemDeleted anymore. An earlier refactor had removed its last sender four months before, so the arm was already dead when the prune landed in it, and deleting an item simply left its cards on the dashboard. The test for the change sent .itemRemoved straight to the dashboard feature's own test store, never going through the app-level arm, so it passed, and it kept passing for the four and a half months after the change landed, until an unrelated fix to the list's download requests noticed that itemDeleted "had no sender" and wired it up again.
Trying to derive the paths mechanically
The first attempt was the cheap one, grepping the action names that appear on the changed lines and listing their senders. It missed the bug completely, because the changed line sits inside an unchanged arm, so itemDeleted never appears on a + or - line. It would have been misleading anyway, since itemDeleted is a case in two different enums, and the other one (a delegate action with a different payload) does have a live sender, so a grep would have said "sent, fine".
The second attempt was a small Python script that builds one record per path, which the clustering would later group. It starts from each changed line, finds the reducer arm the line sits in (marking the arm as touched even when only a line inside it changed), qualifies the action by its parent chain (.list(.itemDeleted) rather than a bare itemDeleted), follows case x(XFeature.Action) declarations to resolve the child, and then searches the repository for production senders and handlers. On the refactor PR it raised one flag, and it was the real bug.
.list(.itemDeleted) touched-by=['in-arm'] <-- HANDLED, NO PRODUCTION SENDER
That looks promising until you run it over other PRs. Across 14 merged ones it raised 100 flags, and of 15 triaged by hand from four small PRs, 2 were real (both actions that are handled and tested but never sent by any production code), so about 13% precision. The false positives came from case names shared with plain value enums (.draft, .archived, .none), sends to child features written as .element(id:action:), actions the framework sends by itself (like .dismiss through @Presents), sends through a scoped store or a ternary, and arms that match several patterns (case .a, .b:). Most of those are syntax problems a proper Swift syntax tree would fix, while shared names need real type resolution, which means the compiler's index rather than text matching.
Grouping those records into clusters, which is the part the HN comment was about, was the weakest step of all. Connecting files that share an action path produced blobs, and for the refactor PR one group pulled in 16 unrelated files from outside the diff because they shared a common action name like openDetail.
A second bug the grouping couldn't reach
The other replayed bug was a double-tap race on a screen's close button. The view sent .minimize without awaiting it, and the reducer's .minimize arm kept no in-flight state, so two taps started two hand-offs of the same object into a session actor. The session declined the older hand-off, and that hand-off's cleanup then cleared the object the newer one had just handed over. The grouping put the view and the reducer together and printed both senders side by side, one awaited and one not, but those were in one hunk of one file, which file order already shows. What made two hand-offs destroy each other lived in the session actor in another layer, reached through a dependency call, and action grouping doesn't follow dependency edges at all. The few other fixes in the sample were the same kind (a race across a dependency boundary, or ordering between SwiftUI teardown and an effect, where nothing static links the two sides).
One instruction instead of a tool
So the regrouping wasn't worth building, but the question behind the one hit was. For each changed line, who in production sends input to the handler it sits in? Asking it by hand of the refactor's diff leads straight to the dead arm, and it fits into one more line in the brief of the reviewer agent that already looks for states that are checked but never set.
The first version of that line said, roughly, find the production senders of any handler a changed line sits in, and read the implementation behind each dependency it calls. Reviewer agents looking at it found a P1 in the one-liner itself. "Read the implementation behind each dependency" has no depth limit, on a reviewer that runs on every diff, so it could walk the whole program. It also had no step in the reviewer's procedure that would reach it (the steps all started from state-carrying types in the diff, so a handler whose own line didn't change was never visited), and the only output template needed a flow that triggers the bug, which an unreachable handler doesn't have.
The revised version bounds the walk.
- Take the innermost dispatch point the changed line sits in (an enum arm, a message or notification handler, a listener), even when that point's own line is unchanged.
- Stop at the first production sender, counting dispatch the framework or runtime does as production, and not counting tests, previews or debug-only code. When there's no sender this is still a search of the whole repository, so what the rule limits is how far the reviewer walks, not how widely it searches.
- Match a shared name by its owning type, and when no sender can be established either way, report the handler as unverified, not unreachable.
- If the changed line relies on a dependency doing its work, read that dependency's live implementation one level deep, and only to check it isn't a stub or a no-op.
It also got its own step in the procedure and its own output entry, with a severity rule (P1 when the changed line is what the change exists to do, P2 otherwise or when unverified). The race from the second bug stays out of its reach on purpose, since one level down only checks for a stub, and finding actions that nothing sends across the whole program is a job for a periodic sweep over the code, tests included, rather than for a reviewer reading one diff.
Replaying the idea before building it
Regrouping a diff by execution path sounds like it should find more bugs, and against real history it mostly reordered things the reviewer could already see. The useful part was a narrower question about one edge of the path, which needed a reviewer instruction rather than a tool, and that only showed up because the idea got replayed against a bug review was already known to have missed, before anything was built. If you're weighing a review tool like this, that replay is cheap and tells you more than the pitch does. I haven't replayed the instruction itself against that refactor yet, so for now I'm treating it as a likely catch rather than a proven one, and the part of it I'd keep in any version is the set of bounds on how far the reviewer goes.
Top comments (0)