Skip to content

Install the machine service when a desktop-hosted server moves away - #4175

Merged
SawyerHood merged 1 commit into
bb/moved-desktop-cli-servicefrom
bb/moved-desktop-runtime
Sep 23, 2026
Merged

SawyerHood merged 1 commit into
bb/moved-desktop-cli-servicefrom
bb/moved-desktop-runtime

Conversation

@SawyerHood

@SawyerHood SawyerHood commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

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

AGENT GENERATED

After its local server moves, the desktop app used to keep this computer a
machine through its own bb-app process: the daemon ran only while the app was
open and, bundled with the app, never updated itself, so the first server
update after the move took the machine and its threads offline.

Now, when the desktop activates a move (live or on a later launch) and no
machine service exists for its data directory, it stops its own runtime and
runs the bundled `install-machine.sh --adopt` in the background, logging to
<data-dir>/logs/install-machine-service.log. If the install fails, for example
without Node.js 22.19+, it keeps today's app-owned machine, explains why once
per move, and tries again on the next launch.

bb-app's moved mode no longer starts a host daemon when a machine service runs
the data directory; it only answers the old address with the move notice, so
the desktop app and `npx bb-app` never compete with the service for the daemon
lock. Without a service, moved mode now points at
`bb server install-machine-service`.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@SawyerHood
SawyerHood force-pushed the bb/moved-desktop-runtime branch from 629b782 to 8d86b5d Compare September 23, 2026 17:10
@SawyerHood
SawyerHood marked this pull request as ready for review September 23, 2026 17:37
@SawyerHood
SawyerHood merged commit cd79198 into main Sep 23, 2026
18 checks passed
@SawyerHood
SawyerHood deleted the bb/moved-desktop-runtime branch September 23, 2026 17:38
SawyerHood added a commit that referenced this pull request Sep 23, 2026
…puter (#4176)

## Human comments

## What was wrong

Nothing in the move checklist told someone moving a desktop-hosted
server what happens to their computer afterwards, or that keeping it
connected needs Node.js 22.19+.

Stacked on #4175, which installs the service from the desktop app.

## What changed

- `ServerMoveAppOptions` carries the server's `BB_APP_SURFACE`, taken
from `serverConfig` in `start-server.ts` and defaulting to `web` in
`createApp`. It flows through `createDefaultServerMoveEnvironment` into
`ServerMoveEnvironment.serverAppSurface` and the check environment.
- When the server runs in the desktop app, `runServerMoveCheck` adds an
info item, `desktop-app-machine`. It says the app will keep the computer
connected as a background machine that updates with the server, and that
this needs Node.js 22.19+ there. It never blocks the move.

No server/daemon wire change.

## How you verified

- `apps/server/test/server-move/checks.test.ts`: a desktop-hosted server
gets the item; a web one doesn't; `canMove` is unchanged.
- Test environment builders updated.
- `pnpm exec turbo run test --filter=@bb/server -- test/server-move/`:
97 passed.
- Full `@bb/server` suite: 3085 passed.
- `pnpm exec turbo run typecheck --filter=@bb/server` passes.

🤖 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