Skip to content

fix(pr-pipeline): cut a file larger than one chunk into pieces at its hunks - #18196

Merged
kyle-sexton merged 6 commits into
mainfrom
fix/18178-split-file-into-pieces
Nov 22, 2026
Merged

kyle-sexton merged 6 commits into
mainfrom
fix/18178-split-file-into-pieces

Conversation

@kyle-sexton

@kyle-sexton kyle-sexton commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Refs: #18178

Summary

pr-verify and pr-review-main gave no verdict when one file's diff was larger than one chunk (300,000 bytes): split-diff.py kept every file whole and exited 3. PR #18165 hit this with one 334 KB file.

split-diff.py now cuts such a file at its hunk headers (@@ lines) into pieces of at most the chunk size. Each piece repeats the file's header (its lines before the first hunk), and no two pieces of one file share a chunk. The manifest lists each piece as chunk <k> piece <i> of <n> <status> <path>. A whole file is listed as before.

Fix

  • .github/scripts/pr-review-main/split-diff.py: pieces_of packs a file's hunks into pieces under its header. A piece counts as one file for the optional file cap. MAX_CHUNKS stays the cost guard: a diff that needs more chunks, pieces included, still exits 3 with nothing written.

  • A file with one hunk that is over the cap together with its header still exits 3, with "a file has a hunk larger than one chunk". The issue asks for such a hunk to be cut at line boundaries. That is not done here, for two reasons:

    • ci-workflows' generate-review-chunks/split.sh calls this same split-diff.py. It cuts oversize files at their hunks itself, and relies on this refusal for an oversize hunk ("the split refuses it and the review stays partial"). Cutting at lines would hand its compose.cjs pieces it does not know about.
    • A piece cut mid-hunk has no @@ header, so a reviewer could not place its lines.

    Cutting at hunks alone is enough for PR docs(upstream): re-audit cursor pstack drift and move the pin to 0b46ec3 #18165: its largest hunk is 290,134 bytes.

  • The prompts are updated so a judge cannot read a piece as a whole file:

    • pr-verify's chunk-note.md and the final judge's manifest description in spec-prompt.md
    • pr-review-main's chunk note in all three legs
  • Also updated: the step comments, and pr-review-main's too-large stop message.

  • chunk-diff.sh's header no longer says an over-size file gets no verdict. It now names only a hunk over one chunk, or a diff over MAX_CHUNKS.

  • docs/conventions/pr-pipeline/README.md describes the pieces and the stop that remains. A pr-pipeline changelog fragment is added.

  • Not changed: what the verifier trusts (resolve-pr, the trusted-text inputs, permissions). The existing final-judge path covers a cut file, because a cut file always makes more than one chunk.

Verification

  • node --test --test-concurrency=4 over pr-review-main/workflow.test.mjs, pr-verify/chunk-diff.test.mjs, pr-verify/workflow.test.mjs and pr-verify/spec-prompt-text.test.mjs: 127 passed.
  • New and changed tests:
    • a file cut into pieces, with its manifest lines
    • a small file sharing the last piece's chunk
    • the MAX_CHUNKS exit with pieces, and the file cap counting each piece
    • a single over-size hunk still exiting 3
    • under pr-verify.yml's real limits, one 334 KB file in 12 hunks giving chunks=2 with no ::error::, its pieces rebuilding the patch byte for byte
    • pr-review-main's "Write the diff" step judging a many-hunk file in two chunks with no stop
    • the chunk prompts naming piece <i> of <n>
  • scripts/run-ruff.sh check on split-diff.py: clean.
  • scripts/check-affected.sh: 19 passed, 3 skipped.
  • pr-verify and pr-review-main run these scripts from main's checkout (.base), so this PR's own run still uses the old splitter. Done-when item 1 is proven live after merge, when pr-verify re-runs on docs(upstream): re-audit cursor pstack drift and move the pin to 0b46ec3 #18165.
  • Left out: the full .github suite (per-machine limit; CI runs it), and cutting a single over-size hunk at line boundaries (see Remaining).

Remaining

This PR delivers done-when items 2 and 3, and item 1 for every file whose largest hunk, with the file's header, fits in one chunk. #18165 is such a file.

Item 1 says: "A PR whose single file diff is larger than MAX_DIFF_BYTES (and within MAX_CHUNKS chunks) gets a pr-verify verdict." It is not delivered for a file whose one hunk is over MAX_DIFF_BYTES with its header. That case still gets no verdict.

Basis: the issue's Fix says "A single hunk larger than a chunk is cut at line boundaries." Cutting there needs a follow-up in ci-workflows. .github/actions/generate-review-chunks/split.sh calls this same split-diff.py and relies on its refusal of an oversize hunk ("A file with a hunk over the budget with its header is not cut, so the split refuses it and the review stays partial"). Its build-review-prompt/compose.cjs labels pieces only from the sliced.txt list that split.sh writes. The orchestrator chose to keep the refusal here.

Related

🤖 Generated with Claude Code

https://claude.ai/code/session_01RAoAtViDMW2P121uLvSb35

kyle-sexton and others added 4 commits November 22, 2026 12:40
… hunks

split-diff.py cut no file, so a single file diff over MAX_DIFF_BYTES left
pr-verify and pr-review-main with no verdict. It now cuts such a file at
its hunk headers into pieces of at most the cap, each under the file's own
header, and the manifest lists each piece as `piece <i> of <n>`. A file
with one hunk over the cap with its header, and a diff over MAX_CHUNKS
chunks, still exit 3 with nothing written.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RAoAtViDMW2P121uLvSb35
…pieces

The pr-verify chunk note, the final judge's manifest description, the
pr-review-main chunk note and the step comments said every chunk holds
whole files. They now say a file larger than one chunk is cut at its
hunks into pieces in different chunks, listed as `piece <i> of <n>`, and
that the no-verdict stop is a hunk over one chunk or a diff over
MAX_CHUNKS.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RAoAtViDMW2P121uLvSb35
The convention README said every chunk holds whole files and that a single
file over 300000 bytes gets no verdict. It now names the pieces and the
remaining single-hunk stop, with a changelog fragment. The pr-review-main
chunk note no longer invites a finding for a hunk a piece does not hold.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RAoAtViDMW2P121uLvSb35
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 22, 2026 18:08
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T18:14:06.009392Z e5cba98 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 255e2e9733197b77a2b9ddd775a32d90e0a7fb9e: read 11 of 11 changed file(s); 0 finding(s), 0 as inline comments.

Security review: no security issues found

This review covered only blocking findings, because this lane already reviewed an earlier head (e5cba98c). I read every hunk of all 11 changed files in .claude-lane/pr.diff and the whole head split-diff.py. The two workflows and pr-review-main/split-diff.py match trusted-path globs, so I read their full change and what it gates.

What I checked

  • Parsing the untrusted diff. pieces_of (split-diff.py:53-75) cuts a file only at lines that start with @@.
    • A pull request author cannot plant a fake cut point in file content. Every hunk content line starts with a prefix byte ( , +, - or \), and no git header line starts with @@.
    • Each piece is head + hunks, built only from the patch's own bytes. The new tests rebuild the original patch byte for byte from the pieces.
    • A file over the cap with no hunk, or with one hunk over the cap together with its header, still fails closed with exit 3 and writes nothing (:68-69, :95-98).
  • Manifest. The piece <i> of <n> prefix is built from integers only (split-diff.py:143). The path still comes from the unchanged entry() and stays quoted the way git quotes it, so a path the author chooses cannot add a line or fake a piece marker. The prompts still frame the manifest as untrusted data.
  • Shell in pr-review-main.yml. The new note text sits inside an existing double-quoted bash string in all three legs (lines 1219, 2177 and 3113). The backticks around piece <i> of <n> are escaped and diff --git has no backticks, so nothing new is command-substituted. The stop too-large message changes only its literal text.
  • Trust surface. The diff leaves permissions, triggers, token requests, trusted-text inputs and resolve-pr unchanged. The splitter still runs from the base checkout (.base/...) under python3 -I, so the PR's own copy does not run in its own lanes.
  • Prompt wording. The added instruction "never report a change as missing only because your piece does not hold it" applies only to hunks that other chunks hold. It removes no guardrail, and the existing cross-chunk reference finding stays.
  • Gates. No merge hold, kill switch, trusted-actor check or token scope changes. A single file over one chunk used to stop as too-large with no review. It now gets reviewed in pieces, which adds coverage and lets no new actor or input through.
  • test-scope comment. The line added to workflow.test.mjs only selects more tests. It removes nothing.

Spend: a pull request with a single-file diff over 300 KB now runs one review or verifier run per chunk where it used to stop. This uses prepaid model usage only, so it is not a hold.

critical-findings: 0

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

claude-review reviewed 255e2e9733197b77a2b9ddd775a32d90e0a7fb9e: read 11 of 11 changed file(s); 0 finding(s), 0 as inline comments.

Code review: PR #18196: cut a file larger than one chunk into pieces at its hunks

This review is blocking only. The lane already reviewed an earlier head (e5cba98c), so this pass reports only blocking findings and manifest flag lines. I found nothing blocking.

I read every hunk of all 11 changed files in the full diff. I also read the head copy of split-diff.py in full.

What I checked in split-diff.py at this head:

  • Piece size. No piece can go over max_bytes. A file is cut only when its header plus its largest hunk fits (split-diff.py:68), and each new piece starts with the header.
  • Two pieces of one file never share a chunk. A new piece starts only when len(prev) + len(hunk) > max_bytes. The next piece is the header plus that hunk, so a chunk holding both pieces would be over the cap.
  • A file with no hunks over the cap (at == len(lines), so hunks is empty) returns None. It is refused by name, as before.
  • Manifest entries. entry(lines_of(unit)) reads each piece's repeated header, so status and path come out right for every piece, renames included.

test-scope: line in pr-review-main/workflow.test.mjs:7. This matches the repository's existing convention. The test symlinks plugins/source-control into .base (around line 1417), so a change to that plugin's manifest correctly selects this test. It is not a finding.

Closing issue: the PR context has no closing-issue section, only Refs: #18178, so I judged no acceptance criteria. The PR body says done-when item 1 is only partly delivered: a file whose single hunk is over one chunk, header included, still gets no verdict. That is the author's claim; I did not verify it.

Verification: the test runs, the ruff check and the check-affected.sh results in the PR body are author-claimed. I did not run them; this lane has no shell.

Spend (not a finding): a PR with one file over 300000 bytes now gets chunked pr-verify and pr-review-main runs instead of stopping. That means more lane runs, paid from prepaid API credit. The MAX_CHUNKS cost guard is unchanged.

Loosened checks:

  • I judged the rewritten refusal expectations in workflow.test.mjs and chunk-diff.test.mjs as not a loosening. The refusals that remain (a hunk over the cap, a diff over MAX_CHUNKS) are still tested.
  • Loosened checks would be marked: fail. This is the default, because the prompt has no loosened_check_verdict: line. Patterns: 0, because there is no loosened_check_patterns: line.
  • The prompt has no loosened_check_decision_record: line either, so I did not check the citation requirement.

Verifier dropped 0 of 0 candidates.

kyle-sexton and others added 2 commits November 22, 2026 13:32
The suite symlinks plugins/source-control into its checkout and reads
plugin.json through it, so a change to that file must select the suite
(scripts/affected-tests.sh R8).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RAoAtViDMW2P121uLvSb35
@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 22, 2026
Merged via the queue into main with commit 5e31393 Nov 22, 2026
55 checks passed
@kyle-sexton
kyle-sexton deleted the fix/18178-split-file-into-pieces branch November 22, 2026 18:59
@github-actions github-actions Bot added the merge-path: owner-agent Post-merge accounting record (README.md, Merge paths) label Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-path: owner-agent Post-merge accounting record (README.md, Merge paths)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant