Repository navigation
Description
Summary
On this machine, 14 of the last 16 claude-code threads created from the UI hung on "Working…" forever at their first message. The claude CLI spawns and receives the prompt, then is silently shut down a few seconds later; the server never learns the turn died, shows "Working…" indefinitely, and the Stop button fails internally with No runtime exists for environment …. Stopping and re-sending ("kicking") the thread always recovers it.
Root cause (traced end-to-end with strace on the host daemon, session files, and the events table): the daemon's shell-env refresh treats a cosmetic PATH difference as a real change and mass-evicts "idle" runtimes — and a claude-code thread whose first turn is still starting up counts as idle.
Environment
- bb-app 0.35.1, headless Linux server install (Ubuntu, Node v22.22.2 via fnm), accessed remotely via bb connect
- Provider: claude-code (Claude Code CLI under
~/.local/share/fnm/...) - zsh with
eval "$(fnm env)"in.zshenv/.zprofile/.zshrc
The failure chain
- The daemon resolves the user's login-shell environment (
zsh -ilc 'printf __BB_SHELL_ENV_START__; env; …') with a ~10s TTL cache (DK=1e4in the daemon bundle). - Every probe evals
fnm env, which mints a unique/run/user/<uid>/fnm_multishells/<pid>_<timestamp>directory and prepends it to PATH. So every resolution differs from the last one (this box has accumulated >100k multishell dirs). replaceBaseShellEnvcompares envs by strict equality, sees a "change", and callsshutdownProviderMaintenanceRuntime()+evictIdleRuntimeEntries().evictIdleRuntimeEntries()shuts down every runtime entry with no active thread IDs, terminals, or in-flight thread commands. A claude-code thread's first turn is only queued during CLI startup —thread.startsettles immediately (prompt queued via queue-operations) andturn/starteddoesn't fire until ~5–7s later — so the freshly spawned runtime looks idle and is evicted mid-startup.- The CLI dies gracefully (session jsonl records
[Request interrupted by user]with"interruptedByShutdown": true~2.4s after the prompt was committed). Nothing is logged daemon- or server-side. - Server-side, the turn was dispatched but
turn/startednever arrives, and there is no watchdog/timeout for this state → the thread shows "Working…" forever. - Because eviction deletes the entry, a subsequent user Stop fails with
CommandDispatchError: No runtime exists for environment env_…(unknown_environment) — visible in host-daemon/server logs for every hung thread. - Stop + re-send recovers because
turn.submitrecreates the runtime and resumes the session.
The UI flow reliably loses the race because opening the new thread view triggers extra daemon work (composer/model warm-up → maintenance runtime creation → another TTL-expired env probe) right inside the vulnerable window. bb thread spawn threads usually survive — same thread/start payload byte-for-byte, just no follow-on probe in the window.
Captured evidence (one instance, strace attached to the daemon)
14:31:12.084server: thread created,thread/start+turn/startdispatched to the (pre-existing) env bridge — both visible in the trace as daemon pipe writes14:31:12.349daemon:execve zsh -ilc 'env'probe →fnm env --shell zsh→ new multishell dir14:31:13.081bridge spawnsclaude --output-format stream-json … --session-id 82f29bc8-…14:31:15.361second probezsh -lc 'env'→ another new multishell dir (…_1786131075413)14:31:20.3probe result lands → env "differs" → eviction: the env bridge exits, the 7-second-old claude process is orphaned (reparented to init) and dies. A new maintenance bridge spawns at14:31:20.28using the fresh multishell path.- Thread shows "Working…" until the user stops it at
14:31:37(eventsystem/thread/interrupted), with noturn/startedever recorded.
Multishell-dir creation timestamps line up within seconds of the CLI death in every hung thread examined across two days.
Suggested fixes (any one of these breaks the chain; all three are worth having)
- Don't treat cosmetic env drift as a change. Ignore volatile components when diffing the resolved shell env (fnm multishell paths are the obvious case), or only evict when something the runtimes actually depend on changed — or don't evict running-state environments on env refresh at all.
- Don't classify a starting thread as idle. A runtime whose
thread.start/turn/startwas accepted but whose turn hasn't started yet should count as active work forevictIdleRuntimeEntries()/replaceEntryForSkillCatalog()(e.g., keep the in-flight retain untilturn/started, not until the RPC settles). - Add a turn-start watchdog. If a dispatched turn produces no
turn/startedwithin N seconds, fail the turn visibly instead of showing "Working…" forever. Relatedly, when a runtime is shut down/exits while a turn is pending, surface that as a thread error — today it is completely silent, and the only artifact is the laterNo runtime exists for environmenterror when the user clicks Stop.
Investigated with Claude Code on the affected machine; happy to provide the full strace capture, session files, or run a patched build to verify a fix.
Activity
Protect pending turns from runtime eviction (get-bb#1196)
Protect pending turns from runtime eviction (get-bb#1196)
Add the turn-start watchdog: stalled dispatches become visible errors
Keep provider usage requests alive across login-shell env refreshes (#…