can1357/oh-my-pi · error · HTTPException
request body too large
Error message
request body too large
What it means
When the declared Content-Length exceeds settings.gh_proxy_max_body_bytes, the proxy rejects the request up front with HTTP 413 'request body too large'. This is the header-based early check in _read_body_capped; a separate streaming check (errorIndex 3966) catches bodies whose actual size exceeds the cap.
Source
Thrown at python/robomp/src/proxy/server.py:425
async def _read_body_capped(request: Request) -> bytes:
"""Read the request body with a hard byte cap.
Checks `Content-Length` first (cheap reject before any read), then
streams chunks via `request.stream()` with a running counter so a
client that lies about (or omits) the header still can't get more
than `max_bytes` into memory. We deliberately do NOT call
`request.body()` first — that would buffer the full payload before
auth checks ever run.
"""
max_bytes = settings.gh_proxy_max_body_bytes
cl = request.headers.get("content-length")
if cl is not None:
try:
declared = int(cl)
except ValueError as exc:
raise HTTPException(400, "invalid content-length") from exc
if declared > max_bytes:
raise HTTPException(status.HTTP_413_REQUEST_ENTITY_TOO_LARGE, "request body too large")
chunks: list[bytes] = []
total = 0
async for chunk in request.stream():
if not chunk:
continue
total += len(chunk)
if total > max_bytes:
raise HTTPException(status.HTTP_413_REQUEST_ENTITY_TOO_LARGE, "request body too large")
chunks.append(chunk)
body = b"".join(chunks)
# Starlette's `request.body()` / `request.json()` re-read from
# `request._body`. We consumed the stream above, so seed the cache
# to keep downstream JSON parsing working without a second read.
request._body = body # type: ignore[attr-defined]
return body
async def _authenticate(request: Request) -> bytes:
body = await _read_body_capped(request)View on GitHub (pinned to 9690622007)
Solutions
- Shrink the request payload (split into multiple smaller calls, truncate embedded content)
- If the limit is genuinely too small, raise gh_proxy_max_body_bytes in the proxy settings
- Compress content externally (e.g. paste a link instead of inlining large text)
Example fix
// before
await post("/gh/v1/post_comment", { body: hugeText });
// after
const summary = hugeText.slice(0, 5000);
await post("/gh/v1/post_comment", { body: summary }); Defensive patterns
Strategy: validation
Validate before calling
const MAX = settings.gh_proxy_max_body_bytes; // obtain configured limit
if (Buffer.byteLength(payload) > MAX) throw new Error(`body ${Buffer.byteLength(payload)}B exceeds ${MAX}B cap`); Try / catch
try {
const res = await fetch(url, opts);
if (res.status === 413) throw new Error("request body too large: split or shrink the payload");
} catch (err) { /* handle */ } Prevention
- Check payload size before every write call
- Split large content into multiple requests
- Know the configured gh_proxy_max_body_bytes and enforce it client-side
When it happens
Trigger: POSTing (e.g. post_comment, open_pull_request) with a JSON body whose Content-Length header is larger than gh_proxy_max_body_bytes.
Common situations: Attaching huge payloads by mistake (embedding file contents in a comment); a batch script concatenating many items into one request; misconfigured gateway forwarding compressed+uncompressed duplicates; too-low server limit for legitimate payloads.
Related errors
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/5835c9107da921db.
Report an issue: GitHub.