feat(mobile): upload attachments to cloud storage instead of through the relay

Merged
SA
2mo ago
+1820-121

The bug

James attached a 100 MB zip from Files and got:

fetch failed: UnexpectedException: cannot parse response (at ExpoModulesCore/Promise.swift:56)

Reproduced against the production relay: Cloudflare's edge rejects a request body over 100 MB with an HTML 413, and returns it ~2 MB into the upload. The client is still writing when the server answers and closes, which NSURLSession surfaces as NSURLErrorCannotParseResponse. The composer then printed that verbatim.

Mobile enforced no attachment limit anywhere, and its two paths disagreed:

PathTransportCap
Home composerattachments.upload, base64 in JSON25 MB (host-side)
Workspace composerfilesystem.writeFile, base64 in JSONnone

Base64 inflates by 4/3, so a 100 MB file became a ~133 MB body. James hit the unbounded one.

The change

Attachments go device → R2 → host. The bytes never touch the relay or our API in either direction.

  • attachment.createUpload records a pending files row and returns a presigned PUT against the private bucket (1h TTL, signature covering content-type and content-length).
  • The device streams to it with File.upload — native, never in the JS heap, continues when iOS backgrounds the app.
  • What crosses the relay on send is a list of file ids.
  • The host calls attachment.resolve, which HEADs each object against its declared size and returns presigned GETs, then streams R2 → disk itself.

Uploads start when a file is attached, not when the message is sent, so the transfer overlaps composing. The tray draws a progress arc while one runs, and a destructive mark if it fails; sending clears the error and retries rather than making you re-pick.

Agents are unaffected — they still get the same worktree-relative .superset/attachments/... paths.

Retention

The files row stays pending for its whole life. The object is a transfer buffer, dead once the host has written it into the worktree, and pending is exactly what the existing 24h sweep reclaims. Its empty sha256 is the marker: every other file is identified by content digest, so an empty one keeps attachments out of page-asset reuse lookups and is what resolve filters on. Without that filter any file id in the organization could be handed a signed URL, a page's private assets included.

No migration — deliberately. An attachments parent row would point at a workspace id minted client-side that the cloud DB never sees, so it would not buy the reap-on-delete story that would justify it.

Verified

Against a local API + MinIO, with a simulator:

  • 147 MB upload from the app, progress ring captured mid-flight
  • 5 MB round trip returned byte-identical (sha 3d67f169fdf8556e both ways)
  • 209,715,201 → too_big (max 209,715,200)
  • Bytes never PUT → "Attachment was not uploaded — send the bytes first"
  • Same file id and org, digest flipped → resolve refuses

Repo typecheck 38/38, check:i18n green with all 16 locales translated, mobile/host-service/shared/i18n suites pass, and the Composer pod scheme builds.

Screenshots and evidence: https://claude.ai/code/artifact/67277efa-b7b7-496e-9eb1-6ec0b2ffcba4

Worth a reviewer's attention

  • Old hosts lose attachments until they update. There is no base64 fallback — an older host-service gets "Update Superset on this machine to attach files". One path instead of two, but it is a regression for anyone on an older desktop. Happy to add the fallback if you would rather.
  • 200 MB per file, 10 per send (@superset/shared/attachment-limits). Transport no longer constrains it; what bounds it is that the bytes land in someone's worktree.
  • The host's old inline cap was renamed MAX_INLINE_ATTACHMENT_BYTES (still 25 MB, still used by desktop and the CLI) so it no longer collides with the new shared constant.

Known gaps, not fixed

  • The tray does not scroll to a newly added attachment, so on a full tray the newest file's ring can sit off-screen. Two lines to change, but the carousel documents "adding an item never moves the offset" as deliberate — a decision to reverse rather than a bug to patch.
  • The collapsed composer shows no progress; its pill draws its own thumbnail and never receives progress.

https://claude.ai/code/session_01L5RZ86YCC4rehoJgfwjb1k


Summary by cubic

Fixes mobile attachment uploads over ~75 MB failing when sent through the relay, whose Cloudflare edge rejects request bodies over 100 MB. Attachments now stream device → R2 → host over presigned URLs — never through the relay as base64 JSON — and uploads begin when a file is picked, overlapping composing, with a progress ring or failure mark on the thumbnail.

Migration

  • Hosts on older desktop versions can't attach files until updated; they get "Update Superset on this machine to attach files" since there's no base64 fallback.

Details

  • Limits are 200 MB per file and 10 per send, enforced at pick time.
  • Uploaded bytes are kept per draft, so a send or a retried failed workspace create reuses the same file ids instead of re-uploading.
  • resolve only signs URLs for transfer-only rows (empty sha256), so other org files can't be fetched with a file id; those files rows stay pending so the 24-hour sweep reclaims them, no migration needed.
  • The composer refuses to send while an upload runs (spinner, no mic) so the tap isn't swallowed; a failed upload keeps the arrow because sending retries it. The iOS accent is now dark since iOS 26 fills system controls with it; the composer and text inputs state their own colors.
  • Progress is throttled to half-percent changes and the ring animates linearly, so it creeps at a constant speed without re-rendering the tray on every iOS report.
  • Sends are locked before awaiting uploads, the cap reads the store rather than the rendered list, and filename claims are exclusive — closing double-tap, double-add, and name-collision races.
  • Tests cover the upload settle/retry logic and attachment filename claiming; the overwrite collision test now actually asserts its result.
  • Known gaps: the tray doesn't scroll to newly added attachments, and the collapsed composer shows no progress.

Summary by CodeRabbit

  • New Features
    • Added direct attachment uploads with progress tracking, cancellation, retry support, and clear failure states.
    • Attachments remain available across chats and workspaces during sending and retries.
    • Added secure transfer of attachments into workspaces.
  • Bug Fixes
    • Improved handling of unavailable attachments and older host versions with actionable messages.
  • User Experience
    • Added validation for 200 MB file-size and 10-attachment limits.
    • Added localized attachment status, error, limit, and update messages across supported languages.