Repository navigation
Serve small host files with one daemon round trip - #8117
Merged
ymichael merged 2 commits intoNov 24, 2026
Merged
Conversation
The raw file stream made a metadata-only host.read_file_chunk probe and then read the first chunk, so every host file preview cost two serial RPCs. The first read now returns the metadata with the first 64 KiB, and the stream uses those bytes. It also carries the If-None-Match revisions as knownRevisions, so an unchanged file returns no bytes and answers 304 from the same read. Bumps HOST_DAEMON_PROTOCOL_VERSION to 282 for the new required field. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ions Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
deleted the
bb/small-host-files-one-round-trip-thr_ayhvwekcsv
branch
November 24, 2026 21:52
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.
Human comments
What was wrong
serveDaemonFileStream(apps/server/src/services/hosts/daemon-file-stream.ts) always sent ahost.read_file_chunkwithlength: 0to get metadata, thencreateFileStreamResponseread the first chunk with a second RPC. Every un-ref'd raw host file request therefore cost two serial daemon round trips: image previews, the file viewer's 64 KiB sample, thread-storage files and project/environment files. Only a304took one. This is finding #7 of the server→daemon RPC audit. I checked the call pattern in the code and on a running server before changing anything: main makes 2 RPCs per small file.What changed
daemon-file-stream.ts): the first read isoffset 0, length 64 KiB. The daemon returns the metadata together withmin(64 KiB, size)bytes, and the stream source uses those bytes as its first chunk when the response starts at byte 0. A file up to 64 KiB, or a preview sample of any file, now takes one RPC. Files over 64 KiB save one RPC but still take two waves (first chunk, then the rest in parallel).length: 0) for HEAD,If-None-Match: *, and ranges that don't start at byte 0 (video seeks, suffix ranges), so those requests don't ship 64 KiB that would be thrown away.HOST_DAEMON_PROTOCOL_VERSION281 → 282:host.read_file_chunkgains a requiredknownRevisions: revision[](max 16). The server fills it from the request'sIf-None-Matchtags (W/"file-<revision>"). When the file's current revision is in the list, the daemon returns the metadata with no bytes, and the server answers304from that same read.length: 0wheneverIf-None-Matchis present, would bring back the second RPC for files that changed.[].file-read.ts): reads 0 bytes when the revision is known. The revision check and the read are otherwise unchanged.docs/debugging-and-qa.md.How you verified
Real running servers, main vs this branch, same inputs. I ran
pnpm start:worktree(its own dev data dir, not~/.bb) on main, then rebuilt and restarted it on this branch. There were two hosts:POST /hosts/join-codes, whoseBB_SERVER_URLpointed at a TCP proxy that delays each direction by 100 ms (~200 ms RTT).I counted host RPCs on the remote daemon with an
--importpreload that logs everyfs.openof the test directory. Eachhost.read_file_chunkopens the file exactly once. Each cell below is the median of 8 requests toGET /api/v1/hosts/:id/files/<path>.Remote host (200 ms RTT):
Range: bytes=0-65535Range: bytes=0-65535Range: bytes=100000-loadFilePreviewinapps/app/src/lib/api.ts). For a ≤64 KiB image that drops from 4 RPCs / ~820 ms to 2 RPCs / ~410 ms on the remote host. Each image rendered from the file URL saves ~200 ms.200with the new bytes in one RPC.Tests:
apps/server/test/files/file-content-routes.test.ts. It asserts the daemon command sequence (offset, length,knownRevisions) for GET, the preview Range, matching and staleIf-None-Match, HEAD, a multi-chunk file (no duplicate offset-0 read), and a seek. It fails on main, which sends alength: 0probe and then re-reads offset 0.host-files.test.ts: the first chunk comes back with metadata, and a known revision returns no bytes.turbo run typecheck --filter=@bb/server --filter=@bb/host-daemon. Vitest forfile-content-routes,host-file-routes,daemon-file-stream,file-stream-response(77 passed), andhost-filesplusserver-connectionin the daemon (60 passed).packages/host-daemon-contract/test/contract.test.tsnow pins protocol 282 and rejects a missing, malformed or over-longknownRevisions(56 passed). CI runs the full suites.🤖 Generated with Claude Code