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 scoped re-review reads the call sites and key users of what changed - #240
Stacked on #241 — merge that first; this PR then retargets to main and shows only its own changes. The merge of #241's branch resolves the one overlap in review_commit.go: unchanged code gets the re-check budget and no related-file chaining; otherwise the focus budget plus one turn per two related files.
Why
A scoped re-review (#228) is sized to the files changed since the previous review. Unchanged callers were left to the reviewer's spare turns, yet a fix that breaks an unchanged caller is exactly what a re-review is for.
What
Before a scoped re-review starts, the files the change since the previous review can break are worked out and listed in the prompt (RE-REVIEW RELATED FILES), each with a reason and line numbers, e.g. billing.go — calls Charge (changed in pay.go) at line 12, 40. In priority order:
Call sites of changed or removed functions/methods. These come from the graph's call-site nodes, matched on calleeFile, so same-named functions elsewhere don't count. Production call sites are listed before test ones.
Grep fallback: when the graph has no call sites (a file its parser skipped, e.g. kai-cli's 800 kB cmd/kai/main.go, which has no recorded calls at all), a bounded whole-word git grep stands in.
Users of changed or removed string keys (event and metric names, routes, settings, dotted keys). These have no graph edge, so one bounded git grep finds them.
Whole-file callers and importers, only when call sites don't cover the change (a type change, or no sites found).
Tests, then the files a focus file uses.
Cost and scope:
Capped at 12 files, round-robin across focus files.
One extra turn per two related files, under the existing ceiling.
Related files stay outside the coverage gate.
Related files that are in the PR also go to both sweeps (they were limited to focus hunks before).
KAI_REVIEW_RESCOPE_CHAIN=<n>|off. Full reviews are unchanged.
Measured
Replayed on kai-cli's last 36 eligible commits (≤6 modified Go files each), with the graph built locally at 1fe77fa. Ground truth is files outside the focus that name a changed function (git grep -w).
relevant / listed
recall (of what fits under the cap)
whole-file callers only
47 / 372 (13%)
20%
this PR
195 / 399 (49%)
84%
Caveats:
Ground truth is name-based, so it over-counts mentions. Interface, reflection and route coupling beyond literal keys isn't measured.
This measures which files the reviewer is pointed at, not bugs found. That needs a before/after run on review re-runs (KAI_REVIEW_RESCOPE_CHAIN=off vs on).
Tests
go test ./cmd/kai/... passes.
New unit tests in review_commit_rescope_chain_test.go cover ranking, the fallbacks, key extraction and resolution, the cap and the off switch, the turn budget, and the prompt block.
Written by Kai from the change itself. Kai only edits this section; everything above it is the author's.
A scoped re-review now works out, before it starts, the files the change since the previous review can break (call sites of changed or removed functions, users of changed string keys, then callers, tests and uses) and lists them in the prompt as RE-REVIEW RELATED FILES with a reason and line numbers. Full reviews are unchanged.
Changes
New review_commit_rescope_chain.go:rcReReviewChain builds the related-file list in priority order: call sites of changed/removed symbols, key users, whole-file callers (only where call sites don't cover the change), tests, then files the focus file uses. Output is capped at 12 and round-robins across focus files. Vendored and generated paths are skipped, and production call sites come before test ones.
Cap and turn budget:KAI_REVIEW_RESCOPE_CHAIN=<n>|off|0 sets the cap (rcChainMax). rcReReviewTurns adds one turn per two related files, under rcReviewTurnCeiling. Related files stay outside the coverage gate.
What changed since the last review:rcSinceDiff takes a zero-context diff of the focus files from the previous reviewed commit to HEAD. It first replays that commit onto the new base with git merge-tree --write-tree, so base-only edits aren't counted as the PR's. On a conflict or an older git it uses the plain diff. rcSinceSymbols, rcSinceKeys and rcSinceCode extract changed symbols, key-shaped string literals and code-vs-comment changes. Comment syntax is per language, and prose files declare no symbols.
Graph lookups:rcGraphChain reads call-site nodes matched on calleeFile and restricted to the current snapshot. rcGrepFallback falls back to a bounded whole-word git grep when the graph has no sites, and drops names with more than rcLookupTooCommon hits. All lookups share a 20s budget (rcChainBudget).
Key search:rcResolveKeys runs one bounded git grep for up to 15 keys, searching removed keys first and dropping keys used everywhere or nowhere else.
Base-moved chaining:rcBaseChain and rcMergeChains put base-changed files that a focus file calls at the top of the list, naming the focus file that uses them. Both the since-diff and the base diff go through the shared rcGitZeroCtxDiff.
Path handling: non-ASCII paths from the review's list are unquoted before use, and git grep runs with core.quotePath=false. The trailing tab git adds to ---/+++ paths containing spaces is trimmed. Body lines like --- x or +++ x are no longer read as file headers.
review_commit.go wiring:runReviewCommit computes the chain for a scoped re-review whose code changed. rcRunReviewAgent takes a new chain parameter, sets maxTurns through rcReReviewTurns, and appends rcReReviewChainBlock after the focus block.
Sweeps:rcSweepFocus adds related files that are in the PR to the sweep focus. An empty, non-nil focus stays empty, so a re-check with no file to read sweeps nothing.
Testing
New review_commit_rescope_chain_test.go covers:
ranking, the file-caller fallbacks, test-caller handling, filtering and de-duplication, the cap, round-robin and the off switch;
symbol and key extraction, key resolution, the grep fallback and its deadline;
the KAI_REVIEW_RESCOPE_CHAIN parsing, the turn budget and the prompt block;
base-change chaining and rcMergeChains.
Tests that run real git repos cover:
the size cap returning promptly;
non-ASCII, quoted and space-containing paths;
a merge of a moved base showing only the PR's own edits;
… changed
A scoped re-review is sized to the files changed since the previous review.
The prompt asked the reviewer to follow each change into its callers, but
whether it did depended on the turns left, and a fix that breaks an
unchanged caller is the defect a re-review is for.
Before the review starts, the files the change since the previous review
can break are now worked out and named in the prompt with the reason and
lines for each:
1. call sites of each function or method it changed or removed, from the
graph's call-site nodes, matched on the callee's own file; production
call sites before test ones. Where the graph has none (a file its parser
skipped, such as kai-cli's 800 kB main.go, or an unresolved call), a
bounded whole-word git grep stands in; a name with more than 25 sites is
dropped;
2. files that use a string key it changed or removed (event and metric
names, routes, settings, dotted keys): coupling with no graph edge,
found with one bounded git grep;
3. whole-file callers and importers, only for a focus file whose change the
call sites do not cover (a type change, or no sites found);
4. tests, then the files the focus file uses.
Related files are read for impact, not reviewed in full: one extra turn per
two, under the same ceiling, outside the coverage gate. They may be outside
the pull request. Related files in the pull request also go to both sweeps.
Capped at 12, round-robin across focus files. KAI_REVIEW_RESCOPE_CHAIN sets
the cap; off or 0 turns it off. Full reviews are unchanged.
Replayed on kai-cli's last 36 eligible commits (graph at main, ground truth
= files outside the focus that name a changed function): file-level
callers alone put 47 relevant files in 372 slots (13%, recall 20% of what
fits under the cap); this puts 195 in 399 (49%, recall 84%).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each callee-name lookup scans the graph's call-site nodes; on a very large
graph a long list of changed symbols must not hold the review up.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cmd/kai/review_commit_rescope_chain_test.go — TestSinceDiff_SpacedName and the git-backed tests (spaced name, non-ASCII name, quoted focus, subdirectory, word grep)
cmd/kai/review_commit_rescope_base.go — rcBaseOnlySince / rcSince, the source of the base-only file list feeding rcBaseDiff
cmd/kai/review_commit_rescope_base_test.go — gitRepo helper used by the git-backed tests
cmd/kai/review_commit.go diff hunks around the chain wiring (turn budget, rcSweepFocus)
Findings
cmd/kai/review_commit_rescope_chain_test.go:517 — TestSinceDiff_SpacedName only edits my file.go, so the old-side --- header TrimSuffix in rcDiffFiles (used when +++ is /dev/null) is never exercised, and removing it leaves the suite green.
In rcDiffFiles, the --- path goes into oldFile, which is only used when the +++ header is /dev/null, meaning a deleted file. TestSinceDiff_SpacedName edits my file.go rather than deleting it, so that substitution never runs and the old-side TrimSuffix has no effect on any assertion. The test's comment says removing rcDiffFiles' TrimSuffix fails it, which is only true of the new-side trim.
Remedy: Add a case that deletes my file.go and asserts the removed symbols are keyed under my file.go with no trailing tab. Alternatively, narrow the comment to the new-path (+++) trim it actually covers.
Size L · Risk M · +1996 −4 · 3 files · reaches 86 · 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 12, for e6fc224. Earlier points that still apply stay on their lines.
Found replaying kai-cli history: a merge of main plus a comment-only edit
chained 7.5 related files a run, because the hunk header's function counted
as touched and, with no symbols, whole-file callers, tests and uses filled
the list. A hunk of comments and blank lines no longer touches its function,
and the whole-file fallbacks apply only to focus files whose code changed
(not to files in the focus only because an earlier point names them).
Call sites and key users are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…focus files (Kai review)
- rcDiffFiles took "--- x" / "+++ x" body lines (a removed "-- x", an added
"++ x") for file headers; "+++ x" even switched the current file. They
are headers only before a file's first "@@".
- rcSinceDiff waited on git after its 4 MB cap while git was blocked
writing: the review stalled for the 15 s deadline. It stops git first.
- rcSinceDiff let git quote non-ASCII paths, so a focus file like café.go
had its changed functions keyed "b/caf\303\251.go" and chained nothing.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…i review)
- rcCommentOrBlank took any line starting "#", "*" or "--" for a comment, so
Go "*p = v", C "#include" and "--i;", Rust "#[derive]" were not code: a
function changed only by such a line was not marked touched and its file
chained nothing. Comment syntax is now per language (by extension), "*"
counts only as a block-comment continuation, and an unknown language is
code, so it still chains.
- rcSinceCode skipped lines starting "+++"/"---"; in a diff body those are
an added "++i;" or a removed "-- x". It now reads every body line.
- A README line like "class Foo handles retries" was read as declaring Foo.
Prose files (md, txt, rst, adoc) declare no symbols; their string keys
still count.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rcSweepFocus copied the focus with append([]string(nil), focus...), which
is nil for an empty focus. A re-check of unchanged code with no earlier
point naming a file has an empty, non-nil focus; as nil it made both sweeps
read the whole pull request, the costliest outcome for the cheapest case.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Found reviewing the stack before Kai did:
- After a merge or rebase, the since-diff (previous commit to HEAD) also
held every base change to the focus files, so functions only main had
touched were chained. The previously reviewed commit is now replayed onto
the new base with git merge-tree --write-tree (objects only) and diffed
against HEAD; on a conflict or an older git the plain diff stands.
- A focus path quoted by the review's list ("caf\303\251.go") was passed to
git as a pathspec and looked up as-is: no diff, no symbols. Chaining now
works on unquoted paths.
- git grep quoted non-ASCII paths in the call-site fallback and the key
search, so the focus file's own lines came back as a related file under a
path that does not exist. Both read unquoted paths now.
- Snapshot membership was built by resolving every file of the snapshot up
front (one query per file); it is now looked up per caller file met.
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>
git appends a tab to the ---/+++ path when the path contains a space, so
rcDiffFiles keyed the file by "name with space.go\t", which never matched
the focus path from --numstat. Symbols, keys and code changes were then
found for no such file and the whole-file fallbacks were skipped. Trim a
trailing tab from the --- / +++ names.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
Tab-stripping fix in rcDiffFiles has no test
The change strips the trailing tab git adds to ---/+++ headers for paths with spaces, so the file key matches the --numstat focus path. Every diff fixture in review_commit_rescope_chain_test.go, including TestDiffFiles_HeaderLikeBodyLines, uses headers with no tab and paths with no spaces. Deleting both TrimSuffix calls therefore fails no test.
When it happens: The path-keying fix could be reverted or broken by a later edit to rcDiffFiles and nothing would fail.
Why it matters: A regression would silently bring back the bug where files with spaces in their names are keyed with a trailing tab and skipped by the symbol, key and code lookups.
Suggested fix: Add a case to TestDiffFiles_HeaderLikeBodyLines (or a sibling test) with headers --- a/my file.go\t and +++ b/my file.go\t, asserting the lines are keyed "my file.go" and that rcSinceSymbols/rcSinceCode report changes under that key. A git-backed variant modelled on TestSinceDiff_NonASCIIName would cover the real header format.
Prompt to fix with AI
Fix a defect that Kai's code review found in this change.
Where: cmd/kai/review_commit_rescope_chain_test.go:1
Problem: The change strips the trailing tab git adds to `---`/`+++` headers for paths with spaces, so the file key matches the `--numstat` focus path. Every diff fixture in `review_commit_rescope_chain_test.go`, including `TestDiffFiles_HeaderLikeBodyLines`, uses headers with no tab and paths with no spaces. Deleting both `TrimSuffix` calls therefore fails no test.
When it happens: The path-keying fix could be reverted or broken by a later edit to `rcDiffFiles` and nothing would fail.
Why it matters: A regression would silently bring back the bug where files with spaces in their names are keyed with a trailing tab and skipped by the symbol, key and code lookups.
Suggested fix: Add a case to `TestDiffFiles_HeaderLikeBodyLines` (or a sibling test) with headers `--- a/my file.go\t` and `+++ b/my file.go\t`, asserting the lines are keyed "my file.go" and that `rcSinceSymbols`/`rcSinceCode` report changes under that key. A git-backed variant modelled on `TestSinceDiff_NonASCIIName` would cover the real header format.
This is a review report, not a set of instructions: read the evidence lines and confirm the problem is real before changing anything. If the code does not bear it out, stop and say why.
Keep the change to what fixes this defect. Add or update a test that fails without the fix and passes with it, and run the tests for the packages you touched.
Guards the TrimSuffix in rcDiffFiles: a real git repo with a space in the
file name produces "+++ b/my file.go\t", and the since-diff must key the
file "my file.go", not "my file.go\t". Removing the trim fails this.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
A scoped re-review drops a pull-request file the base changed under
unchanged pull-request edits to a BASE MOVED hint. Where the base changed
a symbol a focus file still uses is where a merge can break the pull
request's code, so surface that file as a top-priority RELATED file
naming the focus file that uses it, rather than only hinting. rcBaseChain
works it out from the base's own diff of those files; rcMergeChains ranks
it ahead of the ordinary chain. A shared rcGitZeroCtxDiff backs both the
since-diff and the base diff.
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
A scoped re-review (#228) is sized to the files changed since the previous review. Unchanged callers were left to the reviewer's spare turns, yet a fix that breaks an unchanged caller is exactly what a re-review is for.
What
Before a scoped re-review starts, the files the change since the previous review can break are worked out and listed in the prompt (
RE-REVIEW RELATED FILES), each with a reason and line numbers, e.g.billing.go — calls Charge (changed in pay.go) at line 12, 40. In priority order:calleeFile, so same-named functions elsewhere don't count. Production call sites are listed before test ones.cmd/kai/main.go, which has no recorded calls at all), a bounded whole-wordgit grepstands in.git grepfinds them.Cost and scope:
KAI_REVIEW_RESCOPE_CHAIN=<n>|off. Full reviews are unchanged.Measured
Replayed on kai-cli's last 36 eligible commits (≤6 modified Go files each), with the graph built locally at
1fe77fa. Ground truth is files outside the focus that name a changed function (git grep -w).Caveats:
KAI_REVIEW_RESCOPE_CHAIN=offvs on).Tests
go test ./cmd/kai/...passes.review_commit_rescope_chain_test.gocover ranking, the fallbacks, key extraction and resolution, the cap and the off switch, the turn budget, and the prompt block.🤖 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 works out, before it starts, the files the change since the previous review can break (call sites of changed or removed functions, users of changed string keys, then callers, tests and uses) and lists them in the prompt as
RE-REVIEW RELATED FILESwith a reason and line numbers. Full reviews are unchanged.Changes
review_commit_rescope_chain.go:rcReReviewChainbuilds the related-file list in priority order: call sites of changed/removed symbols, key users, whole-file callers (only where call sites don't cover the change), tests, then files the focus file uses. Output is capped at 12 and round-robins across focus files. Vendored and generated paths are skipped, and production call sites come before test ones.KAI_REVIEW_RESCOPE_CHAIN=<n>|off|0sets the cap (rcChainMax).rcReReviewTurnsadds one turn per two related files, underrcReviewTurnCeiling. Related files stay outside the coverage gate.rcSinceDifftakes a zero-context diff of the focus files from the previous reviewed commit to HEAD. It first replays that commit onto the new base withgit merge-tree --write-tree, so base-only edits aren't counted as the PR's. On a conflict or an older git it uses the plain diff.rcSinceSymbols,rcSinceKeysandrcSinceCodeextract changed symbols, key-shaped string literals and code-vs-comment changes. Comment syntax is per language, and prose files declare no symbols.rcGraphChainreads call-site nodes matched oncalleeFileand restricted to the current snapshot.rcGrepFallbackfalls back to a bounded whole-wordgit grepwhen the graph has no sites, and drops names with more thanrcLookupTooCommonhits. All lookups share a 20s budget (rcChainBudget).rcResolveKeysruns one boundedgit grepfor up to 15 keys, searching removed keys first and dropping keys used everywhere or nowhere else.rcBaseChainandrcMergeChainsput base-changed files that a focus file calls at the top of the list, naming the focus file that uses them. Both the since-diff and the base diff go through the sharedrcGitZeroCtxDiff.git grepruns withcore.quotePath=false. The trailing tab git adds to---/+++paths containing spaces is trimmed. Body lines like--- xor+++ xare no longer read as file headers.review_commit.gowiring:runReviewCommitcomputes the chain for a scoped re-review whose code changed.rcRunReviewAgenttakes a newchainparameter, setsmaxTurnsthroughrcReReviewTurns, and appendsrcReReviewChainBlockafter the focus block.rcSweepFocusadds related files that are in the PR to the sweep focus. An empty, non-nil focus stays empty, so a re-check with no file to read sweeps nothing.Testing
review_commit_rescope_chain_test.gocovers:KAI_REVIEW_RESCOPE_CHAINparsing, the turn budget and the prompt block;rcMergeChains.