Fix silent failure on large PRs (406 diff too large)#82
Open
MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
Open
Fix silent failure on large PRs (406 diff too large)#82MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
Conversation
When the GitHub API returns HTTP 406 for diffs exceeding the 20,000-line limit, the action previously swallowed the error and reported 0 findings, giving a false sense of security. This fix: - Detects the 406 response in get_pr_diff() and falls back to local git diff (origin/base...HEAD, then HEAD~1) - If local diff also fails, raises DiffTooLargeError with a structured JSON output including scan_status: "incomplete" and skip_reason - Updates action.yml to detect incomplete scans and surface them as ::error:: annotations instead of silently passing Fixes anthropics#80 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
Fixes #80 — When a PR's unified diff exceeds GitHub's 20,000-line API limit, the action silently reports 0 findings instead of surfacing the error. This gives a false sense of security since the PR appears clean when no analysis actually occurred.
Changes
get_pr_diff()— Instead of lettingraise_for_status()throw a generic error that gets swallowed, we now explicitly check for status 406 and fall back gracefullygit diff— When the API returns 406, we rungit diff origin/<base_ref>...HEADlocally (the action already checks out code), falling back togit diff HEAD~1if neededDiffTooLargeErrorexception — Raised only when both the API and all local diff fallbacks failscan_status: "incomplete"andskip_reason: "diff_too_large"instead of an empty findings listaction.yml— The shell wrapper now detectsscan_status == "incomplete"and emits::error::annotations so the failure is visible in the GitHub Actions UI (instead of silently passing with 0 findings)How it works
get_pr_diff()requests the diff from GitHub API_get_local_diff(base_ref)which tries:git diff origin/main...HEAD(using PR's actual base branch)git diff HEAD~1(fallback)DiffTooLargeError,main()outputs structured error JSON,action.ymlsurfaces it as an error annotationTests
Added 9 new tests (176 total pass):
origin/base...HEADbeforeHEAD~1HEAD~1when base ref failsHEAD~1)DiffTooLargeErrorwhen all fallbacks failmain()produces structured incomplete scan output forDiffTooLargeErrorTest plan