Repository navigation
Description
Summary
Two concurrent provider-managed thread starts can become permanent error threads when a shell-environment refresh invalidates their shared provider-installation probe. The workspaces provision successfully, but both thread.start commands fail with Runtime shutting down instead of transparently checking the provider again and continuing.
Versions and environment
- bb 0.39.0, running from source at
c2837e0d4876e13b570159656925fab0123e5dcc - macOS 26.5.1 (25F80), Node v22.23.1
- Codex provider, codex-cli 0.148.0
- Two personal workspaces on host M4; bb Connect paired at https://ymichael.getbb.app
- Investigation thread: https://ymichael.getbb.app/threads/thr_piqfifpsii
Steps to reproduce
The timing is intermittent in the product and deterministic at the host-daemon command layer:
- Start two installation-managed provider threads concurrently so they share one in-flight
providerInstallationStatuspromise. - While that promise is pending, let
replaceBaseShellEnvobserve a changedPATH. It clears the installation gate and shuts down the maintenance runtime. - The runtime rejects the shared status request with
Runtime shutting down. - Observe both accepted
thread.startcommands reject instead of re-probing in the new gate generation.
Live occurrences:
- https://ymichael.getbb.app/threads/thr_5qw4sdamqk
- https://ymichael.getbb.app/threads/thr_gegqmx649k
They were created 1.5 seconds apart and failed at the same millisecond after sharing the status probe.
Expected vs actual
Actual:
Command thread.start failed
Runtime shutting down
Both thread timelines stop after successful workspace provisioning. There is no provider output, requested command execution, or final response.
Expected:
Invalidating a provider-installation probe should cause waiting thread starts to join a fresh probe against the new shell environment. If that probe succeeds, both real threads should continue starting.
Evidence
The thread-start preflight awaits the shared installation gate:
bb/apps/host-daemon/src/command-handlers/thread.ts
Lines 100 to 140 in c2837e0
| async function requireSupportedProviderCliForThreadStart({ | |
| command, | |
| options, | |
| }: RequireSupportedProviderCliArgs): Promise<void> { | |
| if (!command.bridgeLaunch.capabilities.providerInstallation) { | |
| return; | |
| } | |
| const requirement = | |
| command.type === "thread.rewind.prepare" | |
| ? ("thread_rewind" as const) | |
| : undefined; | |
| // A changed PATH can resolve a different provider binary, and the runtime | |
| // manager only learns about one through this refresh: it clears the gate | |
| // and evicts idle runtimes so the thread launches against the new env. It | |
| // has to run before the memo is consulted, since a hit would otherwise | |
| // skip the probe that used to carry the refresh, and before the gate | |
| // samples its generation, so the clear does not discard the fresh probe. | |
| // The refresh's own short TTL keeps back-to-back starts free. | |
| await options.refreshShellEnv(); | |
| // The probe spawns the provider CLI several times, so a remembered | |
| // supported answer is served without touching the maintenance bridge or | |
| // re-verifying the bridge artifact. | |
| const status = await options.runtimeManager.providerInstallationGate.run( | |
| providerInstallationGateKey({ | |
| providerId: command.providerId, | |
| bridgeLaunch: command.bridgeLaunch, | |
| requirement, | |
| }), | |
| async () => { | |
| const bridgeLaunch = await resolveRuntimeBridgeLaunch( | |
| command.bridgeLaunch, | |
| options, | |
| ); | |
| return options.providerInstallationStatus({ | |
| providerId: command.providerId, | |
| bridgeLaunch, | |
| ...(requirement !== undefined ? { requirement } : {}), | |
| }); | |
| }, | |
| ); |
A changed shell environment clears the gate and immediately shuts down the maintenance runtime:
bb/apps/host-daemon/src/runtime-manager.ts
Lines 659 to 671 in c2837e0
| async replaceBaseShellEnv( | |
| shellEnv: NonNullable<AgentRuntimeOptions["shellEnv"]>, | |
| ): Promise<void> { | |
| if (shellEnvEquals(this.baseShellEnv, shellEnv)) { | |
| return; | |
| } | |
| this.baseShellEnv = { ...shellEnv }; | |
| // A new PATH can resolve a different provider binary, so the remembered | |
| // version check no longer describes what a thread would run. | |
| this.providerInstallationGate.clear(); | |
| await this.shutdownProviderMaintenanceRuntime(); | |
| await this.evictIdleRuntimeEntries(); |
The gate avoids caching a pre-invalidation answer, but still returns that stale promise or rejection to callers that were already waiting:
bb/apps/host-daemon/src/provider-installation-gate.ts
Lines 84 to 134 in c2837e0
| return { | |
| clear() { | |
| generation += 1; | |
| settledByKey.clear(); | |
| pendingByKey.clear(); | |
| }, | |
| run(key, probe) { | |
| const currentTime = now(); | |
| const settled = settledByKey.get(key); | |
| if (settled !== undefined) { | |
| if (settled.expiresAt > currentTime) { | |
| return Promise.resolve(settled.status); | |
| } | |
| settledByKey.delete(key); | |
| } | |
| const pending = pendingByKey.get(key); | |
| if (pending !== undefined) { | |
| return pending; | |
| } | |
| const startedGeneration = generation; | |
| const started = probe() | |
| .then((status) => { | |
| const settledAt = now(); | |
| // Expired neighbours are swept here rather than on a timer so the | |
| // map stays bounded without keeping the process alive. | |
| pruneExpired(settledAt); | |
| // Bridges report `versionUnsupported: false` for a CLI that is not | |
| // installed at all. Only a bridge that enforces a minimum version | |
| // (codex, pi) can turn a too-old CLI installed in the meantime, | |
| // without a PATH change, into an unsupported answer, so only its | |
| // not-installed answer is worth forgetting. A bridge that reports | |
| // `minimumSupportedVersion: null` (Claude Code, ACP) can never | |
| // reject, and its launcher finds the executable on its own, so its | |
| // not-installed answer is remembered like a supported one. | |
| if ( | |
| (status.installed || status.minimumSupportedVersion === null) && | |
| !status.versionUnsupported && | |
| startedGeneration === generation | |
| ) { | |
| settledByKey.set(key, { status, expiresAt: settledAt + ttlMs }); | |
| } | |
| return status; | |
| }) | |
| .finally(() => { | |
| if (pendingByKey.get(key) === started) { | |
| pendingByKey.delete(key); | |
| } | |
| }); | |
| pendingByKey.set(key, started); | |
| return started; | |
| }, |
Relevant host-daemon log for both starts:
type="thread.start" message="Runtime shutting down"
at shutdownProviderMaintenanceRuntime
at replaceBaseShellEnv
What you ruled out
- The personal workspaces provisioned successfully, so this was not workspace provisioning failure.
- Neither provider session began; the prompts and requested shell command were never processed.
- Both independent environments failed simultaneously, ruling out workspace-local state.
- Stable provider-probe failures still surface normally; only a probe invalidated by a gate generation change should retry.
- Searched open and closed issues for
Runtime shutting down, thread start, provider maintenance, and shell-environment refresh; no duplicate found.
Suggested priority and effort
High. The race silently turns accepted user messages into permanent error threads. Retrying in a new thread is a workaround, but the original work does not recover. The fix is localized to the shared provider-installation gate.
- Reproduced from live thread evidence and with a deterministic regression test on the base commit.
- Searched open and closed issues for the same problem.
- Agent-written report links the investigation thread.
AGENT GENERATED
Activity
fix(host-daemon): retry provider probes after invalidation (get-bb#2381)