Repository navigation
Attach a large file over a slow connection: upload it in parts - #2971
Open
davidmckayv wants to merge 6 commits into
Open
davidmckayv wants to merge 6 commits into
davidmckayv wants to merge 6 commits into
Conversation
A file attached in one request has to reach the server inside the edge's request timeout. Over a slow upload link a file of a few megabytes can't, however often it is tried. createAttachmentUpload, uploadAttachmentPart and completeAttachmentUpload send it in parts of a size the server chooses, each short enough to arrive, and cancelAttachmentUpload stops one. The deployment says attachmentUploadsInParts where they are served. The one-request uploadConversationAttachment is unchanged.
… again by itself On a slow upload link no file over a few megabytes could be attached: the whole file went up in one request, and the edge in front of OpenBot Cloud closes any request whose body takes more than 125 seconds to arrive, so trying again only failed again. Where the deployment offers it (attachmentUploadsInParts), a file over 1MB now goes up in parts of the size OpenBot chooses (createAttachmentUpload, uploadAttachmentPart, completeAttachmentUpload), as OpenAI's Uploads, Slack's external uploads, Microsoft Graph's upload sessions and Google's resumable uploads do. One part is in flight at a time across the tab, so files sent together don't split a slow link and push every part past the limit. A file of 1MB or less, and every file on an OpenBot that doesn't offer parts, still goes in one request. Every request (each part, the start, the finish and the one-request upload) is tried again by itself while its failure may pass: no answer, 408, 429, a 5xx (Cloudflare's 520 to 524 among them) or a refusal OpenBot marks retryable, honouring Retry-After. Up to 8 tries, about 1s doubling to 30s apart with jitter (p-retry), as Google's and AWS's storage clients retry. A part that is sent again keeps its Idempotency-Key. A part the finish says is missing (ATTACHMENT_PARTS_MISSING) is sent again once and the finish asked again with a new key. An upload that never gets through is stopped on the server (cancelAttachmentUpload), and the file is refused in words that don't ask the person to try again. The tile shows how far a file sent in parts has got: "Uploading…" with the percentage and a thin bar, and the same bar along a picture's placeholder, read from XMLHttpRequest's upload progress (fetch reports none in any browser). It goes through lib/client.ts's one transport, with the same cookie, headers, refusals and reachability as fetch. Removing a file while it goes up in parts stops it, and nothing is said about it. upload-in-parts-browser.test.tsx drives the real message box in Chromium and WebKit against a server that answers as the spec says (checked with its zod schemas) and answers 524 to any body that took too long to arrive, with Chromium's network throttled: in one request the file is refused, in parts it arrives whole.
completeAttachmentUpload refuses an upload with a part missing under ATTACHMENT_PARTS_MISSING, listing each part in problems, so an app sends exactly those again without reading the sentence, and tells it apart from a full message.
…ent answer A file picked the moment the message box appeared, before the page had read the deployment answer, went in one request for good: whether to send it in parts was read from what the screen drew, and that reads as no until the answer arrives. On a slow connection that is exactly when the answer takes longest, so every try of the file was cut off at the edge and it was refused. Found on the real stack at phone width. The upload now asks for the deployment answer itself when it sends a file larger than one part: the one already held, or the one on its way. Only a deployment that can't be read sends the file in one request. The conversation composer, the new-conversation screen and the held files of a first message all go through it, so nothing passes the flag around any more. upload-in-parts-browser.test.tsx holds the deployment answer until the file is picked: before this, the file went as one POST .../attachments; now it goes in parts, in Chromium and WebKit.
…anding in A 10MB PDF picked right after the page loaded was refused with "is too large for a PDF. The limit is 8MB." on an OpenBot that takes 100MB. The message box screens a pick against the limits it was drawn with, and until the deployment answer arrives those are the smallest any OpenBot takes. It is the same race as choosing parts from a value the screen read too early. Now a pick made while that answer is on its way, holding a file a stand-in limit would refuse on size, waits for the answer (attachmentLimitsNow: the one held or the one on its way, asked once, the defaults only if it can't be read) and is screened against it. A pick within every stand-in limit is screened at once, as before, so its tile shows without waiting. Gestures are screened in turn, each counting its files before the next is screened, so two picks in one tick still can't pass the per-message cap. The SDK's own size backstop reads the same limits when it checks a pick, so it can't refuse what the screen passed before the render that brings the answer. The conversation box, /channel/new and Home all screen through this. upload-in-parts-browser.test.tsx holds the deployment answer and picks a 10MB PDF: before, it was refused at 8MB; now it uploads, in Chromium and WebKit. composer-upload-group.test.tsx stages two batches in one tick while the limits load and still stages exactly the cap.
davidmckayv
requested review from
MikeRyanDev,
dustywusty,
guidovizoso,
mxmzb,
samjulien and
tylerslaton
as code owners
December 4, 2026 23:09
…ain while they may pass Since the box learned to wait for the server's limits, every pick was screened a microtask later, even one with nothing to wait for. In WebKit its tile was then drawn a task after the pick, and a strip read straight after the pick was empty. The browser test's wait for uploads to settle read exactly that, saw nothing uploading, and checked the server before the file had gone (CI, WebKit: "a part the server failed is sent again by itself" found no part 3 at all). A pick that has nothing to wait for is screened and staged in the event that brought it again, as it was before; only a pick that waits for the limits, and any gesture behind it, takes its turn. The test's wait now waits for each picked file to be on the strip (or refused) before it looks for uploads in flight. The deployment read a pick or an upload waits on is also asked again, up to three more times, while its failure may pass (the uploads' own rule, now in lib/api/may-pass.ts), so one dropped read on a slow connection doesn't send a large file in one request. A refusal still answers at once. upload-in-parts-browser.test.tsx: "a picked file's tile is on the strip as soon as it is picked" fails in WebKit on the previous composer and passes now.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
On a slow upload link, no file over a few megabytes could be attached. A person on OpenBot Cloud with an upload speed of 15 to 35 KB/s tried 21 times and every try failed. The whole file went up in one request, and the edge in front of OpenBot Cloud closes any request whose body takes more than 125 seconds to arrive. So the composer's "Try again" could never work: at that speed the same request is cut off the same way every time. OpenBot Cloud takes files up to 100 MB, and sending one of those inside 125 s needs about 6.7 Mbps of sustained upload.
The API (
api/openapi/conversations.yaml, additions only):createAttachmentUpload,uploadAttachmentPart,completeAttachmentUploadandcancelAttachmentUploadsend a file in parts. The server chooses the part size; every part is that size except the last.ATTACHMENT_PARTS_MISSING, with each part listed inproblems. A file over the limit for its kind is refused withATTACHMENT_TOO_LARGE(422).attachmentUploadsInParts.uploadConversationAttachmentis unchanged, so released apps keep working, and an app uses parts only where the deployment offers them.The app:
Retry-After, makes up to 8 tries about 1 s doubling to 30 s apart, with jitter, and keeps the same Idempotency-Key on every try.XMLHttpRequest, through the app's one transport inlib/client.ts, becausefetchreports no upload progress in any browser. The cookie, headers, refusals and reachability are the same as withfetch.Design choice, and sources
Every leading product splits a large upload into parts with a step that puts them together. That way no single request has to outlive an edge timeout, and a part that fails is retried on its own:
files.getUploadURLExternal, thenfiles.completeUploadExternal.Retries follow Google Cloud Storage's retry strategy: retry on 408, 429, 5xx and connection errors, with exponential backoff and jitter (https://docs.cloud.google.com/storage/docs/retry-strategy).
The progress display follows the published composer pattern: a percentage and a bar while the size is known, and no bar parked at 100% while the server confirms (https://getstream.io/chat/docs/sdk/react/features/messaging/sending-with-pending-uploads/).
Open-source options I considered first:
So the parts follow OpenAI's and Slack's shape, as the account import already uploads its bundle. The retries use
p-retry9.0.0 and the single lane usesp-limit7.3.3. Both are pinned and released within the last two months.Tests
app/tests/upload-in-parts-browser.test.tsxdrives the real message box in Chromium and WebKit against a server that answers as the spec says. Every request and answer is checked against the spec's zod schemas, and any request whose body took too long to arrive is answered 524, as Cloudflare answers. Chromium's upload is throttled.ATTACHMENT_PARTS_MISSING;End to end on the real product (a throwaway Linux box running OpenBot's stack with a local Intelligence and an S3-compatible object store, in Chromium and WebKit, wide and at phone width, light and dark). Uploads went through a proxy limited to 50 KB/s that cuts off any request body still arriving after 40 s, a scaled-down Cloudflare.
Changelog
Conversations.