Skip to content

ci: build the Claude review diff with git so large PRs get reviewed - #2488

Merged
sbryngelson merged 1 commit into
MFlowCode:masterfrom
sbryngelson:claude-review-large-diff
Nov 25, 2026
Merged

sbryngelson merged 1 commit into
MFlowCode:masterfrom
sbryngelson:claude-review-large-diff

Conversation

@sbryngelson

Copy link
Copy Markdown
Member

Summary

The Claude review failed on #2486 before Claude started (run):

could not find pull request diff: HTTP 406: Sorry, the diff exceeded the maximum number of files (300).

#2486 changes 377 files. 362 of them are golden files under tests/, which the review leaves out, but the filter ran after gh pr diff had fetched the whole diff. Any PR that regenerates more than about 300 golden files hits this. The PR got a red check and no comment.

Changes

  • Build the diff and the changed-file list with git diff base...head -- . ':(exclude)tests' after fetching refs/pull/<n>/head. This has no file limit. The PR's commits are fetched as objects only; nothing from them is checked out or run.
  • Run the publish step after a failed step, so a job that breaks before the review posts the "no review was produced" comment with a link to the run. The job still ends red.

Testing

A pull_request_target workflow runs the base branch's copy, so this PR cannot exercise its own change. The new step was extracted from the YAML and run locally on a full clone:

After merge, #2486 needs the claude-full-review label to get its review.

gh pr diff fails with HTTP 406 when a PR changes more than 300 files.
MFlowCode#2486 changes 377, of which 362 are golden files under tests/ that the
review discards anyway, so the job failed before Claude started and
posted nothing.

Fetch the PR's commits and diff them locally against the base, leaving
out tests/. The commits are fetched as objects only and never checked
out or run. Also run the publish step after a failed step, so a job that
breaks before the review says so on the PR.
@sbryngelson
sbryngelson requested a review from a team as a code owner November 25, 2026 14:57
@sbryngelson
sbryngelson requested review from wilfonba and removed request for a team November 25, 2026 14:57
@sbryngelson
sbryngelson merged commit e6544c5 into MFlowCode:master Nov 25, 2026
19 checks passed
@github-actions

Copy link
Copy Markdown

Claude Code Review

Head SHA: 46e0506

Files changed:

  • 1
  • .github/workflows/claude-code-review.yml

Summary: The PR now builds the review diff and the changed-file list with git diff BASE...HEAD -- . ':(exclude)tests' after fetching refs/pull/<n>/head. This replaces gh pr diff, which returns HTTP 406 above 300 files, and gh pr view --json files, which silently stops at 100 files (it returned 100 of #2486's 377). The publish step now also runs after a failed step, as long as the review state was resolved. The change does what the description says. The new git diff calls cannot run anything from the PR: --no-ext-diff --no-textconv is set, attributes and config come from the base worktree, and the repo has no submodules. The three findings are all minor.

Findings:

  • low .github/workflows/claude-code-review.yml:208 (confident): This comment still says "the diff and file contents arrive through the API as data". The diff now comes from PR objects fetched with git fetch (line 121) and diffed locally. Only the file contents still come through the API. The PR updated the matching comment at lines 63-66 but missed this one. Suggested wording: "the diff is built with git from the PR's fetched objects and file contents come through the API; neither is checked out or run."

  • low .github/workflows/claude-code-review.yml:126 (confident about the mechanism; no such paths exist in the repo today): git diff --name-only C-quotes paths by default (core.quotePath=true). In a scratch repo, docs/ü.md came out as "docs/\303\274.md" and docs/a"b.md as "docs/a\"b.md". The old gh pr view --json files list gave raw paths. The prefetch loop (lines 160-180) passes each line unchanged to gh api "repos/$REPO/contents/$path?ref=...". For a PR touching such a file, that request fails, the manifest wrongly reports the file as "deleted, binary, empty or over 1 MB", and Claude gets no context for it. Fix: emit raw paths with git diff -z --name-only ... | tr '\0' '\n'. -c core.quotePath=false alone still quotes " and \.

  • low .github/workflows/claude-code-review.yml:121 (uncertain about impact): This brings back the PR-head fetch that ci: resolve CodeQL code-scanning alerts in workflows #1825 removed from this privileged job to close code-scanning alert Some of the example cases do not run to completition #57 (actions/untrusted-checkout/high). The ci: resolve CodeQL code-scanning alerts in workflows #1825 description says the checkout comment was written "so the fetch doesn't get reintroduced later", and this PR rewrites that comment. The PR description does not mention the reversal. The fetch is safe for the job's own steps (see Summary), but two things changed:

    • Code scanning will likely not catch this form. In CodeQL's current GitMutableRefCheckout, the match is a case-sensitive \bpr_number\b in the command or a check of env: expressions, and here the PR number reaches git through the script-local $PR_NUMBER. So nothing automated would flag a later step that checks out or runs this ref.
    • The fetch stores refs/remotes/pr-review/head in the repo where the agent runs an unrestricted shell. git log --all, git branch -a and git rev-list --all now include the PR's commits, while the prompt (lines 235-251) calls the checkout "the repository as it is without this PR" and points the agent at git history.

    Suggested fix: fetch without a destination ref, which leaves only FETCH_HEAD, or run git update-ref -d refs/remotes/pr-review/head after the two git diff calls. The objects stay, so the diff is unaffected. Also note the ci: resolve CodeQL code-scanning alerts in workflows #1825 reversal in the PR description so the decision is on record.

Coverage: I read the full post-change workflow (392 lines) and diffed it line by line against the base copy. The only changes are the four hunks in review.diff. I checked every changed step against its surrounding steps and outputs:

  • Head SHA. steps.state.outputs.current_head_sha is the same value the prefetch step uses.
  • Error handling. set -euo pipefail with the cat-file || fetch fallback is correct. A failed diff build now reaches the publish step.
  • Publish condition. ${{ !cancelled() && steps.state.outcome == 'success' }} replaces the implicit success(), and the YAML parses. Requiring the state step guarantees the head SHA, the existing comment ID and the .claude-review/ directory. When output.md is missing, the placeholder path is taken, with Claude step outcome "skipped".

History and tooling I traced:

  • ci: resolve CodeQL code-scanning alerts in workflows #1825. Its description and diff show the fetch it removed and why.
  • CodeQL. I downloaded the UntrustedCheckoutQuery.qll, Bash.qll and Helper.qll sources to check how the untrusted-checkout query matches git fetch.
  • gh. gh 2.104 supports --json baseRefOid; it returned 40fb8d23, the base tip.
  • Repo contents. .gitattributes holds only linguist-generated entries and sets no diff drivers. There is no .gitmodules, and no tracked path is non-ASCII or contains quotes or spaces.
  • Other workflows. No other workflow uses gh pr diff or the removed .raw files, and claude.yml does not need the same change.

Candidates I checked and dropped:

  • A transient early failure now replaces an existing review comment with "No review was produced". The workflow already does this when Claude fails, so the behaviour is consistent.
  • Failures in the four steps up to Resolve review state still post nothing. That is by design, since publishing needs the head SHA and comment ID.
  • A push between resolving the head SHA and the fetch is covered by the fetch-by-SHA fallback.

There is no linked issue; the PR cites the failed run on #2486. CI checks for this PR were still pending when I looked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant