Skip to content

Keep thread provisioning off the HTTP readiness path - #8426

Merged
SawyerHood merged 1 commit into
mainfrom
startup-thread-provisioning-off-readiness
Nov 30, 2026
Merged

SawyerHood merged 1 commit into
mainfrom
startup-thread-provisioning-off-readiness

Conversation

@SawyerHood

Copy link
Copy Markdown
Collaborator

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 #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).

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.
@SawyerHood
SawyerHood merged commit ce95d0e into main Nov 30, 2026
31 checks passed
@SawyerHood
SawyerHood deleted the startup-thread-provisioning-off-readiness branch November 30, 2026 23:39
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).
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