Skip to content

Add bb server install-machine-service - #4174

Merged
SawyerHood merged 1 commit into
bb/moved-desktop-installer-adoptfrom
bb/moved-desktop-cli-service
Sep 23, 2026
Merged

SawyerHood merged 1 commit into
bb/moved-desktop-installer-adoptfrom
bb/moved-desktop-cli-service

Conversation

@SawyerHood

@SawyerHood SawyerHood commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

After a server moves off bb-app or the desktop app, there was no supported way to turn the old computer into a persistent, self-updating machine while keeping its identity and threads. The only way to get an auto-updating daemon was to enroll a new machine, and threads can't move or fork onto a different machine.

Stacked on #4173, which adds install-machine.sh --adopt.

What changed

  • New command bb server install-machine-service [--data-dir <dir>] [--yes] [--json] (apps/cli/src/commands/server-machine-service.ts):
    • requires the server-moved.json lock, auth.json, a server address in config.json, and Node.js 22.19+ on the PATH
    • asks for confirmation unless --yes
    • stops the bb recorded in bb-app-runtime.json, using the same verified stop as bb-app stop
    • runs install-machine.sh --adopt --data-dir <dir>
    • --json prints dataDir, serverUrl, toHostName and serviceFile
    • the Node check runs before anything stops, so an old Node leaves bb running
  • Installer location: the bb-app launcher passes the installer path (server/dist/assets/install-machine.sh) to the CLI as BB_MACHINE_INSTALLER, the same way it already passes BB_APP_VERSION. The CLI ships its own installer rather than downloading the server's, so people already stuck on an older server can still adopt.
  • @bb/config/machine-service: findMachineServiceFile finds the launchd plist or systemd unit whose BB_DATA_DIR matches a data directory, comparing canonical paths and undoing the installer's escaping.
  • bb server unlock refuses while such a service exists, because unlocking would start a second daemon on the same data. The error gives the command that removes the service.
  • Docs: the machines guide template, the bb-cli skill and its command index and thread-creation reference, docs/api_to_audit.md, docs/server-move-plan.md, and docs/cli-guide-and-skill.md.

No server/daemon wire change.

How you verified

  • apps/cli/src/__tests__/command-output/server-machine-service.test.ts, run with a fake installer against a real live process:
    • stops the recorded bb (it exits with SIGTERM) and passes --adopt --data-dir
    • refuses a directory that no server moved away from
    • leaves bb running when node on PATH is 20.18.1
    • reports an installer failure
    • unlock refuses while the service exists
  • packages/config/test/machine-service.test.ts: launchd and systemd matching, symlinked data directories, escaping, and no match.
  • packages/bb-app/test/index.test.ts: the CLI receives BB_MACHINE_INSTALLER.
  • pnpm exec turbo run test --filter=@bb/cli --filter=@bb/templates: 841 + 47 passed.
  • pnpm exec turbo run test --filter=@bb/config --filter=bb-app: passed.
  • Typecheck passes for @bb/cli, @bb/config and bb-app.

🤖 Generated with Claude Code

AGENT GENERATED

After a server moves off a desktop app or bb-app, the old computer stays a
machine only while that app runs, and its daemon cannot update itself.
`bb server install-machine-service` gives that data directory the persistent,
self-updating service a CLI-installed machine gets: it requires a move lock,
the machine's auth.json and config.json, and Node.js 22.19+ on the PATH, then
stops the bb recorded in bb-app-runtime.json and runs
`install-machine.sh --adopt --data-dir <dir>` from the bb-app package (the
launcher passes its path to the CLI as BB_MACHINE_INSTALLER).

`@bb/config/machine-service` finds the launchd or systemd service that runs a
daemon for a data directory. `bb server unlock` uses it to refuse while such a
service exists, since unlocking would start a second daemon on the same data.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@SawyerHood
SawyerHood added this pull request to stack #4177 September 23, 2026 16:29
@SawyerHood
SawyerHood marked this pull request as ready for review September 23, 2026 17:37
@SawyerHood
SawyerHood merged commit 57784a5 into main Sep 23, 2026
18 checks passed
@SawyerHood
SawyerHood deleted the bb/moved-desktop-cli-service branch September 23, 2026 17:38
SawyerHood added a commit that referenced this pull request Sep 23, 2026
…4175)

## Human comments

## What was wrong

This is the part that fixes the desktop case directly. After its local
server moved, the desktop app ran this computer's daemon through its own
bb-app process in moved mode. That process was killed when the app quit
and restarted on the next launch, and its bundled daemon never updated
itself. So the machine was offline whenever the app was closed, and it
dropped off entirely after the next protocol bump on the server.

Stacked on #4174, which adds `bb server install-machine-service` and
`@bb/config/machine-service`.

## What changed

- **Desktop** (`apps/desktop/src/moved-machine-service.ts`, `main.ts`).
When the app activates a move, either live or on a later launch, and no
machine service exists for its data directory, it does this in the
background:
- stops its own runtime and runs the bundled `install-machine.sh
--adopt`, found through `resolveDesktopMachineInstallerPath`
- logs the installer's output to
`<data-dir>/logs/install-machine-service.log`
  - restarts its runtime afterwards
- on failure (for example, no Node.js 22.19+), keeps today's app-owned
machine, shows one dialog per move with the installer's reason, and
tries again on the next launch
- move activation no longer waits for the runtime, so app startup isn't
blocked by the install
- **bb-app moved mode** (`packages/bb-app/src/launcher.ts`):
- when a machine service runs the data directory, it doesn't start a
host daemon and only answers the old address with the move notice, so
neither the desktop app nor `npx bb-app` competes with the service for
the daemon lock
- without a service, its ready output points at `bb server
install-machine-service`
- **Docs:** the machines guide template, the bb-cli thread-creation
reference, and `docs/server-move-plan.md`.

No server/daemon wire change.

## How you verified

- `apps/desktop/test/moved-machine-service.test.ts`:
- runs a real `/bin/sh` fake installer and checks the arguments, log
append, reason from this run's `✗` line, and fallback exit description
  - existing service → no action
  - no service → the runtime stops before the install
  - a failed install is explained once per move
- `apps/desktop/test/app-paths.test.ts`: the installer path inside the
asar-unpacked `bb-app` package.
- `packages/bb-app/test/moved-mode.test.ts`: with a service, moved mode
never starts a daemon, keeps the responder, and exits on shutdown.
- `pnpm exec turbo run test --filter=bb-app`: 149 passed.
- Desktop typecheck passes. Desktop tests pass except two
Electron-launch tests that also fail here without this change
(`preload-build.test.ts`, SIGABRT launching Electron) or are flaky under
load (`electron-builder-config.test.ts` passes alone).
- **Not verified:** a packaged desktop app through a real server move.
The installer asset ships in the desktop bundle because the
desktop-hosted server already serves `/install.sh` from
`server/dist/assets`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

> AGENT GENERATED

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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.

1 participant