Repository navigation
Serve command lists from the last shell env; stop phone command prefetch - #6219
Merged
ymichael merged 1 commit intoOct 26, 2026
Merged
Conversation
The daemon's provider.list_commands and provider.usage now use the last resolved login-shell environment and refresh it in the background, as thread start does since #4022. Model listing, provider health and installation status/run still wait for a fresh environment once the 10s cache expires, because their answers depend on the current PATH. The first resolution after daemon start still blocks. The composer no longer prefetches the command catalog when focus enters it on coarse pointers. Opening a thread focuses its composer, so every thread open on a phone requested the catalog. Commands now load on the first / or $ query and show the existing "Searching commands…" state until they arrive. The focus listener, the prefetch request path and its query-options helper are removed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
deleted the
bb/cheap-first-command-list-no-phone-prefetch-thr_wueryp4vjz
branch
October 26, 2026 17:33
ymichael
added a commit
that referenced
this pull request
Oct 29, 2026
…6571) ## Human comments ## What was wrong Since #6219, `providerUsage` refreshes the login-shell env with `allowStale: true`, so the refresh can land while the usage request is still running. When PATH changed, `RuntimeManager.replaceBaseShellEnv` shut down the provider maintenance runtime immediately, including one with a request in flight, and that request failed with `Provider "codex" is not running`. With fnm, PATH changes on every probe (`eval "$(fnm env)"` mints a new `fnm_multishells/<pid>_<ms>` dir), so every usage call on that host failed. Fixes #6533. ## What changed `apps/host-daemon/src/runtime-manager.ts`: - The maintenance runtime now lives in a slot that counts the requests using it, including requests still waiting for it to start. When the shell env changes or a provider update invalidates it, a busy slot is retired: new requests get a fresh runtime, and the old runtime shuts down when its last request finishes. Idle slots still shut down immediately, and `shutdownAll` still stops every slot right away, busy or retired. This replaces the old pending/generation/active-count fields. - `shellEnvEquals` ignores the `fnm_multishells/<id>` segment of PATH entries, so per-shell fnm drift no longer counts as an env change for maintenance or environment runtimes (the trigger behind #1156). No wire changes, so there is no `HOST_DAEMON_PROTOCOL_VERSION` bump. ## How you verified - New tests in `runtime-manager.test.ts`: - A busy maintenance runtime survives a PATH change, concurrent requests get the fresh runtime, and the old runtime shuts down after its request resolves. - An fnm-multishell-only PATH change keeps the runtime, while a real PATH change still replaces it. - `shutdownAll` stops a retired runtime that still has a request in flight. - The first two tests fail against the old `runtime-manager.ts` and pass with the fix. - The existing pending-turn eviction test used fnm paths to force an eviction; it now uses plain PATH changes. The stale-creation race test now asserts through the public API instead of a removed private field. - `pnpm exec turbo run typecheck test lint --filter=@bb/host-daemon`: 839 tests passed. Fixes #6533 > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
Every new thread gets its own worktree, so the first command-list lookup for a thread always reaches the machine, even with the server-side cache in #6210. On the machine,
provider.list_commandsran throughwithMaintenanceRuntime, which waited for a fresh login-shell environment whenever the cached one was more than 10s old. That wait is 0.6–2.2s depending on the shell. #4022 made thread start use the last resolved environment and refresh it in the background, but kept every maintenance request blocking, so command listing still paid for the login shell. Separately,shouldPrefetchCommandCatalogprefetched the catalog whenever focus entered a composer on a coarse pointer. Opening a thread focuses its composer, so every thread open on a phone sent this request, even when nobody typed a command.What changed
Daemon (
apps/host-daemon/src/app.ts).withMaintenanceRuntimenow takes the shell-environment refresh mode explicitly at each call site:provider.list_commandsprovider.usageprovider.list_modelsprovider.healthprovider.installation.status/.runThe first resolution after daemon start still blocks for every request. The cache only serves a stale environment once one has been resolved. No wire fields change, so there is no
HOST_DAEMON_PROTOCOL_VERSIONbump.App. The coarse-pointer focus prefetch is gone, along with everything that existed only for it:
focusinlistener incomposer-root.tsx;prefetchCommands/useComposerCommandPrefetchincomposer-search.tsx;composerFocused,shouldPrefetchCommandCatalogandprefetchCommandCataloginuseCommandSuggestions.ts;projectCommandsQueryOptions, now inlined back intouseProjectCommands.The catalog loads on the first
/or$query. On first open the menu shows what it already has (prompt-action commands such asplanandgoal) with the refreshing spinner, then fills in the catalog. With nothing to show yet, it shows the existing "Searching commands…" row.docs/api_to_audit.md(composer search contract) now says that commands load on the first command query rather than when focus enters the composer.This is independent of #6210 and based on main. The two together make the first lookup in a new worktree cheap: #6210 serves repeat lookups from the server, and this change removes the login-shell wait from the misses.
Remaining cost on a miss: the maintenance runtime still restarts after 60s idle, plus Claude Code's startup check (about 350ms total in the measurements below). One race existed before this change and is unchanged: if a background refresh finds a different PATH while a listing request is in flight,
replaceBaseShellEnvshuts down the maintenance runtime under that request. The shell env holds only PATH and bb's own variables, so this only happens when PATH actually changes.How you verified
apps/host-daemon/src/app.test.ts: a table test runs each of the six maintenance RPCs with an expired shell env and a pending login-shell resolution.list_commandsandusageanswer on the last resolved env without waiting.list_models,health,installation.statusandinstallation.rundon't reach the runtime until the fresh env resolves, and then run on it. A second test checks thatlist_commandsstill waits for the first resolution after daemon start. FlippinglistCommandsto blocking, orproviderHealthto stale, fails the matching case.apps/app/src/hooks/useCommandSuggestions.dom.test.tsx: the real hook makes no catalog request before a trigger, reportsisLoadingwhile the first request is pending, then returns the catalog.pnpm exec turbo run test --filter=@bb/host-daemon: 823 passed, 12 skipped.pnpm exec turbo run test --filter=@bb/app -- src/hooks/useCommandSuggestions src/components/promptbox src/components/plugin/PluginNewThreadComposer: 599 passed.pnpm exec turbo run typecheck --filter=@bb/app --filter=@bb/host-daemonandpnpm exec turbo run lint --filter=@bb/app(0 errors) passed.pnpm start:worktreebuild: Chrome at 390×844 withpointer: coarseemulated. Tapping into the new-thread composer sent no/commandsrequest. Typing/sent one request; the menu showed the prompt-action commands with the spinner, then the full catalog when the (artificially delayed 1.5s) response landed.Measurements.
GET /api/v1/projects/:id/commands?provider=claude-codeon apnpm start:worktreeinstance (main without #6210, so every call reaches the daemon). This machine's login-shell resolution takes about 570ms. Before = this branch withlistCommandsswitched back toallowStale: false, otherwise identical build.🤖 Generated with Claude Code