Repository navigation
Stream self-update and plugin host artifact downloads through verified file transfer - #6331
Merged
ymichael merged 1 commit intoOct 27, 2026
Conversation
Base automatically changed from
bb/stream-and-consolidate-skill-and-attachment-tran-thr_tjj6vvmme2
to
main
October 26, 2026 19:46
…d file transfer Daemon self-update buffered the whole host package with arrayBuffer(), checked its sha256 only when the server sent one, and wrote the tarball non-atomically; the server read the tarball into memory per request. Plugin host artifacts were collected into one buffer of up to 256 MiB and the cached copy was read and re-hashed on every worker start. - GET /install/bb-app.tgz streams the cached tarball through the shared host artifact file response; headers and bytes are unchanged. - Self-update streams into host-package-download/ via writeVerifiedFile, requires x-bb-artifact-sha256, checks content-length and a 1 GiB cap, renames the verified file into place, and clears leftovers per attempt. - fetchPluginHostArtifact returns the response body; the node artifact cache streams it through writeVerifiedFile and remembers verified cache files by (dev, ino, size, mtime, ctime) with a racy-timestamp guard. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
force-pushed
the
bb/stream-self-update-and-plugin-host-artifact-down-thr_x6v3wayctj
branch
from
October 26, 2026 21:34
51ea6a7 to
d962007
Compare
ymichael
deleted the
bb/stream-self-update-and-plugin-host-artifact-down-thr_x6v3wayctj
branch
October 27, 2026 03:51
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
Two server-to-daemon downloads still held the whole payload in memory, and they skipped the verification that #6330 added for skills and attachments.
response.arrayBuffer(). It checked the sha256 only if the server sentx-bb-artifact-sha256. It then wrotebb-app-update-<pid>.tgzwithwriteFile, which is not atomic and leaves a partial file behind if the daemon crashes mid-write.GET /install/bb-app.tgzcalledreadFileon the whole tarball for every request.fetchPluginHostArtifactcollected chunks into one buffer of up toHOST_ARTIFACT_MAX_BYTES(256 MiB), so the cache held two copies during a write. Every worker start or bridge launch also read the whole cachedhost.mjsback and re-hashed it withreadFile.What changed
Both downloads now go through
writeVerifiedFilefrom@bb/file-transfer(added in #6330, moved into the package by #6335); no parallel download code is added.Self-update (
apps/host-daemon/src/protocol-self-update.ts)<dataDir>/host-package-download/bb-app.tgz.partialthroughwriteVerifiedFilewith a sha256 and an expected size. On success it renames the file tobb-app.tgzand runsnpm install -gon it. The rename also gives npm the.tgzname it uses to recognize a tarball.x-bb-artifact-sha256fails the attempt and nothing is installed.content-lengthbecomes the expected size when present. There is also a 1 GiB cap that rejects an oversizedcontent-lengthbefore any bytes are read.Install route (
apps/server/src/server.ts,apps/server/src/internal/host-artifact-response.ts)GET /install/bb-app.tgzstreams the file through the existinghostArtifactFileResponse, which now takes the response headers as a parameter. The plugin artifact route passes its own headers.etag,x-bb-artifact-sha256,content-length,content-type,cache-control), the 304 path and the response bytes are all unchanged.host_package_unavailable500.Plugin host artifacts (
server-client.ts,node-artifact-cache.ts,plugin-host-artifact-cache.ts,plugin-host-manager.ts)fetchPluginHostArtifactreturns the response body as a stream after the status andcontent-lengthchecks.readHostArtifactBytesis deleted..staged-<uuid>.tmpthroughwriteVerifiedFilewith the digest, the byte length and the 256 MiB cap, then renames it into place.(dev, ino, size, mtimeNs, ctimeNs), mirroring Transfer skill trees by manifest, fetching only missing files #6330'sSkillTreeRegistry. The same racy-timestamp guard applies: a file whose mtime or ctime is within 2 s of now is not remembered. A changed stat key triggers a full re-hash; if that fails, the file is deleted and downloaded again.Compatibility (no
HOST_DAEMON_PROTOCOL_VERSIONbump)The wire format is unchanged: same routes, request headers, response headers and bytes.
server.protocolVersion > HOST_DAEMON_PROTOCOL_VERSION; an older or equal server is refused before any download. So this daemon only ever downloads from servers built after this change. Every server since Ship a host-only artifact for enrolled machines #2969 (2026-09-02) sendsx-bb-artifact-sha256andcontent-lengthon the 200, so requiring the digest cannot strand a daemon that is updating from a newer server.if-none-match, which still gets a 304.install.shand the Windows installer download the same URL.compress()middleware gzipstext/javascriptand removescontent-length. The daemon already tolerated a missingcontent-length, and it still verifies the exact byte length and digest from the session payload.How you verified
Tests
apps/host-daemon/src/node-artifact-cache.test.ts:apps/host-daemon/src/protocol-self-update.test.tsnow uses server-shaped responses and adds:content-length, connection reset mid-body). Each asserts no install and no files left in the data dir.content-lengththat cancels the body before it is readbb-app.tgz, never the.partialapps/server/test/app/skeleton.test.tsasserts the streamedcontent-length, and that a cached tarball whose size changed returnshost_package_unavailable.Commands
pnpm exec turbo run typecheck test --filter=@bb/host-daemon --filter=@bb/server:builtin-plugins.test.ts(builtin plugin hot-reload, which this PR doesn't touch). It failed under load average ~23. Run alone, a different test in that file failed once, then the whole file passed twice.oxfmt --checkandoxlintare clean on the changed daemon and test files.Memory, measured on the real code paths
createAppinstall route (test harness) and the realregisterInternalPluginHostArtifactRoutesbehindcompress(), served over HTTP with@hono/node-server.createProtocolSelfUpdater(stubinstallTarball;/install/versionrewritten to protocol+1) and the realcreateServerClient().fetchPluginHostArtifactwithensureCachedPluginHostArtifact.host.mjs(2.1 MB). The 64 and 256 MiB payloads are those same files repeated.process.resourceUsage().maxRSSgrowth during one download. Server figures are peakarrayBuffersgrowth.Not changed
apps/host-daemon/src/server-move/download.tshas its own streamed, verified download for server moves. It overlaps withwriteVerifiedFileand could be folded in separately.bb-app-artifact.tsstill reads the packed tarball once per server process to compute its digest. That happens at build time, not per request.