Skip to content

Reject HEIC/HEIF attachment uploads with a reason - #2170

Merged
SawyerHood merged 2 commits into
mainfrom
bb/fix-1670-heic-images
Aug 21, 2026
Merged

SawyerHood merged 2 commits into
mainfrom
bb/fix-1670-heic-images

Conversation

@SawyerHood

@SawyerHood SawyerHood commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator

What was wrong

POST /api/v1/projects/:id/attachments stored and served a pasted or dropped .heic file verbatim and classified it as a localImage because its MIME type starts with image/. Nothing downstream can decode HEIC/HEIF: Chromium (the web app and the Electron shell) ships no HEVC decoder, so the composer thumbnail and the timeline <img> showed the broken-image glyph, and no provider image input accepts HEIC either (Codex replaced it with "image content omitted because it could not be processed"). The user saw a broken picture and the model silently received nothing. Issue: #1670. Report: https://get-bb.github.io/reports/issues/1670.html

This PR is a stopgap, not the rendering fix the issue asks for. Rendering HEIC requires an HEVC decoder that bb does not have. The only portable option is libheif/libde265 compiled to WASM (libheif-js, LGPL-3.0, ~1.4 MB, a patent-encumbered codec that Chromium itself declines to ship), run either in the browser before upload or in the server process (where a 12 MP photo blocks the event loop for about two seconds unless it moves to a worker; measured 0.1 s decode + 0.1 s encode for a 1.4 MP sample). That dependency and placement decision belongs to the maintainers, so this PR does the safe part: it turns the silent failure into an immediate, explained refusal. The issue stays open for the transcoding work (Refs, not Fixes).

What changed

  • apps/server/src/services/projects/attachments.ts: storeAttachment refuses uploads whose MIME type is image/heic, image/heif, or their -sequence variants with 400 invalid_request and the message HEIC images are not supported. Convert the image to JPEG or PNG before attaching it. This is exactly the set of uploads that used to become a broken localImage: Chromium labels a pasted or dropped .heic image/heic, and bb project attachment upload infers the same from the extension. The same bytes sent with a non-image MIME type (for example --mime-type application/octet-stream) still store as a plain localFile, as on main, so a user can hand the raw file to an agent that converts it on the host. Every client (web, desktop, mobile document picker, CLI, SDK) gets the same answer. No wire change between server and daemon.
  • apps/app/src/components/thread/embedded-chat/useComposerAttachmentUploads.ts: the follow-up and queued-message composers now show the server's reason (Failed to attach IMG_0001.heic: HEIC images are not supported. ...) instead of a bare Failed to attach: IMG_0001.heic. The new-thread composer already did this through getMutationErrorMessage; this brings the other composers in line. Transport errors keep the old generic text.
  • CLI guide template (packages/templates/src/templates/bb-guide-projects.md) and the bb-cli skill (apps/server/src/services/skills/builtin-skills/bb-cli/SKILL.md) mention that image/heic and image/heif uploads are rejected.

Revision after review: the first version also rejected by .heic/.heif extension alone, which blocked the explicit non-image upload path that main handled correctly as a localFile. The rejection is now MIME-only and the test pins the localFile path.

Not included: an onError fallback tile in AttachmentPreview/ConversationAttachments for threads that already hold HEIC localImage attachments. That is a general broken-image UI concern, independent of HEIC, and is left for a follow-up.

Deviation from the report's proposed fix: it proposed transcoding HEIC to JPEG at upload with a WASM decoder. Not done here for the reasons above. If the maintainers want HEIC to just work, the smallest follow-up is a browser-side conversion before upload (decode with libheif-js, encode with OffscreenCanvas.convertToBlob("image/jpeg")), mirroring the mobile app, which already asks the iOS picker for JPEG instead of HEIC. The server check then stays as the backstop for programmatic uploads.

How you verified

New tests, both fail on origin/main and pass here:

  • apps/server/test/public/public-project-attachments.test.ts > rejects HEIC/HEIF image uploads instead of storing an image nothing can render. With attachments.ts reverted to origin/main: AssertionError: expected 201 to be 400 (the HEIC was stored as a localImage). It also asserts that image/heif; charset=binary is rejected and that the same bytes as application/octet-stream return 201 {"type":"localFile"}.
  • apps/app/src/components/thread/embedded-chat/useComposerAttachmentUploads.test.tsx > shows the server's reason when it refuses an upload. On main: Expected: "Failed to attach IMG_0001.heic, shot.png: HEIC images are not supported. ...", Received: "Failed to attach: IMG_0001.heic, shot.png".

Run from the committed tree at d28f3fc34 (git status --porcelain empty, origin/main at f6fb434ab):

  • pnpm exec turbo run typecheck --filter=@bb/server --filter=@bb/app --filter=@bb/templates --filter=@bb/cli: Tasks: 7 successful, 7 total.
  • pnpm exec turbo run test --filter=@bb/server --filter=@bb/templates --filter=@bb/cli: cli 48/48 files; templates 6/6 files; server 193/195 files. The two server failures are unrelated to this change: internal-skill-trees.test.ts asserts file mode 0644 and gets 0664 on this workstation's umask 0002 (fails identically on clean main, passes in CI), and plugin-update.test.ts > waits one full interval when no plugins are eligible for update checks hit its 5 s timeout under a load average of 35; it passes alone with --testTimeout=60000 (test body 1.9 s).
  • pnpm exec turbo run test --filter=@bb/app: 409 passed (409) files, 3157 passed | 3 skipped; vitest also reported one unhandled post-teardown timer from ThreadTimelineRows.windowing.test.tsx (document is not defined in useScrollToSearchedMessage.ts), a file this PR does not touch; that file and the composer test pass cleanly when re-run together.

Manual, on a dev instance of this branch, re-running the report's repro:

  • curl -F "[email protected];type=image/heic" .../attachments (nokia autumn_1440x960.heic) returns 400 {"code":"invalid_request","message":"HEIC images are not supported. Convert the image to JPEG or PNG before attaching it."}; type=image/heif with an IMG.HEIF filename is also rejected; type=application/octet-stream returns 201 {"type":"localFile",...}; a PNG returns 201 {"type":"localImage",...}.
  • bb project attachment upload <project> --client-file sample.heic (MIME inferred from the extension) prints Error: HTTP 400: HEIC images are not supported. ...; with --mime-type application/octet-stream it prints Attachment uploaded: sample-...heic.
  • Headless Chromium paste of the real HEIC File into the new-thread composer and into a thread's follow-up composer (first revision; the app code and the image/heic server response are unchanged since): no <img> is created, and the composer shows the reason inline.

Refs #1670

AGENT GENERATED: by Claude Opus 5

Independent verification

Verified round 2 on d28f3fc34 (merge-base with origin/main f6fb434ab; origin/main has since gained only the unrelated c942421a4), in a separate worktree with its own dev instance.

Commands and results:

  • git checkout origin/main -- apps/app/src/components/thread/embedded-chat/useComposerAttachmentUploads.ts apps/server/src/services/projects/attachments.ts, then pnpm exec vitest run test/public/public-project-attachments.test.ts (apps/server): AssertionError: expected 201 to be 400 in rejects HEIC/HEIF image uploads instead of storing an image nothing can render (1 failed | 3 passed). pnpm exec vitest run src/components/thread/embedded-chat/useComposerAttachmentUploads.test.tsx (apps/app): Expected: "Failed to attach IMG_0001.heic, shot.png: HEIC images are not supported. ...", Received: "Failed to attach: IMG_0001.heic, shot.png" (1 failed | 3 passed).
  • git checkout HEAD -- <same files>: both files 4/4 pass.
  • pnpm exec turbo run typecheck --filter=@bb/server --filter=@bb/app --filter=@bb/templates --filter=@bb/cli: Tasks: 7 successful, 7 total.
  • pnpm exec turbo run test --filter=@bb/server --filter=@bb/templates --filter=@bb/cli --filter=@bb/app --force: app 409/409 files, cli 48/48, templates 6/6, server 194/195 files (1823/1824 tests). The one failure is internal-skill-trees.test.ts (0644 vs 0664 file mode under umask 0002), a known local-only failure unrelated to this PR.
  • Repro on the fixed branch (own dev instance, nokia autumn_1440x960.heic): curl -F "[email protected];type=image/heic" -> 400 {"code":"invalid_request","message":"HEIC images are not supported. ..."}; type=image/heif -> 400; type="Image/HEIC; charset=binary" -> 400; type=application/octet-stream -> 201 {"type":"localFile",...}; no explicit type (curl default octet-stream) -> 201 localFile; PNG -> 201 {"type":"localImage",...}. bb project attachment upload <proj> --client-file sample.heic -> Error: HTTP 400: HEIC images are not supported...; with --mime-type application/octet-stream -> Attachment uploaded: sample-...heic.
  • Headless Chromium paste of a real image/heic File into the new-thread composer and into a thread's follow-up composer: no <img> pointing at /attachments/content is created; the new-thread composer shows HEIC images are not supported. Convert the image to JPEG or PNG before attaching it. inline and the follow-up composer shows Failed to attach IMG_0001.heic: HEIC images are not supported. .... The original broken-thumbnail symptom no longer reproduces.
  • Checked that storeAttachment has a single caller (the upload route), that the mobile document picker surfaces the 400 through its BbHttpError toast, and that the mobile photo picker already requests JPEG for HEIC assets, so the new server policy matches the existing mobile stance.
  • CI: all checks green (Checks, Package Smoke ubuntu/macos, Tests app-1/2/3, integration, packages, server).

Residual risks (acknowledged by the PR): HEIC still cannot be attached as an image until a transcoder lands (issue stays open via Refs); existing threads with stored HEIC localImage attachments still render the broken-image glyph; HEIC bytes uploaded with a misleading non-HEIC image MIME type are not sniffed. Minor doc gap: the bb-plugin-authoring skill's SDK attachment paragraph mentions the size caps but not the HEIC rejection.

AGENT GENERATED: by Claude Opus 5

SawyerHood and others added 2 commits August 21, 2026 07:03
Chromium (web app and Electron shell) has no HEVC decoder and no provider
image input accepts HEIC, but the server stored and served pasted iPhone
photos verbatim as a localImage. The composer and timeline showed a broken
thumbnail and the model silently received nothing.

bb ships no HEIF transcoder, so the server now refuses HEIC/HEIF uploads
(by MIME type or extension) with an actionable 400, and the composer shows
the server's reason instead of a bare "Failed to attach".

Co-Authored-By: Claude <[email protected]>
Extension-only HEIC uploads with a non-image MIME type were stored as a
plain localFile on main, which is not the broken case; keep that path so
a user can still hand the raw file to an agent. Refuse only the
image/heic and image/heif classifications that produced a broken
thumbnail and an image the model never received.

Co-Authored-By: Claude <[email protected]>
@SawyerHood
SawyerHood marked this pull request as ready for review August 21, 2026 07:44
@SawyerHood
SawyerHood merged commit e0175eb into main Aug 21, 2026
13 checks passed
@SawyerHood
SawyerHood deleted the bb/fix-1670-heic-images branch August 21, 2026 14:39
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