Skip to content

fix: reconstruct diff from per-file patches when GitHub 406s on large PRs - #61

Open
jainakshay93 wants to merge 1 commit into
Agent-Field:mainfrom
jainakshay93:fix/large-pr-diff-406-fallback
Open

fix: reconstruct diff from per-file patches when GitHub 406s on large PRs#61
jainakshay93 wants to merge 1 commit into
Agent-Field:mainfrom
jainakshay93:fix/large-pr-diff-406-fallback

Conversation

@jainakshay93

Copy link
Copy Markdown

Problem

_fetch_pr_once fetches the PR diff via Accept: application/vnd.github.v3.diff. GitHub returns 406 Not Acceptable when the diff is too large to generate — reproduced on a 722-file PR. diff_resp.raise_for_status() then aborts the whole review, so large PRs can't be reviewed at all.

Fix

The per-file patches are already fetched from the /pulls/{n}/files API a few lines above. On a 406, reconstruct an equivalent unified diff from those patches instead of failing:

except httpx.HTTPStatusError as exc:
    if exc.response.status_code != 406:
        raise
    full_diff = "\n".join(
        f"diff --git a/{f.path} b/{f.path}\n--- a/{f.path}\n+++ b/{f.path}\n{f.patch}"
        for f in changed_files if f.patch
    )

Small/normal PRs are unchanged — the real .diff media type is still used whenever it succeeds.

Testing

A 722-file PR that previously 406'd now fetches (≈3.5 MB reconstructed diff) and reviews to completion.

Note

GitHub's /files API caps at 3000 files and omits patch for individually huge files, so extreme PRs may have partial diffs — but a partial diff is strictly better than a hard failure.

🤖 Generated with Claude Code

… PRs

_fetch_pr_once fetches the diff via the .diff media type, which GitHub
406s when the diff is too large (e.g. 722-file PR), aborting the review.
On 406, rebuild the unified diff from the per-file patches already
fetched from the /files API.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant