Skip to content

Let the machine installer adopt an enrolled data directory - #4173

Merged
SawyerHood merged 1 commit into
mainfrom
bb/moved-desktop-installer-adopt
Sep 23, 2026
Merged

SawyerHood merged 1 commit into
mainfrom
bb/moved-desktop-installer-adopt

Conversation

@SawyerHood

@SawyerHood SawyerHood commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

When a bb server moves off the desktop app (or npx bb-app), the old computer stays a machine only through that app's own bb-app process. That daemon runs only while the app is open, and because it ships inside the app it never updates itself. Every release changes HOST_DAEMON_PROTOCOL_VERSION (203 → 207 → 215 → 216 across 0.43.0–0.43.4), so the first server update after the move rejects the old computer's daemon, and threads on that machine stop working. Machines installed from the command line don't have this problem: install-machine.sh gives them a launchd/systemd service with --auto-update. But the installer only works from an enrollment bundle, which creates a new machine, so it can't take over the old computer's existing machine and its threads.

This PR is the first layer of a stack; it has no prerequisite.

What changed

  • apps/server/src/assets/install-machine.sh accepts --adopt --data-dir <dir>. It reads the machine ID from <dir>/auth.json, and the server address plus credential headers (serverHeaders, or a legacy machineCredential) from <dir>/config.json. It skips bb machine enroll, then runs the normal install:
    • installs the server-matched package into <dir>/npm
    • uses the existing "already joined" path, so it doesn't re-join
    • writes the launchd/systemd service with --auto-update
    • waits for the daemon to connect
  • The adopted identity, which includes the credential, reaches node through an environment variable rather than argv, the same way the bootstrap bundle does.
  • --adopt refuses to combine with --bootstrap-env or with lifecycle actions, and it requires --data-dir.

No server/daemon wire change.

How you verified

  • New cases in apps/server/test/app/install-machine-script.test.ts:
    • adopting a directory installs a launch agent for it, doesn't enroll again, and sends the connect header to the package download
    • a legacy machineCredential is used as the header
    • invalid flag combinations are rejected
    • a directory without auth.json fails before npm runs
  • The fake curl now records its --config headers.
  • pnpm exec turbo run test --filter=@bb/server -- test/app/install-machine-script.test.ts src/services/machines/bootstrap.test.ts: 48 passed.
  • Full @bb/server suite on the top of the stack: 3085 passed.
  • Not tested against a real server; the npm install, launchd and the daemon are faked.

🤖 Generated with Claude Code

AGENT GENERATED

`install-machine.sh --adopt --data-dir <dir>` installs the persistent,
self-updating host daemon service for a data directory that is already
enrolled, such as the one a server move leaves on the old server's computer.
It reads the machine ID from auth.json and the server address and credential
headers from config.json instead of a bootstrap bundle, skips enrollment, and
otherwise runs the normal install: server-matched package in <dir>/npm,
launchd/systemd service with --auto-update, and a wait for the daemon to
connect.

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 changed the title bb/moved desktop installer adopt Let the machine installer adopt an enrolled data directory Sep 23, 2026
@SawyerHood
SawyerHood marked this pull request as ready for review September 23, 2026 17:37
@SawyerHood
SawyerHood merged commit 103d987 into main Sep 23, 2026
18 checks passed
@SawyerHood
SawyerHood deleted the bb/moved-desktop-installer-adopt branch September 23, 2026 17:38
SawyerHood added a commit that referenced this pull request Sep 23, 2026
## 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](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