Repository navigation
fix(attachments): attach files up to 32 MB and always answer an oversize upload with its reason - #1071
Conversation
…ize upload with its reason The ceiling was 8 MiB, and a body past Bun's 128 MiB default got an empty 413 the browser could not explain. MAX_ATTACHMENT_BYTES is now 32 MiB, Bun.serve admits bodies up to 64 MiB, and POST /api/pane/image reads its body with its own bound (announced length, then a running byte count) so an oversize upload answers 413 image_too_large as JSON. The browser still refuses a file over the limit before it uploads. Fixes #445
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Summary
Merge Risk: ⚪ Minimal · up to
|
Review of #1071: the browser regression still built its oversize file as 8 MiB + 1 byte, which the new 32 MiB limit accepts, so CI failed waiting for the size note. Size it from MAX_ATTACHMENT_BYTES, and word the changelog fragment for files picked in the browser (the server's own body ceiling still answers a bare 413).
Fixes #445
Root cause
shared/attachments.ts:7capped an attachment at 8 MiB (MAX_ATTACHMENT_BYTES = 8 * 1024 * 1024), checked by the browser before upload and again inserver/paste.ts:85-93, so a 20 MB file was refused.POST /api/pane/imageread its body withrequest.json()(server/index.ts:2666) under Bun.serve's default body limit (server/index.ts:1670, nomaxRequestBodySize): a body past that limit got Bun's own empty 413, and a chunked body that announced no length was not bounded by the route (it ended asinvalid_json).What changed
MAX_ATTACHMENT_BYTESis 32 MiB (shared/attachments.ts). The browser pre-check insrc/lib/api.tsreads it, so the composer refuses a larger file before it uploads and names the 32 MB limit.server/paste.tsaddsreadImageBody: the route refuses a body pastMAX_IMAGE_BODY_BYTES(base64 of 32 MiB plus a 1 MiB envelope) by itscontent-lengthfirst and by a running byte count for a chunked body, answering 413{ error: { code: "image_too_large", message } }.Bun.servesetsmaxRequestBodySizeto 64 MiB (BUN_BODY_CEILING), above the route's bound. Only a non-browser client sending more than 64 MiB still sees Bun's empty 413 (documented inserver/index.tsandshared/AGENTS.md). That cap applies to every route; the only other large-body route, voice transcription, keeps its own lower bound.docs/guide.md(8 MB -> 32 MB),server/AGENTS.mdandshared/AGENTS.md; changelog fragmentchangelog.d/attachment-limit-32-mb.md.Tests
server/api.contract.test.ts(POST /api/pane/image):image_too_largeand a message.invalid_json): a chunked body with no length is counted and refused past the bound with 413 JSON.handleMachineRequest) returns 200.src/lib/api.test.ts:Evidence (independent re-run)
image_too_largeJSON; a 70 MiB body (non-browser, over the 64 MiB cap) -> Bun's empty 413, as documented.@pathmention in the draft. The Korean UI shows the translated message. No horizontal scroll at 390 wide, no page errors or CSP violations, and the same pre-existing harness 404s (/api/telemetry, /api/worktree/list, /api/fs/stat) appear before and after. No CSS changes.Checks run
bun run typecheck: exit 0HERDR_TEST_MODE=unit bun teston api, paste, machine-proxy, machines, server conventions and changelog-fold tests: 75 pass, 0 failbun run test:unit: 3516 pass, 0 fail, 8 skipbun test ./server/api.contract.test.ts -t 'POST /api/pane/image'on an isolated herdr session: 9 pass, 0 fail