Skip to content

claude-code: new thread's first turn silently killed by idle-runtime eviction on cosmetic shell-env drift (fnm multishells) — stuck on "Working…" forever #1156

Closed

Description

@bighitbiker3

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

  1. The daemon resolves the user's login-shell environment (zsh -ilc 'printf __BB_SHELL_ENV_START__; env; …') with a ~10s TTL cache (DK=1e4 in the daemon bundle).
  2. 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).
  3. replaceBaseShellEnv compares envs by strict equality, sees a "change", and calls shutdownProviderMaintenanceRuntime() + evictIdleRuntimeEntries().
  4. 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.start settles immediately (prompt queued via queue-operations) and turn/started doesn't fire until ~5–7s later — so the freshly spawned runtime looks idle and is evicted mid-startup.
  5. 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.
  6. Server-side, the turn was dispatched but turn/started never arrives, and there is no watchdog/timeout for this state → the thread shows "Working…" forever.
  7. 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.
  8. Stop + re-send recovers because turn.submit recreates 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.084 server: thread created, thread/start + turn/start dispatched to the (pre-existing) env bridge — both visible in the trace as daemon pipe writes
  • 14:31:12.349 daemon: execve zsh -ilc 'env' probe → fnm env --shell zsh → new multishell dir
  • 14:31:13.081 bridge spawns claude --output-format stream-json … --session-id 82f29bc8-…
  • 14:31:15.361 second probe zsh -lc 'env' → another new multishell dir (…_1786131075413)
  • 14:31:20.3 probe 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 at 14:31:20.28 using the fresh multishell path.
  • Thread shows "Working…" until the user stops it at 14:31:37 (event system/thread/interrupted), with no turn/started ever 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)

  1. 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.
  2. Don't classify a starting thread as idle. A runtime whose thread.start/turn/start was accepted but whose turn hasn't started yet should count as active work for evictIdleRuntimeEntries()/replaceEntryForSkillCatalog() (e.g., keep the in-flight retain until turn/started, not until the RPC settles).
  3. Add a turn-start watchdog. If a dispatched turn produces no turn/started within 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 later No runtime exists for environment error 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

  1. added theissue type on Aug 8, 2026
  2. self-assigned this
    on Aug 8, 2026
  3. added a commit that references this issue on Aug 8, 2026
    3e77578
  4. added a commit that references this issue on Aug 14, 2026
    ebcdeb5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions