Skip to content

fix(attachment, github): Use fallback when diff is too large#642

Merged
JeanMertz merged 2 commits into
mainfrom
prr212
May 16, 2026
Merged

fix(attachment, github): Use fallback when diff is too large#642
JeanMertz merged 2 commits into
mainfrom
prr212

Conversation

@JeanMertz
Copy link
Copy Markdown
Collaborator

GitHub's unified-diff endpoint (application/vnd.github.diff) caps
responses at 20,000 lines and returns HTTP 406 beyond that. Previously,
jp would surface that as an opaque error, making large PRs unusable
via the gh:pr attachment URI.

When the 406 is detected, the handler now falls back to the paginated
/pulls/{N}/files endpoint and synthesizes a unified-diff-like blob
from the per-file DiffEntry records. Each file gets the standard diff --git a/PATH b/PATH header plus the patch hunks as returned by GitHub.
Renames and copies include the appropriate rename from/ rename to
(or copy from/copy to) markers so downstream consumers can still
identify the nature of each change.

When GitHub omits the patch field for a file (binary files or files
exceeding GitHub's per-file limit), a placeholder line is emitted that
surfaces the file status and line counts, ensuring the LLM still knows
the file was modified even without hunks.

The existing exclude-pattern logic applies equally to the fallback path,
so files like Cargo.lock or snapshot files are dropped before the
synthesized blob is assembled. A notice is injected into the PR header
whenever the fallback is used, including the count of patch-truncated
files when non-zero.

GitHub's unified-diff endpoint (`application/vnd.github.diff`) caps
responses at 20,000 lines and returns HTTP 406 beyond that. Previously,
`jp` would surface that as an opaque error, making large PRs unusable
via the `gh:pr` attachment URI.

When the 406 is detected, the handler now falls back to the paginated
`/pulls/{N}/files` endpoint and synthesizes a unified-diff-like blob
from the per-file `DiffEntry` records. Each file gets the standard `diff
--git a/PATH b/PATH` header plus the patch hunks as returned by GitHub.
Renames and copies include the appropriate `rename from`/ `rename to`
(or `copy from`/`copy to`) markers so downstream consumers can still
identify the nature of each change.

When GitHub omits the `patch` field for a file (binary files or files
exceeding GitHub's per-file limit), a placeholder line is emitted that
surfaces the file status and line counts, ensuring the LLM still knows
the file was modified even without hunks.

The existing exclude-pattern logic applies equally to the fallback path,
so files like `Cargo.lock` or snapshot files are dropped before the
synthesized blob is assembled. A notice is injected into the PR header
whenever the fallback is used, including the count of patch-truncated
files when non-zero.

Signed-off-by: Jean Mertz <git@jeanmertz.com>
@JeanMertz JeanMertz changed the base branch from prr211 to main May 15, 2026 21:37
Signed-off-by: Jean Mertz <git@jeanmertz.com>
@JeanMertz JeanMertz merged commit 69a521d into main May 16, 2026
14 checks passed
@JeanMertz JeanMertz deleted the prr212 branch May 16, 2026 06:16
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