Skip to content

Host daemon falls back to bare launchd PATH when login-shell probe fails, breaking provider CLI detection (codex/claude) until daemon restart #5292

Closed as duplicate

Description

@theFong

Summary

The bb host daemon builds the PATH it hands to provider bridges, plugin workers, terminals, and setup hooks from a one-shot login-shell probe taken at daemon startup (runtime-shell-env.ts). When that probe fails or times out - which is easy on macOS, where the interactive probe ($SHELL -ilc) regularly takes 1.2-1.9 s against the 3 s timeout and can exceed it while the machine is under load at login - the daemon silently falls back to its own bare launchd PATH (/usr/bin:/bin:/usr/sbin:/sbin). Every provider CLI lookup then fails ("bb could not find the Codex CLI", "spawn cursor-agent ENOENT") even though the CLIs are installed, until the daemon happens to be restarted at a moment the probe succeeds.

Two aggravating design issues:

  1. The startup fallback is captured once and kept. resolveUserShellPathWithPrevious caches previousPath only on success, so after a failed startup probe the effective PATH stays the broken daemon PATH until a later refresh succeeds - and the machine-environment layer (machine-environment.ts) falls back to exactly that captured value whenever a managed PATH variable is removed from Settings -> Environment variables.
  2. The non-interactive fallback probe (-lc) omits anything configured in ~/.zshrc. On macOS the Claude Code installer instructs users to add ~/.local/bin to ~/.zshrc, and tools like bun/opencode often live there too. -lc sources .zprofile/.zshenv but not .zshrc, so a "successful" probe via the -lc fallback still cannot find claude.

This is invisible while a global machine environment PATH variable exists (it overrides the broken shell PATH for every bb shell), which is why it surfaces as "removing the synced PATH broke codex/claude on my Mac." Removing the variable is correct; the daemon fallback PATH is what is broken.

Versions and environment

  • bb 0.45.0 (desktop app on macOS, enrolled host daemon via the app.getbb.host-daemon launchd service; bb-app npm package 0.45.0)
  • macOS (Darwin 25.6.0), Node 22.22.0
  • Providers: claude-code (claude 2.1.296 at ~/.local/bin/claude), codex (codex-cli 0.159.0 at /opt/homebrew/bin/codex)
  • Host daemon started by launchd with PATH=/usr/bin:/bin:/usr/sbin:/sbin, SHELL=/bin/zsh

Steps to reproduce

  1. Enroll a macOS machine so the host daemon runs from launchd (bare PATH, no user shell env).
  2. Ensure ~/.zshrc adds ~/.local/bin (the Claude Code installer default) and that the daemon starts while the machine is busy enough that $SHELL -ilc exceeds 3 s (measured 1.9 s idle; boot/login storms exceed it).
  3. Observe the daemon captured shell env: a plugin/bridge worker spawned afterwards has PATH=<bb dist dir>:/usr/bin:/bin:/usr/sbin:/sbin (via ps eww <worker-pid>).
  4. Start a codex or claude-code thread: the turn fails with "bb could not find the Codex CLI on this machine" / "spawn claude ENOENT".
  5. Restart the daemon (launchctl kickstart -k gui/$(id -u)/app.getbb.host-daemon.<server>-<hostId>) when the machine is idle: workers now get the full login-shell PATH and the same providers work immediately, with no other change.

Also reproducible purely at the probe layer:

# ~1.9s idle on macOS - the 3s timeout has little headroom under load
time /bin/zsh -ilc true
# -lc fallback omits ~/.zshrc entries:
/bin/zsh -ilc 'env' | grep '^PATH=' | tr ':' '\n' | grep -c '.local/bin'   # 1
/bin/zsh -lc  'env' | grep '^PATH=' | tr ':' '\n' | grep -c '.local/bin'   # 0

Expected vs actual

Expected: bb shells always carry at least the user's login-shell PATH; if the interactive probe times out, the fallback should still include the directories users are told to put CLIs in, and the daemon should retry the probe rather than keep a broken capture.

Actual (worker env captured with ps eww after a failed startup probe):

PATH=/Users/alecf/.bb/npm/lib/node_modules/bb-app/host-daemon/dist:/usr/bin:/bin:/usr/sbin:/sbin

Corresponding provider failures in ~/.bb/logs/host-daemon.8.log:

{"level":40,"type":"provider.list_models","err":{"message":"bb could not find the Codex CLI on this machine. Install Codex (https://developers.openai.com/codex/cli) or put `codex` on PATH, then retry."}}
{"level":40,"type":"provider.list_models","err":{"message":"spawn cursor-agent ENOENT"}}

After a daemon restart at an idle moment, the same worker class gets:

PATH=/Users/alecf/.bb/npm/lib/node_modules/bb-app/host-daemon/dist:/Users/alecf/.bun/bin:...:/Users/alecf/.local/bin:...:/opt/homebrew/bin:...

and codex/claude-code work with no other change.

Evidence

  • Probe + fallback: apps/host-daemon/src/runtime-shell-env.ts - USER_SHELL_ENV_TIMEOUT_MS = 3_000 at
    const USER_SHELL_ENV_TIMEOUT_MS = 3_000;
    ; arg sets -ilc then -lc in userShellEnvArgSets (same file, ~L313); prepareRuntimeShellEnv falling back to process.env.PATH at apps/host-daemon/src/start-host-daemon.ts#L160 ((await resolveUserShellPath()) ?? process.env.PATH).
  • Machine-environment interaction: apps/host-daemon/src/machine-environment.ts#L32-40 (shellEnvironment) - when a managed PATH variable is removed, shells fall back to originalShell.PATH, i.e. the startup capture; if that was the failed-probe fallback, removing the variable surfaces the breakage.
  • Observed on bb 0.45.0: daemon started Oct 5 from launchd; worker spawned Oct 9 with the bare PATH (above); errors provider.list_models "could not find the Codex CLI" / "spawn cursor-agent ENOENT" in ~/.bb/logs/host-daemon.8.log; launchctl kickstart -k on the daemon fixed both providers with zero other changes.
  • Timing measurement: /bin/zsh -ilc true took 1.2-1.9 s real on an idle M3 Pro; the 3 s timeout leaves about 1 s of headroom.

What you ruled out

Suggested priority and effort

Medium: hits any macOS (and likely Linux systemd) enrolled host whose daemon starts under a stripped environment while the interactive probe times out - common right after boot/login. User-visible symptom is providers "not installed" though they are. A restart workaround exists but is undiscoverable. Likely fixes (maintainer's call): retry the probe with backoff before settling for process.env.PATH, raise the timeout, and/or merge probe results across -ilc/-lc attempts instead of first-win; optionally re-probe periodically rather than caching the startup capture indefinitely.

AGENT GENERATED

Activity

  1. added theissue type on Oct 9, 2026
  2. added
    host
    providers
    partial-repro
    on Oct 9, 2026
  3. bb-slop-cop commented on Oct 9, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Classification: Bug · Priority: Medium · Effort: Medium. Labels: host, providers, partial-repro.
    • Report: https://get-bb.github.io/reports/issues/5292.html
    • Verdict: PARTIALLY REPRODUCED · root-cause confidence: high for the verified PATH-restoration defect.
    • Evidence: Two clean trusted-main checkouts reproduce child lookup failing with ENOENT after a successful shell refresh: removing a managed PATH causes the machine-environment overlay to restore its stale startup snapshot. Three control cases pass in each run; 35 relevant existing tests pass.
    • Correction: Main already has request-triggered shell refresh with a 10-second TTL. Native macOS launchd timing and real provider behavior remain unverified.
    • No PR: A complete repair requires choosing startup retry/fallback and removed-variable restoration policies, failing the simple-fix gate.

    AGENT GENERATED

  4. maxweissenbaeck commented on Oct 19, 2026

    @maxweissenbaeck

    Native macOS repro with a real provider, in case it helps close the "unverified" part.

    Setup: BB 0.46.1, macOS 27 (Apple Silicon). This Mac is an execution host of a remote BB server on another Mac, reached over Tailscale. The local host daemon runs as a LaunchAgent (app.getbb.host-daemon.<server>-<host-id>.plist) whose EnvironmentVariables contain only BB_APP_NPM_PREFIX and BB_DATA_DIR, no PATH. Codex (v0.163.0) is installed through npm under nvm.

    Repro: a normal reboot. At the login start, ps eww showed the daemon and its provider bridge worker with PATH=/usr/bin:/bin:/usr/sbin:/sbin. Every Codex turn then failed:

    bb could not find the Codex CLI on this machine. Install Codex … or put `codex` on PATH, then retry.
    codex app-server exited unexpectedly (code null, signal null): spawn codex ENOENT
    

    The Mac was under very heavy load right after login (load average ~250 from Spotlight and post-boot indexing), which may be why the login-shell probe failed. Before the reboot, the daemon had been started from a shell and had the full PATH, so it only broke at the first launchd login start.

    What didn't help: quitting and reopening the BB desktop app (twice). The app's own processes got the full login PATH, but the LaunchAgent daemon that runs the provider work wasn't restarted.

    What fixed it: bb machine env set PATH (global) with the login PATH, then launchctl kickstart -k gui/$UID/<host-daemon label>. After that, the daemon process itself still showed the bare PATH, but the provider bridge worker had the machine-env PATH and Codex turns started again. (Not yet verified across a second reboot.)

    Suggestions: retry the login-shell probe (or fall back to path_helper and the common Homebrew/nvm locations) when it fails at startup, write PATH into the LaunchAgent plist at enrollment, and name the searched PATH in the ENOENT error.

  5. ymichael commented on Nov 17, 2026

    @ymichael
    Collaborator

    #6194 replaced the bare launchd fallback. What's left is tracked in #6586. Closing as a duplicate.

    AGENT GENERATED

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    hostpartial-reproproviders

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions