Skip to content

Refresh the served bb-app artifact after restart - #877

Merged
SawyerHood merged 2 commits into
ymichael:mainfrom
amadad:fix/server-artifact-cache-freshness
Jul 28, 2026
Merged

Refresh the served bb-app artifact after restart#877
SawyerHood merged 2 commits into
ymichael:mainfrom
amadad:fix/server-artifact-cache-freshness

Conversation

@amadad

@amadad amadad commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • rebuild /install/bb-app.tgz once per server process from the package that process is actually running
  • keep subsequent requests and concurrent callers deduplicated in memory
  • stop trusting a persisted cache entry identified only by package version and daemon protocol

Why

The machine installer promises the exact build served by the current server because unpublished builds can share a version. The persisted cache contradicted that contract: after restarting into a different source build with the same package version and protocol, the server kept serving the previous process's tarball. Remote machines could therefore reinstall successfully and still run stale daemon/bridge code.

Verification

  • regression test fails on main in all three supported layouts (repo-src, repo-dist, packaged) and passes with this change
  • pnpm exec turbo run test --filter=@bb/server --force — 1,258 passed
  • pnpm exec turbo run typecheck --filter=@bb/server --force — passed
  • pnpm exec turbo run build --filter=@bb/server --force — passed
  • Prettier and git diff --check — passed

amadad and others added 2 commits July 28, 2026 00:58
Review follow-up to the once-per-process rebuild.

Deleting the destination tarball before rebuilding turned a transient
build failure into a hard outage: the previous artifact was already gone,
so `/install/bb-app.tgz` had nothing to serve and remote daemons could
neither install nor repair a protocol mismatch. Before this branch a valid
cache entry short-circuited ahead of that delete, so the regression only
appeared once every restart started rebuilding.

Publish by atomic rename instead. `npm pack` writes `bb-app-<version>.tgz`
and the destination always appends `-protocol-<n>`, so the two names can
never collide; both sit in the cache directory, so the rename is
same-filesystem and replaces the old artifact in one step. A failed build
now leaves the last good tarball in place. The metadata sidecar is still
removed so older installs clean themselves up.

Also drop the module-level `pendingBuilds` map. Per-instance memoization
of the build promise already collapses concurrent callers, and the server
constructs exactly one artifact service per process, so the map only added
a second dedupe layer that could never fire.

Both new expectations fail against the pre-change file in all three
layouts (repo-src, repo-dist, packaged).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@SawyerHood
SawyerHood merged commit 85a6d2d into ymichael:main Jul 28, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants