Repository navigation
feat(pr-pipeline): review an oversize main-run diff in chunks #11160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fa3f3a4
feat(pr-pipeline): review an oversize main-run diff in chunks
kyle-sexton 72a8d80
Merge remote-tracking branch 'origin/main' into feat/main-review-chunked
kyle-sexton 0c2438b
Merge remote-tracking branch 'origin/main' into feat/main-review-chunked
kyle-sexton a93c119
Merge remote-tracking branch 'origin/main' into feat/main-review-chunked
kyle-sexton c6af84f
fix(pr-pipeline): keep each file whole in a main-review chunk and tak…
kyle-sexton 5c76ba9
Merge remote-tracking branch 'origin/main' into feat/main-review-chunked
kyle-sexton c7eefbc
Merge remote-tracking branch 'origin/main' into feat/main-review-chunked
kyle-sexton d40517b
fix(pr-pipeline): name each chunked finding's chunk and state the mul…
kyle-sexton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| --- | ||
| bump: minor | ||
| --- | ||
|
|
||
| ### Changed | ||
|
|
||
| - pr-review-main reviews a diff over its 300000-byte cap in chunks instead of stopping. The diff | ||
| splits into at most 4 chunks of at most 300000 bytes, cut at file boundaries with each file | ||
| whole, and each chunk is reviewed by its own run. The lane's one verdict sums the chunks' | ||
| findings, takes the most CRITICAL ones any one chunk found, and binds as a single-pass verdict | ||
| does. A `pr-review-main chunks` notice gives the chunk count and each chunk's bytes, and a | ||
| `pr-review-main chunk` notice per chunk its bytes, findings and CRITICAL ones. A diff that holds | ||
| a single file over 300000 bytes, or needs more than 4 chunks (a multi-file diff over about | ||
| 1.2 MB), still stops as `too-large`; lifting that needs a dynamic chunk count | ||
| ([#11000](https://github.com/melodic-software/claude-code-plugins/issues/11000)). Each listed | ||
| finding names its chunk, so the listed CRITICAL findings can outnumber the `critical` count. A | ||
| chunk that fails, leaves no result or skips a part writes no verdict: the record job posts | ||
| `verdict=none reason=chunk-failed` on the head and the leg fails. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| bump: patch | ||
| --- | ||
|
|
||
| ### Changed | ||
|
|
||
| - The babysit merge gate reads pr-review-main's `verdict=none reason=chunk-failed` check run as a | ||
| designed stop, like `too-large`, `binary` and `long-line`: it counts no CRITICAL finding and | ||
| binds no lane. |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| """Split the main-run review's patch into chunks one review reads whole. | ||
|
|
||
| usage: split-diff.py <patch> <out-dir> <max-bytes> <max-chunks> | ||
|
|
||
| Writes <out-dir>/chunk-<k>.patch, k from 1, each at most max-bytes, the | ||
| patch's bytes in order and nothing else. A chunk ends at a file boundary (a | ||
| `diff --git` line), and a file is never split: a file over max-bytes, or a | ||
| patch that needs more than max-chunks chunks, is too large: nothing is | ||
| written and the exit status is 3. An empty patch writes no chunk. | ||
| """ | ||
|
|
||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| TOO_LARGE = 3 | ||
|
|
||
|
|
||
| class TooLarge(Exception): | ||
| pass | ||
|
|
||
|
|
||
| def lines_of(data: bytes) -> list[bytes]: | ||
| """Each line with its newline; a content line always starts with a | ||
| prefix byte, so a line that starts `diff --git ` is git's.""" | ||
| lines = [line + b"\n" for line in data.split(b"\n")] | ||
| lines[-1] = lines[-1][:-1] | ||
| return [line for line in lines if line] | ||
|
|
||
|
|
||
| def split(data: bytes, max_bytes: int, max_chunks: int) -> list[bytes]: | ||
| files: list[list[bytes]] = [] | ||
| for line in lines_of(data): | ||
| if not files or line.startswith(b"diff --git "): | ||
| files.append([]) | ||
| files[-1].append(line) | ||
| chunks: list[bytes] = [] | ||
| for unit in (b"".join(lines) for lines in files): | ||
| if len(unit) > max_bytes: | ||
| raise TooLarge("a file is larger than one chunk") | ||
| if not chunks or len(chunks[-1]) + len(unit) > max_bytes: | ||
| chunks.append(b"") | ||
| chunks[-1] += unit | ||
| if len(chunks) > max_chunks: | ||
| raise TooLarge(f"the diff needs {len(chunks)} chunks, more than {max_chunks}") | ||
| return chunks | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| patch, out, max_bytes, max_chunks = sys.argv[1:5] | ||
| try: | ||
| chunks = split(Path(patch).read_bytes(), int(max_bytes), int(max_chunks)) | ||
| except TooLarge as error: | ||
| print(f"split-diff: {error}", file=sys.stderr) | ||
| sys.exit(TOO_LARGE) | ||
| for k, chunk in enumerate(chunks, 1): | ||
| (Path(out) / f"chunk-{k}.patch").write_bytes(chunk) | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.