Skip to content

Never kill a desktop server that is still starting - #7783

Open
ymichael wants to merge 1 commit into
mainfrom
bb/never-kill-a-desktop-server-that-is-still-starti-thr_imehzent6e
Open

ymichael wants to merge 1 commit into
mainfrom
bb/never-kill-a-desktop-server-that-is-still-starti-thr_imehzent6e

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Two separate 60-second deadlines stopped a bb server that was still alive and starting. The desktop app (apps/desktop/src/main.ts startOwnedRuntime, STARTUP_TIMEOUT_MS = 60_000) raced waitForCompatibleServer against that deadline, then showed "Could not start bb / Timed out waiting for bb" with no buttons and stopped the runtime. Separately, the bb-app launcher (packages/bb-app/src/launcher.ts startFullStackServerProcess → waitForServerHealth, HEALTH_CHECK_TIMEOUT_MS = 60_000) SIGTERMed its server child on the same deadline. The server runs migrate(db) before it listens (apps/server/src/db.ts, start-server.ts), so a long migration on a large bb.db or a CPU-starved host was killed and rolled back, then failed the same way on every launch. Fixing only the desktop deadline would not have been enough, because the launcher would still have killed the server.

Related: #7753 (15 GB bb.db, event-loop stalls up to 62 s), #2480. Credit: T3 Code fixed the same class in pingdotgg/t3code#35056 ("wait for the server's database upgrade instead of reporting a failed start") and pingdotgg/t3code#26247, which pointed us at it.

What changed

  • bb-app launcher: waitForServerHealth has no deadline. It polls until the child echoes its launch id or the child exits, and childProcess is now required. After 15 s it logs once that the server is still starting and may be upgrading its database. HEALTH_CHECK_TIMEOUT_MS still applies to the host daemon status wait, which is unchanged.
  • Desktop: waitForCompatibleServer takes an AbortSignal instead of a timeout and returns only a settled result (compatible or incompatible). The new owned-runtime-startup.ts (waitForOwnedRuntimeStartup) races the probe against the bb-app process exit with no deadline, stops probing once either side wins, and fires a slow-start callback after 10 s.
    • After 10 s the window switches from "Opening bb" to "Still starting bb", saying bb may be upgrading its data. It switches only if the window is still on the opening view.
    • Startup fails only when bb-app exits. That screen, and the later "bb stopped" screen, now offer Try again and Choose server… and keep the "Logs are under …" hint.
    • STARTUP_TIMEOUT_MS is renamed to MACHINE_READY_TIMEOUT_MS, since it now only bounds the existing "computer connected" wait. That wait opens bb anyway and never kills anything.
    • The "incompatible" path (port answered but is not bb) still stops the runtime, as before.
  • apps/desktop/README.md documents the no-deadline startup.

No server/daemon wire changes.

How you verified

Repro on origin/main (502cf5a): I launched the unmodified desktop dev app (apps/desktop/scripts/run-electron-dev.mjs, isolated worktree data dir) with a NODE_OPTIONS=--import preload. The preload holds only the real apps/server/dist/index.js process for 90 s before it loads, which is the same thing the desktop sees as a slow migrate(db) before listen.

  • The server started waiting at 20:29:51.608 and received SIGTERM at 20:30:51.563, while it was still starting.
  • The window showed "Could not start bb — Timed out waiting for bb at http://127.0.0.1:24909: Timed out after 60000ms waiting for bb server. Last probe: fetch failed." with no buttons.

Same repro with this branch:

  • At 10 s the window showed "Still starting bb".
  • No signal reached the server. It finished its 90 s at 20:37:14 and the window opened the bb workspace at 20:37:26.
  • Failure path: I SIGKILLed the server while it was starting. bb-app exited and the window showed "Could not start bb — bb-app exited before the server was ready with exit code 1" with Try again / Choose server…. Clicking Try again over CDP started a new server, which waited 30 s and then opened bb.

Tests:

  • apps/desktop/test/owned-runtime-startup.test.ts, against a real child HTTP server:
    • a slow server is awaited, the slow-start callback fires, and the child is never signalled;
    • a child exit fails startup and stops the probe loop;
    • fake timers advance 5 minutes with nothing listening and startup is still pending.
  • packages/bb-app/test/server-health-identity.test.ts:
    • waitForServerHealth stays pending through 3 simulated minutes, then resolves when the child answers;
    • it fails, naming the foreign server, only once the child exits.
  • I mutation-checked both no-deadline tests by putting the old Date.now() 60 s deadline back into waitForCompatibleServer and waitForServerHealth: both tests failed, and both pass with this change.
  • pnpm exec turbo run lint typecheck lint:type-aware test --filter=@bb/desktop --filter=bb-app: all green (desktop 629 passed, bb-app 232 passed).

AGENT GENERATED

🤖 Generated with Claude Code

The desktop app and the bb-app launcher each gave the server 60 seconds
to answer /health, then stopped it. The server runs migrate(db) before
it listens, so a long migration on a big bb.db or a starved host was
killed, rolled back, and failed again on every launch.

Both now wait without a deadline while the process lives. Desktop shows
"Still starting bb" after 10 seconds, and fails only when bb-app exits,
offering Try again and Choose server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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