Skip to content

fix(attachments): attach files up to 32 MB and always answer an oversize upload with its reason - #1071

Merged
devswha merged 2 commits into
mainfrom
fix/attachment-limit-and-413
Oct 14, 2026
Merged

devswha merged 2 commits into
mainfrom
fix/attachment-limit-and-413

Conversation

@devswha

@devswha devswha commented Oct 14, 2026

Copy link
Copy Markdown
Owner

Fixes #445

Root cause

  • shared/attachments.ts:7 capped an attachment at 8 MiB (MAX_ATTACHMENT_BYTES = 8 * 1024 * 1024), checked by the browser before upload and again in server/paste.ts:85-93, so a 20 MB file was refused.
  • POST /api/pane/image read its body with request.json() (server/index.ts:2666) under Bun.serve's default body limit (server/index.ts:1670, no maxRequestBodySize): 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 as invalid_json).

What changed

  • MAX_ATTACHMENT_BYTES is 32 MiB (shared/attachments.ts). The browser pre-check in src/lib/api.ts reads it, so the composer refuses a larger file before it uploads and names the 32 MB limit.
  • server/paste.ts adds readImageBody: the route refuses a body past MAX_IMAGE_BODY_BYTES (base64 of 32 MiB plus a 1 MiB envelope) by its content-length first and by a running byte count for a chunked body, answering 413 { error: { code: "image_too_large", message } }.
  • Bun.serve sets maxRequestBodySize to 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 in server/index.ts and shared/AGENTS.md). That cap applies to every route; the only other large-body route, voice transcription, keeps its own lower bound.
  • Docs: docs/guide.md (8 MB -> 32 MB), server/AGENTS.md and shared/AGENTS.md; changelog fragment changelog.d/attachment-limit-32-mb.md.

Tests

server/api.contract.test.ts (POST /api/pane/image):

  • regression (fails on main: 413): a 20 MiB file is stored whole, 200.
  • control: a 40 MiB file (55.9 MB body) gets 413 with image_too_large and a message.
  • regression (fails on main: 400 invalid_json): a chunked body with no length is counted and refused past the bound with 413 JSON.
  • regression (fails on main: 413): a 20 MiB upload through the PC proxy route (handleMachineRequest) returns 200.

src/lib/api.test.ts:

  • regression (fails on main: message says 8 MB): a 40 MiB file is refused in the browser before any upload, naming 32 MB.

Evidence (independent re-run)

  • The new tests run against main's product code: the 4 regression cases fail and the control passes. On this branch all 9 image-route tests pass, and they also pass with the branch merged onto the latest main.
  • curl -i against a running server: 20 MiB file -> 200; 40 MiB file, ceiling+1 (32 MiB + 1 B) and a 60 MiB body -> 413 image_too_large JSON; a 70 MiB body (non-browser, over the 64 MiB cap) -> Bun's empty 413, as documented.
  • Chromium at 1280x800 and 390x844 (390 with mobile emulation), light and dark: attaching a 40 MiB file shows "Too large to attach: backup.zip (40 MB). A file can be up to 32 MB." (before: "up to 8 MB."). A 20 MiB file attaches with no error and its @path mention 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 0
  • HERDR_TEST_MODE=unit bun test on api, paste, machine-proxy, machines, server conventions and changelog-fold tests: 75 pass, 0 fail
  • bun run test:unit: 3516 pass, 0 fail, 8 skip
  • bun test ./server/api.contract.test.ts -t 'POST /api/pane/image' on an isolated herdr session: 9 pass, 0 fail

…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
@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: devswha/herdr-web-ui/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2ebe3cc5-f324-4348-a763-570d065128a8
📥 Commits

Reviewing files that changed from the base of the PR and between 454fc7b and 11bbb79.

📒 Files selected for processing: 10
  • changelog.d/attachment-limit-32-mb.md
  • docs/guide.md
  • scripts/ui-regression.ts
  • server/AGENTS.md
  • server/api.contract.test.ts
  • server/index.ts
  • server/paste.ts
  • shared/AGENTS.md
  • shared/attachments.ts
  • src/lib/api.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.

📝 Summary

Summary by CodeRabbit

  • New Features

    • Increased the attachment size limit from 8 MB to 32 MB for files and images.
  • Bug Fixes

    • Files that exceed the limit are now rejected with a clear size message instead of an unexplained upload error.

The composer attachment limit increases from 8 MiB to 32 MiB. The image-upload route now bounds request-body reading and returns a specific 413 error for oversized bodies. Tests cover successful larger uploads and oversized uploads.

Changes: Attachment upload limits

Layer / File(s) Summary
Raise and share the attachment limit
shared/attachments.ts, src/lib/api.test.ts, scripts/ui-regression.ts, docs/guide.md, changelog.d/attachment-limit-32-mb.md
The shared limit increases to 32 MiB. The browser regression test checks that an oversized file is refused before upload, and the UI test fixture uses the shared limit. The guide and changelog state the new limit.
Bound image-upload request bodies
server/paste.ts, server/index.ts, server/api.contract.test.ts, server/AGENTS.md, shared/AGENTS.md
The image route reads request bodies with a configured bound and returns the image_too_large 413 error when the bound is exceeded. Bun’s request-body ceiling is set to 64 MiB. Contract tests cover successful 20 MiB uploads and oversized uploads, including a streamed request without a declared content length.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: haeminway1

Merge Risk: ⚪ Minimal · up to 11bbb

The larger attachment limit and oversized-upload handling appear ready to merge after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 6 files. (4 skipped: 4… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly summarizes the main changes: increasing attachment limits to 32 MB and returning a reason for oversized uploads.
Description check Passed The description explains the root cause, resulting behavior, implementation, validation, contract-test coverage, and reported test results. It uses different headings from the template, but it provide…
Linked Issues check Passed Issue [#445] requires a higher attachment limit or another upload path and a useful response for oversized uploads. The PR raises MAX_ATTACHMENT_BYTES to 32 MiB, applies the shared limit in the brow…
Out of Scope Changes check Passed The changes stay within issue [#445]. The implementation, contract tests, browser regression test, shared guidance, server guidance, user guide, UI fixture update, and changelog all support the attach…
Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 6 files. (4 skipped: 4 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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).
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.

Attachments stop at 8 MB; a larger file needs a higher limit or another upload path

1 participant