Update bb from inside the app - #4135
Merged
Merged
Conversation
`npx bb-app` and `pnpm start` now run under a small update shim, so Settings → Updates, `bb updates app apply`, and the SDK can download a new bb, restart into it, and roll back automatically if it fails. - npm installs stage into <dataDir>/app-versions/<version> while bb keeps running; source checkouts fast-forward a clean main to origin/main, reinstall, and rebuild. - The launcher backs up bb.db (only when the target adds migrations) before recording the switch, confirms the new version over a three-minute probation, and the shim restores the backup and previous version when it fails to start or keeps crashing. - The server asks the launcher to restart only after the download finishes and no unconfirmed threads started meanwhile. - One shim manages a data directory; a second start runs with updates off. - The web app shows progress, a restarting overlay, and success/rollback results; inside the desktop app a server it did not start gets its own "bb server" row next to "bb desktop". - Nightly builds now check the nightly dist-tag (and latest when it is newer). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The npm shim now records the Node ABI it was given instead of reading process.versions.modules, so its tests no longer assume Node 24. The integration test harness builds the new appUpdate server dependency. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Rolling back only the code is unsafe because most bb releases add migrations and about half drop or rename a column or table, so an older bb often cannot read a database the new version migrated. Making rollback safe needed a pre-update database copy, a probation window, and restore paths in both shims. That was most of the complexity and most of the data-loss risk, for a failure that manual upgrades and the desktop app already handle by updating again. The launcher now records the new version as current when it exits for the restart, and the shim relaunches whatever the state file selects. The new launcher records "updated" once the stack is healthy, or "failed" when a different version starts instead. A source checkout whose rebuild fails stays on the new commit and exits. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The shim changes how bb-app start and pnpm start run bb, so it now only starts when bb is launched with --in-app-updates. Without the flag both commands run the launcher in-process exactly as before, the server reports in-app updates as off, and Settings → Updates shows the upgrade command. A launch flag fits better than an experiment because the shim has to be the parent process from the start, before the server or the database settings exist. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
SawyerHood
force-pushed
the
bb/run-bb-in-interactive-mode-thr_skkan422n6
branch
from
September 23, 2026 19:11
515f4d2 to
4810c49
Compare
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
bb could tell you an update was available, but it couldn't install it. A server started with
npx bb-apporpnpm start, especially a headless one reached through bb Connect, had to be updated by hand in a terminal. The launcher already restarts the server and daemon when they exit, but it starts them from its own package directory. Undernpxthat directory belongs to one fixed version, so a restart just brings the same version back. Nothing stayed running above the launcher that could switch versions, and nothing could undo a bad update.What changed
Off by default. Everything below only runs when bb is started with
--in-app-updates(npx bb-app start --in-app-updatesorpnpm start --in-app-updates). Without the flag, both commands run the launcher in-process as they do onmain. The server then reports in-app updates as off, and Settings → Updates shows the upgrade command. This is a launch flag rather than an experiment because the shim has to be the parent process from the start, before the server or its database settings exist. Two changes ship regardless of the flag: the nightly update check fix, and the separate "bb server"/"bb desktop" rows in the desktop app.Shim and versioned installs (
packages/bb-app/src/app-update/)bb-app start(npx or a global install) andpnpm startrun a small shim. It spawns the real launcher and relaunches it when the launcher exits with code 75.<dataDir>/bb-app-update.json(schema inpackages/config/src/app-update.ts). The schema passes unknown fields through, and bb refuses to overwrite a state file it can't read, because an older npx copy may launch a newer launcher.pnpm dev,pnpm dev --worktree,bb-server, and standalone host daemons don't use the shim.<dataDir>/app-versions/<version>/through a staging dir, using the bundled npm. The stagingpackage.jsonlists the three native packages inallowScripts, because npm 11 rejects--allow-scriptsfor installs like this. A native-module load check runs before anything switches.--bundledforces the npx copy. An install built under a different Node.js ABI falls back to the npx copy.mainthat fast-forwards toorigin/main. It fast-forwards, runspnpm install --frozen-lockfile, rebuilds, and relaunches.scripts/start-bb.mjsnow runs the launcher as a child process (scripts/start-bb-launcher.mjs).bb-app starton the same directory runs with in-app updates off.bb-app stopstops the managing shim.Launcher controller (
launcher-controller.ts, wired intolauncher.ts)updated. If a different version starts instead (for example with--bundled), it records the update as failed.Server, SDK and CLI
GET /system/app-update,POST /system/app-update/apply(returns 409threads_runningunless the caller confirms), andPOST /system/app-update/acknowledge. Machine credentials get 403 on the two POST routes and can't force a check.app-update-changed.app-version.ts: nightly builds now check thenightlydist-tag, and alsolatestin case it's newer. Before this change, nightly users were never offered an update.sdk.system.appUpdate,applyAppUpdate,acknowledgeAppUpdate.bb updates app [status|apply|dismiss].applyconfirms before interrupting threads and follows the update through the restart.Web app
Docs:
docs/configuration.md(In-App Updates), the bb-app README, the machines guide, and the bb-cli skill references. No host-daemon wire change, soHOST_DAEMON_PROTOCOL_VERSIONis unchanged.Open question: the three new SDK methods reach plugins through the bundled plugin SDK types, so a plugin could restart bb. I left them unprefixed, since the
experimental_rule doesn't clearly cover SDK area methods and precedent is mixed. I'm happy to rename them toexperimental_*and adddocs/api_to_audit.mdentries if you'd prefer.How you verified
pnpm exec turbo run typecheckpasses for bb-app, config, server, sdk, cli, app, server-contract, domain and scripts.pnpm exec turbo run testpasses in full for bb-app, config, cli, sdk and server-contract. The server'stest/systemand public app-update tests (199) and the app's app-update, Updates settings and update inventory tests (54) pass.updated; the CLI returned once it did.--bundledbrought 0.43.3 back and recorded "Update to 0.43.4 failed: bb started 0.43.3 instead of 0.43.4."pnpm startsource update in a clone fast-forwarded, reinstalled, rebuilt, relaunched, and recordedupdated.bb-app stopstopped the managing shim in both modes.--in-app-updates,npx bb-appandpnpm startran the server and daemon directly under the launcher, wrote no update state, andbb updates appreported in-app updates as off. With the flag, the shim started and the update applied.npm install bb-app@0.43.4into the staging dir succeeded with the native check.packages/bb-apptarball smoke passes withpioff PATH. The plugin SDK surface check and npm version guard pass.🤖 Generated with Claude Code