Repository navigation
Keep thread provisioning off the HTTP readiness path - #8426
Merged
Merged
Conversation
Startup awaited the thread provisioning sweep before opening HTTP. A thread left in "starting" by a killed server advances to buildThreadStartCommand, which waits up to 30s for provider registrations. Provider plugins only register after the server listens, so each such thread spends the full 30s, and three of them exhaust the launcher's 60s health deadline: `pnpm start` fails with "Server failed to become healthy" on every retry. Run only the thread provisioning step in the background, as #8200 did for machine recovery, and keep the archived/deleted thread teardown awaited.
scowalt
pushed a commit
to scowalt/bb
that referenced
this pull request
Dec 1, 2026
## What was wrong `pnpm start` failed every time with `Server failed to become healthy: Timed out waiting for health` after a bb process was killed while threads were being created. Startup awaits `runStartupRecoverySweep` before opening HTTP, and its `thread-orphan-cleanup` step ran the thread provisioning sweep inline. For each thread left in `starting`, `advanceThreadProvisioning` reaches `buildThreadStartCommand`, which awaits `providerRegistry.whenRegistrationsSettled()`. Provider plugins only register after the server listens (`startServerPlugins` runs after "Server listening"), so each such thread waits the full `REGISTRATIONS_SETTLED_TIMEOUT_MS` (30s). With three stuck threads, startup needs 90s+ and the launcher's 60s health deadline kills it, which leaves the same threads behind for the next attempt. Found on a real data dir with logpoints in the built server: every step up to `runStartupRecoverySweep` finished within a second; the sweep stopped in `thread-provisioning` → `requestThreadStart` → `buildThreadStartCommand` → `whenRegistrationsSettled`. ## What changed Same shape as get-bb#8200 (machine recovery): run only the thread provisioning step in the background through the existing error-handled `runStartupRecoveryStep`, and keep archived/deleted thread teardown awaited. The periodic sweep still runs provisioning then teardown in order. ## How I verified - New `test/services/startup-thread-provisioning.test.ts` holds a starting thread's provisioning open and asserts startup recovery still finishes. It fails without the fix (`startup must not wait for thread provisioning to finish: expected false to be true`) and passes with it. - `turbo run test --filter=@bb/server -- startup-thread-provisioning startup-machine-recovery periodic-sweeps item-sweep periodic-sweep-jobs thread-live-start-handoff environments/provider-orchestration` passes. - `turbo run typecheck lint --filter=@bb/server` passes. - The real data dir that hung starts once the patch is applied (see below).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
pnpm startfailed every time withServer failed to become healthy: Timed out waiting for healthafter a bb process was killed while threads were being created.Startup awaits
runStartupRecoverySweepbefore opening HTTP, and itsthread-orphan-cleanupstep ran the thread provisioning sweep inline. For each thread left instarting,advanceThreadProvisioningreachesbuildThreadStartCommand, which awaitsproviderRegistry.whenRegistrationsSettled(). Provider plugins only register after the server listens (startServerPluginsruns after "Server listening"), so each such thread waits the fullREGISTRATIONS_SETTLED_TIMEOUT_MS(30s). With three stuck threads, startup needs 90s+ and the launcher's 60s health deadline kills it, which leaves the same threads behind for the next attempt.Found on a real data dir with logpoints in the built server: every step up to
runStartupRecoverySweepfinished within a second; the sweep stopped inthread-provisioning→requestThreadStart→buildThreadStartCommand→whenRegistrationsSettled.What changed
Same shape as #8200 (machine recovery): run only the thread provisioning step in the background through the existing error-handled
runStartupRecoveryStep, and keep archived/deleted thread teardown awaited. The periodic sweep still runs provisioning then teardown in order.How I verified
test/services/startup-thread-provisioning.test.tsholds a starting thread's provisioning open and asserts startup recovery still finishes. It fails without the fix (startup must not wait for thread provisioning to finish: expected false to be true) and passes with it.turbo run test --filter=@bb/server -- startup-thread-provisioning startup-machine-recovery periodic-sweeps item-sweep periodic-sweep-jobs thread-live-start-handoff environments/provider-orchestrationpasses.turbo run typecheck lint --filter=@bb/serverpasses.