Repository navigation
Description
Summary
Selecting “new worktree on M5” left the provider/model picker loading for about 60 seconds. The M5 daemon still sent heartbeats, so the server treated it as connected, but every server-to-M5 host RPC timed out; the expected behavior is that a one-way-stale daemon connection is replaced promptly and provider discovery has one bounded wait.
Versions and environment
- bb from source at commit
21cb6b68b8fdffe2cd576f11c8af500f98d22c11(also reproduced while preparing a fix against currentmain) - Server and enrolled daemon protocol version 164
- Server host: macOS on M4
- Remote persistent host: Apple Silicon M5, routed through bb Connect; exact macOS version was unavailable once the machine went offline
- Provider initially selected: Codex, but the failure reproduced for every host RPC and was not provider-specific
- Project
proj_qrv2s45kmq, threadthr_67snhz37mn, hosthost_stzudmkj6u
Steps to reproduce
The sleep/network transition that creates the stale relay leg is timing-sensitive, but these steps reproduced the product failure once it occurred:
-
Enroll a persistent remote Mac through bb Connect.
-
Let the remote Mac sleep or lose networking without a clean WebSocket close, then wake it.
-
Select that machine in the new-worktree picker.
-
Run:
time bb provider models codex --machine M5 --json time bb project paths proj_qrv2s45kmq --machine M5 --limit 1 --json
-
Compare with the same commands using
--machine M4.
Expected vs actual
Expected:
- the daemon reconnects when the server-to-daemon path is no longer usable
- provider/model discovery returns promptly or reports the host unavailable
- selecting “new worktree on M5” does not leave the picker spinning
Actual:
- bb provider models codex --machine M5 --json took 60.19s and returned []
- bb project paths ... --machine M5 took 30.14s and returned HTTP 504
- bb provider list --machine M5 took 60.18s
- equivalent M4 provider listing completed in about 1.18s
- server logs repeatedly reported:
errorCode=command_timeout errorStatus=504 hostId=host_stzudmkj6u
Evidence
- Session
hses_42c3a9z5fjremained registered while its heartbeat timestamp advanced, including after a roughly nine-minute heartbeat gap, yet all outbound host RPCs timed out. - All server-to-M5 commands failed, including provider health, provider model listing, project paths, remote file reads, and update status.
- M5 later showed a repeated disconnect/reconnect pattern with 3–12 minute gaps, and Tailscale independently showed it offline while bb still held an active daemon session. Tailscale is not the bb transport; it confirms the machine lost networking or slept.
- The daemon heartbeat was fire-and-forget, with no proof that the return direction worked:
bb/apps/host-daemon/src/server-connection.ts
Lines 722 to 776 in 21cb6b6
private resetHeartbeat(): void { this.clearHeartbeat(); if (!this.session) { return; } this.lastHeartbeatTickAt = Date.now(); this.heartbeatInterval = setInterval(() => { const session = this.session; if (!session) { return; } const now = Date.now(); const lastTickAt = this.lastHeartbeatTickAt; if (lastTickAt !== null) { const gapMs = now - lastTickAt; const thresholdMs = session.leaseTimeoutMs / 2; if ( isLikelySystemSuspensionDelay({ gapMs, intervalMs: session.heartbeatIntervalMs, }) ) { this.options.logger.info( { gapMs, heartbeatIntervalMs: session.heartbeatIntervalMs, leaseTimeoutMs: session.leaseTimeoutMs, sessionId: session.sessionId, websocketReadyState: this.websocket?.readyState ?? null, }, "Host daemon resumed after likely system suspension", ); } else if (gapMs > thresholdMs) { this.options.logger.warn( { gapMs, heartbeatIntervalMs: session.heartbeatIntervalMs, leaseTimeoutMs: session.leaseTimeoutMs, sessionId: session.sessionId, websocketReadyState: this.websocket?.readyState ?? null, }, "Host daemon heartbeat timer delayed", ); } } this.lastHeartbeatTickAt = now; if (!this.websocket || this.websocket.readyState !== OPEN_READY_STATE) { return; } this.sendMessage({ type: "heartbeat" }); }, this.session.heartbeatIntervalMs); - The server renewed the session for every inbound message but did not acknowledge a heartbeat:
bb/apps/server/src/ws/daemon-protocol.ts
Lines 104 to 194 in 21cb6b6
args.socket.close(1008, "invalid-message"); return; } try { runEventLoopWorkSync(`ws:daemon ${result.data.type}`, () => { const session = requireAuthorizedOpenSession(deps.db, { hostId: args.hostId, sessionId: args.sessionId, }); heartbeatSession( deps.db, session.id, Math.max( Date.now() + session.leaseTimeoutMs, session.leaseExpiresAt + 1, ), ); if (result.data.type === "environment-change") { notifyDaemonEnvironmentChange(deps, { hostId: args.hostId, environmentId: result.data.environmentId, change: result.data.change, }); return; } if (result.data.type === "environment-metadata-change") { recordDaemonEnvironmentMetadataChange(deps, { hostId: args.hostId, environmentId: result.data.environmentId, workspace: result.data.workspace, }); return; } if (result.data.type === "host-rpc.response") { const disposition = deps.hub.recordHostOnlineRpcResponse({ message: result.data, sessionId: args.sessionId, }); if (!disposition.handled && disposition.reason === "session_mismatch") { deps.logger.warn( { commandType: result.data.commandType, expectedSessionId: disposition.expectedSessionId, requestId: result.data.requestId, sessionId: args.sessionId, }, "Ignoring host RPC response from mismatched daemon session", ); } else if (!disposition.handled) { deps.logger.debug( { commandType: result.data.commandType, requestId: result.data.requestId, sessionId: args.sessionId, }, "Ignoring stale host RPC response", ); } return; } if (result.data.type === "connect-tunnel.identity") { deps.sharedPorts.recordTunnelIdentity( args.hostId, result.data.identity, ); return; } if (result.data.type === "plugin-host.worker-exited") { plugins?.handleHostWorkerExit({ authenticatedHostId: args.hostId, pluginId: result.data.pluginId, generation: result.data.generation, }); return; } if (result.data.type === "plugin-host.signal") { plugins?.handleHostSignal({ authenticatedHostId: args.hostId, pluginId: result.data.pluginId, generation: result.data.generation, signal: result.data.signal, payload: result.data.payload, }); return; } if (result.data.type !== "heartbeat") { deps.terminalSessions.handleDaemonTerminalMessage({ hostId: args.hostId, message: result.data, sessionId: args.sessionId, - Installed-only provider discovery used concurrency three with a separate 30-second timeout for each wave, so four probes took about 60 seconds: and
bb/apps/server/src/services/system/execution-options.ts
Lines 161 to 213 in 21cb6b6
async function listInstalledPluginProviderInfos( deps: LoggedWorkSessionDeps, hostId: string, capability?: ProviderCapabilityFilter, ): Promise<ProviderInfo[]> { const registrations = deps.providerRegistry .list() .filter( (registration) => registration.visibility === "installed" && providerMatchesCapability(registration.info, capability), ); const results = await mapProviderMaintenanceRequests( registrations, async (registration) => { const bridgeLaunch = resolveBridgeLaunchForProviderId( deps, registration.info.id, ); if (bridgeLaunch === null) return null; try { const result = await callHostRetryableOnlineRpc(deps, { hostId, timeoutMs: COMMAND_TIMEOUT_MS, command: { type: "provider.health", providerId: registration.info.id, bridgeLaunch, }, }); return result.supported && result.health.status !== "not_installed" ? registration.info : null; } catch (error) { if (!canOmitProviderDiscoveryForError(error)) { throw error; } deps.logger.warn( { ...expectedFallbackErrorLogFields(error), hostId, providerId: registration.info.id, }, "Failed to resolve installed-only provider status", ); return null; } }, ); return results.filter( (provider): provider is ProviderInfo => provider !== null, ); } const PROVIDER_MAINTENANCE_CONCURRENCY = 3; /** * Provider maintenance calls can verify artifacts and start bridge workers. * Keep a large plugin roster from doing all of that host-local work at once * while preserving registry order in the response. */ export async function mapProviderMaintenanceRequests<TValue, TResult>( values: readonly TValue[], request: (value: TValue, index: number) => Promise<TResult>, ): Promise<TResult[]> { const results = new Array<TResult>(values.length); const remaining = values.entries(); const workerCount = Math.min(PROVIDER_MAINTENANCE_CONCURRENCY, values.length); await Promise.all( Array.from({ length: workerCount }, async () => { for (const [index, value] of remaining) { results[index] = await request(value, index); } }), ); return results; }
What you ruled out
- Not provider-specific: non-provider host RPCs timed out too.
- Not a daemon protocol mismatch: both sides reported protocol 164.
- Not a disconnected server-side session: the hub still had the daemon socket registered and inbound heartbeats renewed the database lease.
- Not a generally slow M5 command: no command response arrived before its timeout.
- No matching open or closed issue was found for a one-way-stale remote daemon WebSocket.
Suggested priority and effort
High for remote-host users: it blocks worktree creation and other remote operations. Restarting or waking the daemon until it establishes a fresh session is a workaround; no data loss was observed.
AGENT GENERATED
Activity
Recover one-way-stale remote daemon connections (get-bb#2359)
Preserve heartbeat grace after short suspension (#2372)
Mark silent hosts offline without cancelling their work (#4271)