paperclipai/paperclip · error · GitHubAttachmentUnavailableError
github_attachment_canonical_api_too_large
github_attachment_canonical_api_too_large
Error message
github_attachment_canonical_api_too_large
What it means
While streaming the canonical GitHub API response body, githubAttachmentCommentFetch accumulates bytes and aborts with GitHubAttachmentUnavailableError('github_attachment_canonical_api_too_large') as soon as the cumulative size exceeds MAX_COMMENT_RESPONSE_BYTES. This guards against a lying or absent Content-Length and caps memory use before the body is parsed.
Source
Thrown at server/src/services/chat-github-attachments.ts:500
: "github_attachment_canonical_api_invalid_response",
);
}
const reader = response.body.getReader();
const chunks: Uint8Array[] = [];
let size = 0;
const cancel = () => {
void reader.cancel().catch(() => undefined);
};
signal.addEventListener("abort", cancel, { once: true });
try {
for (;;) {
signal.throwIfAborted();
const next = await reader.read();
signal.throwIfAborted();
if (next.done) break;
size += next.value.byteLength;
if (size > MAX_COMMENT_RESPONSE_BYTES)
throw new GitHubAttachmentUnavailableError(
"github_attachment_canonical_api_too_large",
);
chunks.push(next.value);
}
} finally {
signal.removeEventListener("abort", cancel);
await reader.cancel().catch(() => undefined);
}
return new Response(Buffer.concat(chunks), {
status: 200,
headers: { "content-type": "application/json" },
});
};
}
/**
* The authenticated rendering is evidence only for this exact unchanged source.
* We support GitHub's image anchor mapping, not arbitrary HTML URL extraction.View on GitHub (pinned to 01ad858492)
Solutions
- Reduce the comment size on GitHub (shorten body, remove large HTML blocks) and re-attach the file.
- Check the server's MAX_COMMENT_RESPONSE_BYTES configuration if large attachments are legitimate for your deployment.
- If the Content-Length header check passed but the stream still overflowed, verify the proxy/upstream is not inflating the response (e.g. injecting content or re-encoding).
Example fix
// before: trusting Content-Length alone
if (Number(res.headers.get('content-length') ?? 0) > MAX) throw new TooLarge();
// after: also enforce the cap while streaming
let size = 0;
for await (const chunk of res.body) { size += chunk.byteLength; if (size > MAX) throw new TooLarge(); } Defensive patterns
Strategy: try-catch
Try / catch
try {
const value = await fetchCanonicalComment(url, signal);
} catch (e) {
if (e instanceof GitHubAttachmentUnavailableError && e.code === 'github_attachment_canonical_api_too_large') {
log.warn('comment response exceeded byte cap', { url });
return { kind: 'unavailable', reason: 'too_large' };
}
throw e;
} Prevention
- Keep comment bodies modest; strip or avoid pasting very large HTML/blocks into the source comment.
- Remember the cap applies twice: on the declared Content-Length and again on the streamed byte count — a missing/chunked Content-Length only fails at the stream stage.
- If large responses are legitimate, raise MAX_COMMENT_RESPONSE_BYTES deliberately, not silently.
- Monitor for upstreams/proxies that strip Content-Length (chunked encoding) to know the header pre-check will not protect you.
When it happens
Trigger: The streamed body of the canonical comment API response exceeds MAX_COMMENT_RESPONSE_BYTES mid-read, either because Content-Length was absent/incorrect (chunked transfer) or because the comment payload genuinely grew beyond the cap between the header check and the stream.
Common situations: A very large comment body or HTML rendering pushed a comment past the byte cap; a compromised/misbehaving upstream sends chunked data without Content-Length, bypassing the header check but hitting the stream counter.
Understand the failure class
Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.
Related errors
- The bridge host reached its reserved process body byte ceili
- OpenCode event stream returned HTTP ${response.status}
- OpenCode SSE event exceeded the retained payload limit
- github_attachment_canonical_api_access_denied | github_attac
- github_attachment_empty
AI-assisted analysis of paperclipai/paperclip@01ad858492 (2026-09-10).
Data as JSON: /api/errors/679b9b6e738595bd.
Report an issue: GitHub.