Skip to content

Server never starts: pre-listen startup sweep awaits provider registrations whose 30 s fallback timer is unref'd, so the process exits 0 #4862

Closed

Description

@thomaswillner

Summary

After a crash leaves one thread in status starting (with a ready environment), the bb server can never start again: every boot exits with code 0 before it listens and before its logger writes anything. The supervisor retries forever ("Server failed to restart"). Expected: the 30 s provider-settle timeout fires and startup continues.

Versions and environment

  • bb 0.44.0 desktop app (bundled server), macOS 26.6.2, Apple Silicon. Same result with the 0.45.0 bundle (desktop-v0.45.0).
  • Code is unchanged on main at 09ff18a.
  • Data dir ~/.bb, default ports. The thread that triggered it was an ultragoal plugin worker thread.

Steps to reproduce

  1. Have a thread with status = 'starting', deleted_at IS NULL, and an environment that is ready (here: left behind when the server crash-looped mid-provisioning).
  2. Start the server: ELECTRON_RUN_AS_NODE=1 /Applications/bb.app/Contents/MacOS/bb /Applications/bb.app/Contents/Resources/app.asar.unpacked/node_modules/bb-app/server/dist/index.js with BB_DATA_DIR pointing at that data dir.
  3. It exits with code 0 within ~0.4 s and prints nothing, even with BB_LOG_LEVEL=trace and --trace-exit.

Did not reproduce with an empty data dir: the same binary listens in ~2 s.

Expected vs actual

Expected: startup recovery sweep waits ≤30 s for provider registrations, then the server listens.
Actual:   process exits 0 after ~380 ms, before "Server listening"; server-stdio.log stays empty;
          bb-app logs "Server failed to restart" in a loop (17k times in one day here).

Evidence

Mechanism (permalinks at main 09ff18a):

  • The pre-listen sweep runs and is awaited: start-server.ts#L351. The listener starts after it (#L363), and plugins start after the listener (#L390). markRegistrationsSettled() is only called from startServerPlugins().finally() (#L96), because the registry is created with deferRegistrationsSettled: true (#L164).
  • The sweep picks up starting threads (periodic-sweeps.ts#L318) → advanceThreadProvisioning → requestThreadStart → buildThreadStartCommand, which awaits providerRegistry.whenRegistrationsSettled() (thread-commands.ts#L268).
  • The only fallback is a 30 s timer that is unref'd (provider-registry.ts#L188-L189). Before listen nothing else holds the event loop (better-sqlite3 is synchronous), so Node drains the loop and exits 0 with the promise still pending.

How it was measured:

  • An async_hooks dump at beforeExit (with --enable-source-maps) shows 37 pending promises. The deepest frames are buildThreadStartCommand (thread-commands.ts:268) ← startThreadIfEnvironmentReady ← runThreadProvisioningOrphanCleanupSweep ← runStartupRecoverySweep ← runServer (start-server.ts:322).
  • Preloading a referenced timer (bb --require hold.cjs …/server/dist/index.js, where hold.cjs is setTimeout(() => {}, 90_000)) is enough on its own to fix it. The server listens at t=31 s, the sweep marks the thread error, and the next plain boot listens in 1 s.

What you ruled out

  • Not DB corruption: PRAGMA quick_check = ok, and the migration hashes match a fresh 0.44.0 DB (132/132).
  • Not a server-move lock: bb server unlock --json → unlocked: false.
  • Not the bundle: codesign verifies, and an empty data dir boots.
  • Not fixed in 0.45.0: the same clone exits the same way with the 0.45.0 server.
  • Not sidebar-bootstrap returns 409 no_provider_available during startup: read-only project listing does not await whenRegistrationsSettled #3207: that one is about read-only project listing during startup; this one is the startup sweep hard-blocking listen.
  • NODE_OPTIONS cannot be used as a workaround: this Electron build ignores Node env vars ("Node.js environment variables are disabled because this process is invoked by other apps").

Suggested priority and effort (optional)

High: one crash at the wrong moment makes BB unbootable with no error message, and the only workaround is the external preload above (or hand-editing bb.db). Effort is probably low: don't await whenRegistrationsSettled() from the pre-listen sweep (defer provisioning starts until plugins have settled), or keep the 30 s fallback timer referenced.

AGENT GENERATED (Claude Code session diagnosing a local BB outage on 2026-10-04; evidence above is from that session).

Activity

  1. added theissue type on Oct 4, 2026
  2. added
    host
    providers
    confirmed-repro
    on Oct 4, 2026
  3. bb-slop-cop commented on Oct 4, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Classification: Bug · Priority High · Effort Low; area labels host, providers.
    • Report: https://get-bb.github.io/reports/issues/4862.html — REPRODUCED, root-cause confidence high; applied confirmed-repro.
    • Root cause: The provider-registration fallback timer is unreferenced, allowing an otherwise idle Node process to exit successfully before startup waits complete. The startup sweep reaches this wait before listening or starting plugins.
    • Verification: A real child-process regression fails on unchanged trusted main in two clean checkouts, then passes with the timer fix. All 26 relevant tests and server typechecking pass. Packaged macOS startup and the reporter's database were not exercised.
    • Fix: Keep provider startup fallback timer alive #4864 — ready for review; 37 changed text lines across two files. Not merged.

    AGENT GENERATED

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-reprohostproviders

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions