Repository navigation
fix(ci): skip AI review when a PR exceeds GitHub's diff-file limit - #2536
Merged
Merged
Conversation
`gh pr diff` reads GET /repos/{owner}/{repo}/pulls/{n} with the diff media
type, and that endpoint refuses above 300 files:
HTTP 406: Sorry, the diff exceeded the maximum number of files (300).
PullRequest.diff too_large
PR #2535 changes 804 files, so all three reviews died in "Fetch the PR diff
for the reviewer". 406 is deterministic, so the step's three retries could
never recover it, and its exhausted-loop path is fatal by design — the right
instinct, since a review that silently saw no diff is worse than no review,
but it cannot tell "transient" from "will never fit through this endpoint".
Catch it one step earlier instead. The guard already paginates
/pulls/{n}/files, which has no such cap, so the file count is in hand before
anything asks for the diff. Over the limit, the review is skipped with a
comment saying why, rather than failing three checks red.
Folded into the existing guard rather than added alongside it: seven later
steps hang off its `skip` output, and reusing the id leaves all of them
untouched. That means the step-level event gate moves inline, which is also
more correct — the file limit is a hard API fact and applies on every event,
while the new-file-only rule is policy and stays on the automatic trigger,
so a maintainer can still force a review by hand.
Two counts now come from one pagination pass. The non-added count uses awk
rather than `grep -cv ... || true`: grep exits 1 on no match, which `set -e`
reads as failure and an all-added PR triggers, but `|| true` also swallows
grep's exit >1 on a real error, leaving the count empty — and `[[ "" -eq 0 ]]`
is true in bash, so the guard would skip a PR it never managed to read and
report it as "only adds new files". awk exits 0 with no matches and non-zero
only on a real error, which pipefail turns into the loud failure it should be.
Verified by extracting the step's run: block and executing it against live
PRs with `gh pr comment` stubbed (#2535 skips on both pull_request and
issue_comment; #2507 skips only on pull_request; #2531 is unaffected), and
against a synthetic API for the boundary and error paths (300 files pass,
301 skip, a failing `gh api` or an unreadable file aborts instead of
silently skipping).
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.
gh pr diffreads GET /repos/{owner}/{repo}/pulls/{n} with the diff media type, and that endpoint refuses above 300 files:PR #2535 changes 804 files, so all three reviews died in "Fetch the PR diff for the reviewer". 406 is deterministic, so the step's three retries could never recover it, and its exhausted-loop path is fatal by design — the right instinct, since a review that silently saw no diff is worse than no review, but it cannot tell "transient" from "will never fit through this endpoint".
Catch it one step earlier instead. The guard already paginates /pulls/{n}/files, which has no such cap, so the file count is in hand before anything asks for the diff. Over the limit, the review is skipped with a comment saying why, rather than failing three checks red.
Folded into the existing guard rather than added alongside it: seven later steps hang off its
skipoutput, and reusing the id leaves all of them untouched. That means the step-level event gate moves inline, which is also more correct — the file limit is a hard API fact and applies on every event, while the new-file-only rule is policy and stays on the automatic trigger, so a maintainer can still force a review by hand.Two counts now come from one pagination pass. The non-added count uses awk rather than
grep -cv ... || true: grep exits 1 on no match, whichset -ereads as failure and an all-added PR triggers, but|| truealso swallows grep's exit >1 on a real error, leaving the count empty — and[[ "" -eq 0 ]]is true in bash, so the guard would skip a PR it never managed to read and report it as "only adds new files". awk exits 0 with no matches and non-zero only on a real error, which pipefail turns into the loud failure it should be.Verified by extracting the step's run: block and executing it against live PRs with
gh pr commentstubbed (#2535 skips on both pull_request and issue_comment; #2507 skips only on pull_request; #2531 is unaffected), and against a synthetic API for the boundary and error paths (300 files pass, 301 skip, a failinggh apior an unreadable file aborts instead of silently skipping).