Repository navigation
security-guidance: commit and push reviews no longer hold a large diff in memory - #7140
Merged
Merged
Conversation
The commit and push reviews captured, decoded and split the whole `git show -p` / `git diff` before looking at the number of files. An import of 5,800 files and 4.6 M lines took 6.4 GB, and the review was then skipped for its file count. Read git's output as it arrives and keep what the review uses: the characters of each file the prompt takes, a count of the added lines after them, and past the file cut-off only the file names. Co-authored-by: mhegazy <mhegazy@anthropic.com>
This was referenced Nov 16, 2026
…f-memory Co-authored-by: mhegazy <mhegazy@anthropic.com> # Conflicts: # plugins/security-guidance/hooks/security_reminder_hook.py
Windows can release a killed process's file lock a moment after the process ended, so the wait that follows may see it held once more. Co-authored-by: mhegazy <mhegazy@anthropic.com>
mhegazy
marked this pull request as ready for review
November 18, 2026 01:01
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Human: @mhegazy
What changes
The commit and push reviews read the whole
git show -p/git diffinto memory, decoded it and split it before looking at the number of files. On an import of 5,800 files and 4.6 M lines that took 6.4 GB, and the review was then skipped for its file count. They now read git's output as it arrives and keep only what the review uses:DIFF_PER_FILE_BYTES, 80,000), and a count of the added lines after them. That count decides which files are reviewed when there are more than 30.Skipped commits and pushes also report
diff_mbanddiff_timeout, when not zero.Fixes #7136.
What does not change
Which commits and files are reviewed, and what is sent. The end-of-turn review has its own reader, which is not touched. The combined diff of a merge's conflict resolutions is still read whole.
Limits
Memory
Peak of the hook process, commit review, Linux:
Amend and push are the same. On Windows and macOS the import takes 46 to 63 MB. Half of the import on 2.0.20: 4.1 GB on macOS.
SIGTERMduring such a commit now ends the hook at once; on 2.0.20 it waits 1.3 to 1.5 s for the decode or split to return.Tests
New:
tests/test_commit_diff_memory.py, 117 tests. One existing test changes:test_wait_for_holder_stops_at_the_limit(from #7103) accepts a killed holder's lock released up to 5 s late, which Windows does on some machines, and checks that a file nobody holds is still no wait at all.Runs are on this branch merged with main 1331242, against that main, unless a row says otherwise.
On Windows x64, main logged no commit review for two of the five very large commits in this run and no finding for one of them; this change reviewed or skipped all five as expected. On Windows ARM64 the commit and push cases ran on the single-shot fallback review, as on main. The end-to-end runs use a scripted model.
Generated by Claude Code