You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Review: a re-review counts only the pull request's own changes, and re-checks unchanged code cheaply - #241
Two cases made a scoped re-review (#228) fall back to a full, full-price review:
Merge or rebase of main into the PR. The focus was every file that differs between the previously reviewed commit and HEAD, so every PR file main touched in between counted as changed. After a rebase onto a busy main that's often the whole PR.
Nothing changed (a re-run, an empty push, a rebase with no edits). The code is identical, but the review covered the whole change again.
What
Merge-safe focus (review_commit_rescope_base.go). When the base moved between the two commits, each commit is compared with its own merge base. A file is in the focus only if the PR's own change to it differs: its added and removed lines, ignoring position.
Files that changed only because the base moved are left out of the focus and named in a BASE MOVED note, so the reviewer can still look where a base change meets the PR's code.
The commit-to-commit comparison stays in place when there's no base (a single-commit review), the base didn't move, or no merge base can be found.
Nothing-changed path. When nothing the PR changes differs since the previous review:
The focus is the files the earlier points name, or empty (not nil, so it's not a full review).
The budget is 8 turns plus 3 per such file, never above the full review's base of 30, versus 30–72 before.
The prompt says not to review the change again, only to re-check each earlier point.
The sweeps read only those files' hunks, and the second finder inherits the smaller budget.
Tradeoffs
A file the base changed under unchanged PR edits is no longer re-read by default. A base change that semantically breaks the PR's unchanged code relies on the BASE MOVED note.
Binary files compare by their "Binary files … differ" line only.
Tests
go test ./cmd/kai/... passes.
New unit tests cover patch normalisation, the own/base-only split, and the nothing-changed focus, budget and block.
An end-to-end test on a real git repo checks two scenarios: main edits a file the PR also edits and the author merges main in, and a rebase with no edits. Commit to commit reports 3 changed files; this reports only the file the author edited, and none after the rebase.
Note
This touches the same maxTurns lines in review_commit.go as #240, so whichever merges second needs a small conflict fix. The combined rule: recheck budget when unchanged, otherwise the focus budget plus #240's related-file turns.
Written by Kai from the change itself. Kai only edits this section; everything above it is the author's.
A scoped re-review now counts only the pull request's own changes, so a merge or rebase of the base no longer pulls every file main touched into the focus. When nothing the PR changes differs since the previous review, it re-checks the earlier points on a small budget instead of reviewing the whole change again.
Changes
Merge-safe comparison (new review_commit_rescope_base.go): when the base moved, rcComputeSince compares each commit with its own merge base. rcPatchByFile normalises the per-file patch (added and removed lines, new/deleted file, mode lines, binary line; no hunk positions or blob ids), and rcSplitPRChanges splits files into the PR's own changes and base-only ones. The commit-to-commit diff stays when there is no base, the base did not move, or no merge base is found. rcChangedSinceFn now defaults to rcGitPRChangedSince.
Per-review memo:rcSince works out each previous commit's comparison once per previous commit, HEAD and base, and keeps the focus, base-only files, and the PR's files then and now.
Git diff handling:
Diffs use core.quotePath=false.
rcGitPatchByFile stops git when a patch is over rcPatchLimit, rather than waiting out the 30 s deadline.
rcGitChangedSince now goes through rcGitNames, which lists a rename as both paths.
Path spelling:rcPRFiles maps unquoted paths to the spelling of the --numstat list, which quotes non-ASCII names and gives a rename only its old path. rcPRFileCount counts files the same way, so a rename counts once against the PR's size.
Nothing-changed path (review_commit_rescope.go): rcReReviewFocus returns an empty, non-nil focus (the earlier points' files) when nothing the PR changes differs. It stays a re-check even if the points name every file of a small PR. A change taken back out of the PR (rcDroppedSince) is not treated as unchanged and leads to a full review.
Re-check budget and prompt:rcReReviewUnchanged decides the mode. rcReCheckTurns gives 8 turns plus 3 per point file, capped at 30. rcReCheckBlock tells the reviewer not to review the change again and only to re-check each earlier point.
BASE MOVED note:rcBaseMovedBlock names base-only files outside the focus. rcBaseOnlyOutsideFocus is shared with rcReCheckBlock. The "not in the focus" sentence is dropped on a whole-change review, and files an earlier point added to the focus are not listed.
Wiring (review_commit.go): rcRunReviewAgent picks maxTurns from the re-check budget or the normal one, writes the re-check or focus block plus the BASE MOVED block, and passes maxTurns to the agent config.
The rcReReviewFocus whole-change test no longer lists "nothing changed since", which is now a re-check.
Testing
go test ./cmd/kai/... passes.
Unit tests cover patch normalisation (position-independence, header-like body lines, mode changes), the own/base-only split, the nothing-changed focus, rcReReviewUnchanged, the re-check turns and block, and a dropped change.
Real-git tests cover:
a merge of main and a rebase with no edits;
a reverted file, a non-ASCII filename, and a mode-only change;
quoted and renamed paths, and a rename counting once;
…e-checks unchanged code cheaply
Two cases where a scoped re-review fell back to a full one.
After a merge of main into the pull request, or a rebase onto it, the
focus (files changed since the previous review's commit) counted every
pull-request file main had touched in between, often the whole pull
request. When the base moved, each commit is now compared with its own
merge base, and a file is in the focus only if the pull request's own
change to it (its added and removed lines, ignoring position) differs.
Files that changed only because the base moved are named to the reviewer
in a BASE MOVED note, outside the focus. With no base (a single-commit
review), an unmoved base, or no merge base, the commit-to-commit
comparison stands.
When nothing the pull request changes differs since the previous review
(a re-run, an empty push, a rebase with no edits), the review used to cover
the whole change again. It now re-checks the earlier points in the files
they name, on 8 turns plus 3 per such file (at most a full review's base
of 30), and is told not to review the change again. The sweeps read only
those files' hunks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ully pointed small PR
Found verifying #241:
- git quotes non-ASCII paths in diffs. With the base moved, an edit to such
a file after a merge compared as no change, so the re-review could take
the re-check path and skip it. Diffs now use core.quotePath=false.
- A change taken back out of the pull request (a file reverted to the base)
read as "nothing changed". It now reviews what is left in full.
- Nothing changed and the earlier points name every file of a small pull
request: the focus equalled the change and fell back to a full review.
It stays a re-check.
- The comparison with the previous commit ran up to four times a review,
each with two merge bases and two full diffs when the base moved. It is
worked out once per previous commit, HEAD and base.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
Kai review · Ready to merge (9/10)
Read the whole thing — it does what it says, and nothing jumped out at me.
Next: merge when your checks are green — I found nothing to fix.
Since the last review: 1 fixed
an earlier point — fixed at cmd/kai/review_commit_rescope.go:196: rcBaseMovedBlock(prior, focus) filters through rcBaseOnlyOutsideFocus and omits the "They are not in the focus." sentence when the focus is nil.
To get to 10/10
−1 · tidy 1 nit (folded below)
1 nit · real, but none of them changes what the code does
cmd/kai/review_commit_rescope.go:26 — The header comment in review_commit_rescope.go still lists "nothing changed since" as a case that reviews the whole change, but the code now returns an empty, non-nil focus and runs the small re-check.
Important files changed
File
Change
cmd/kai/review_commit.go
modified · +15 −2
cmd/kai/review_commit_prior.go
modified · +7 −13
cmd/kai/review_commit_rescope.go
modified · +132 −12
cmd/kai/review_commit_rescope_base.go
modified · +341 −0
cmd/kai/review_commit_rescope_base_test.go
modified · +440 −0
cmd/kai/review_commit_rescope_test.go
modified · +2 −3
How I reviewed it — 3 files, 9 turns, 1m14s
0 confirmed findings, 1 refuted. Intent verified.
What I opened
3 of the 6 changed files don't appear below: cmd/kai/review_commit_rescope_base.go, cmd/kai/review_commit_rescope_base_test.go, cmd/kai/review_commit_rescope_test.go.
grep for callers and tests of rcBaseMovedBlock, rcBaseOnlyOutsideFocus, rcBaseOnlySince, rcReReviewFocus across cmd/kai
Findings
nit: cmd/kai/review_commit_rescope.go:26 — The header comment in review_commit_rescope.go still lists "nothing changed since" as a case that reviews the whole change, but the code now returns an empty, non-nil focus and runs the small re-check.
The file header says the review covers the whole change when nothing has changed since the last review. The code now does the opposite: when no changed-since file intersects the pull request's files and no change was dropped, it sets unchanged=true and returns an empty, non-nil focus. That leads to the small re-check path, not a whole-change review.
Remedy: Rewrite the header list so "nothing changed since" is described as leading to the re-check path (rcReReviewUnchanged), not as a whole-change review.
Size L · Risk M · +937 −30 · 6 files · reaches 81 · the full analysis · Reply to any of my comments and I'll answer, or say @kaicontext anywhere on this PR — a question, or "take another look at the retry logic". · Some repos review new pushes only when asked. Comment @kaicontext review any time for a review right away. Kept up to date: this is update 5, for 7c69071. Earlier points that still apply stay on their lines.
…d (Kai review)
- rcPatchByFile took any line starting "--- " or "+++ " for a file header,
so a removed "-- x" (SQL, Lua) or an added "++ x" was dropped, and a pull
request whose only edit was such a line read as unchanged. Header lines
now count only before a file's first "@@".
- rcGitPatchByFile, on a patch over its limit, waited on git while git was
blocked writing the rest: the review stalled for the 30 s deadline. It now
stops git first.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rcPatchByFile dropped "old mode"/"new mode" lines, so with the base moved a
chmod made after the previous review (a script made executable) compared
equal and read as no change. Mode lines, and the mode a file is added or
deleted with, are now part of the normalised patch.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…included
The pull request's file list comes from `git diff --numstat`, which quotes
non-ASCII paths ("caf\303\251.go") and, parsed by fields, names a renamed
file by its old path only. The changed-since lists are unquoted, so:
- an edited non-ASCII file never entered the focus, and with the base
unknown its only edit read as "nothing changed" (a re-check only);
- with the base known, every re-check of a pull request with a non-ASCII
or renamed file was read as a dropped change and became a full review.
Paths are now compared unquoted and returned as the review's list spells
them; the pull request's files at HEAD are worked out the same way as at the
previous commit (unquoted, a rename as both paths) and used for the dropped
check. rcGitChangedSince lists the same way, through rcGitNames, instead of
a second copy of the parsing. The re-check prompt only points at base
changes when BASE MOVED names some.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…iew)
The focus holds both paths of a rename (through rcPRFiles), while changed,
from --numstat, lists it once. Compared against len(changed), a rename since
the previous review could make the focus look like the whole change and
force a full review, and the prompt could read "2 of 1 changed files". The
focus is now compared with the pull request's files counted the same way,
and the prompt uses that count.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ot (Kai review)
Merges #241's rename-count fix (the focus block now counts the pull
request's files as the focus does).
rcSinceDiff passed root-relative focus paths as pathspecs but ran git in
the process's working directory; from a subdirectory they matched nothing,
the diff came back empty and nothing was chained. It, and the merge-tree
replay it uses, now run in the project root.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rcBaseMovedBlock was written whenever prior != nil and always said the
base-only files "are not in the focus" — wrong on a whole-change review
(no focus) and when rcReReviewFocus added an earlier point's file to the
focus. Pass the focus in, drop files that are in it via a shared
rcBaseOnlyOutsideFocus helper (also used by rcReCheckBlock, so the two
prompt blocks agree), and omit the sentence when there is no focus.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Two cases made a scoped re-review (#228) fall back to a full, full-price review:
What
Merge-safe focus (
review_commit_rescope_base.go). When the base moved between the two commits, each commit is compared with its own merge base. A file is in the focus only if the PR's own change to it differs: its added and removed lines, ignoring position.BASE MOVEDnote, so the reviewer can still look where a base change meets the PR's code.Nothing-changed path. When nothing the PR changes differs since the previous review:
Tradeoffs
BASE MOVEDnote.Tests
go test ./cmd/kai/...passes.Note
This touches the same
maxTurnslines inreview_commit.goas #240, so whichever merges second needs a small conflict fix. The combined rule: recheck budget when unchanged, otherwise the focus budget plus #240's related-file turns.🤖 Generated with Claude Code
Kai context
Written by Kai from the change itself. Kai only edits this section; everything above it is the author's.
A scoped re-review now counts only the pull request's own changes, so a merge or rebase of the base no longer pulls every file main touched into the focus. When nothing the PR changes differs since the previous review, it re-checks the earlier points on a small budget instead of reviewing the whole change again.
Changes
review_commit_rescope_base.go): when the base moved,rcComputeSincecompares each commit with its own merge base.rcPatchByFilenormalises the per-file patch (added and removed lines, new/deleted file, mode lines, binary line; no hunk positions or blob ids), andrcSplitPRChangessplits files into the PR's own changes and base-only ones. The commit-to-commit diff stays when there is no base, the base did not move, or no merge base is found.rcChangedSinceFnnow defaults torcGitPRChangedSince.rcSinceworks out each previous commit's comparison once per previous commit, HEAD and base, and keeps the focus, base-only files, and the PR's files then and now.core.quotePath=false.rcGitPatchByFilestops git when a patch is overrcPatchLimit, rather than waiting out the 30 s deadline.rcGitChangedSincenow goes throughrcGitNames, which lists a rename as both paths.rcPRFilesmaps unquoted paths to the spelling of the--numstatlist, which quotes non-ASCII names and gives a rename only its old path.rcPRFileCountcounts files the same way, so a rename counts once against the PR's size.review_commit_rescope.go):rcReReviewFocusreturns an empty, non-nil focus (the earlier points' files) when nothing the PR changes differs. It stays a re-check even if the points name every file of a small PR. A change taken back out of the PR (rcDroppedSince) is not treated as unchanged and leads to a full review.rcReReviewUnchangeddecides the mode.rcReCheckTurnsgives 8 turns plus 3 per point file, capped at 30.rcReCheckBlocktells the reviewer not to review the change again and only to re-check each earlier point.rcBaseMovedBlocknames base-only files outside the focus.rcBaseOnlyOutsideFocusis shared withrcReCheckBlock. The "not in the focus" sentence is dropped on a whole-change review, and files an earlier point added to the focus are not listed.review_commit.go):rcRunReviewAgentpicksmaxTurnsfrom the re-check budget or the normal one, writes the re-check or focus block plus the BASE MOVED block, and passesmaxTurnsto the agent config.rcReReviewFocuswhole-change test no longer lists "nothing changed since", which is now a re-check.Testing
go test ./cmd/kai/...passes.rcReReviewUnchanged, the re-check turns and block, and a dropped change.