fix(api): stream uploads to the file-server with fetch; bump Bun to 1.4.2 (fixes silent upload truncation) - #174
Merged
Conversation
…r node:http On Bun, node:http's ClientRequest can drop the tail of a chunked request body: write() accepts every byte and end() is called after the last write, yet the peer receives 32 KiB-800 KiB less. The file-server then stores a short object and reports success, so a 20 MiB upload comes back corrupt with no error anywhere (Bun 1.3.10-1.3.14; 1 MiB is unaffected). Send the busboy file part with the global fetch and a web ReadableStream instead. Bun's native fetch and Node's undici stream the body intact. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Bun 1.3.x's node:http client drops the tail of chunked request bodies under load (see the previous commit). Bun 1.4.2 streams them intact in the same test, so the base image bump is the second line of defence for every remaining node:http client in the services. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Collaborator
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
danny-avila
approved these changes
Sep 10, 2026
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.
Problem
POST /v1/upload(and/upload/batch) can store a short object and still answersuccess. A 20 MiB upload lands 32 KiB–800 KiB short, different every time; 1 MiB is fine. No service logs an error, and/v1/downloadfaithfully returns the short object.Root cause
The api forwards each busboy file part to the file-server with
axios.put(url, fileStream). axios sends a stream body throughnode:http'sClientRequestas a chunked body. On Bun 1.3.x (oven/bun:1.3.14in every Dockerfile) that client drops queued trailing chunks and still sends a valid chunked terminator — oven-sh/bun#39752, fixed in Bun 1.4.0 by oven-sh/bun#31587.How it was pinned down (prod-like AKS cluster,
kubectl port-forward, never through a proxy):PUTstraight to the file-server, 5× chunked + 5×Content-Length/uploadhandler (busboy →axios.put) run inside the api podtransportClientRequest.write(),end()called last,write()never returnedfalse— stored short 4/4 (axios) and 4/4 (barehttp.request+pipe)Bun.servebyte-counting sink in the same podtransfer-encoding: chunked→ bytes lost on the wirefetch+Readable.toWeb(file)http.request, no busboy, no axios)The shortfall is always
constant + k × 32 KiB— whole trailing socket chunks.Fix
router.ts:putFileToFileServer()sends the busboy part with the globalfetchand a webReadableStream(duplex: 'half'), replacing bothaxios.putstream calls. Runtime-independent (Bun native fetch; undici on Node). busboy'slimits.fileSizestill caps the part, so no separate body-length guard is needed. Verified by hot-loading the patched file into a running api pod: 8/8 intact at 20 MiB, 1 MiB intact.oven/bun:1.3.14→1.4.2everywhere, as the second line of defence for the remainingnode:httpclients (e.g.runtime-session/checkpoint.ts).tsc --noEmitreports no error in the changed file (the 5 pre-existing errors elsewhere are untouched);upload-session,filesandfile-authorizationtests pass.Not affected: sandbox output files go sandbox → egress-gateway → file-server, and the gateway already forwards them with native
fetch.🤖 Generated with Claude Code