Repository navigation
Keep path search on huge workspaces from dropping the host - #5507
Merged
Merged
Conversation
Ranking a million-path listing ran synchronously on the daemon's event loop, so a burst of @-mention searches starved heartbeats past the 30 s lease and the server closed the daemon session. - Rank large listings in 10k-path chunks that yield between chunks, one large ranking at a time. - Skip fuzzy scoring for paths that cannot contain the query's characters in order. - Add a host-rpc.cancel message: the server sends it when the HTTP client aborts or its wait times out, and the daemon aborts the matching path or file search. Bumps HOST_DAEMON_PROTOCOL_VERSION to 236. Fixes #5385 Co-Authored-By: Claude Opus 5.5 <[email protected]>
On a million-path workspace every keystroke re-walked the tree, about 3 s, while ranking took about 0.25 s. Listings that take at least 500 ms to walk are now cached per root and options: searches reuse the cached listing, refresh it in the background once it is 2 s old, and walk again in the foreground once it is 30 s old. Faster listings are never cached, so small workspaces still see every file change immediately. Co-Authored-By: Claude Opus 5.5 <[email protected]>
While newer path, thread or plugin mention results load, the menu kept showing the previous results with no indication they were stale. The mention hooks now report isRefreshing when results are on screen and a search is still debouncing or fetching, and the first section header shows a spinner whose space is always reserved, so the rows do not move. 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
host.list_paths/host.list_fileswalk the whole workspace and then fuzzy-rank every path synchronously on the host daemon's event loop. On a workspace with about 1M non-ignored paths, onepackages/query takes about 14 s of CPU. A typing burst queues several of these back to back, so the daemon sends nothing, heartbeats included, for longer than the 30 s lease. The server then logsDaemon sent nothing within its lease; closing its socketand every host request fails withhost_unavailable(#5385). Searches the browser had already abandoned also kept running to completion. Server-side timeout retries re-sent the same search under a new request ID. So the daemon stayed busy with stale work, and the newest keystroke still timed out.What changed
apps/host-daemon/src/command-handlers/file-list.ts): listings over 10,000 paths are ranked in 10k chunks with asetImmediateyield between chunks. Each chunk's top N are re-ranked as finalists, which gives the same results as a single pass. Large rankings run one at a time in a serial lane, so concurrent bursts cannot stack long event-loop blocks.packages/fuzzy-match/src/index.ts):fuzzyMatchPathsskips paths that cannot contain the query's characters in order, before building fzf rune arrays or structured segment matchers. The check is case-insensitive ASCII. Any non-ASCII query or path is kept, so fzf's diacritic normalization still applies. Rankings are unchanged.host-rpc.cancel { requestId }inpackages/host-daemon-contract/src/session.ts.HOST_DAEMON_PROTOCOL_VERSION235 → 236.NotificationHub.requestHostOnlineRpcaccepts an optionalAbortSignal. When the signal aborts, or the wait times out, it drops the waiter and sendshost-rpc.cancel. The project, environment, files and thread-data path/file routes passcontext.req.raw.signal. An aborted call maps to408 request_cancelled, which keeps it out of error logs; the client has already disconnected.CommandRouterkeeps anAbortControllerper online RPC and aborts it onhost-rpc.cancel. Online RPC handlers now receive a requiredsignal. Path and file search check it before ranking and between chunks, so queued searches exit without ranking. They fail with expected error codecancelled. Other handlers ignore the signal for now.apps/host-daemon/src/command-handlers/file-list.ts): listings that take at least 500 ms to walk are cached per root and listing options. A search reuses the cached listing, starts a background refresh once it is 2 s old (one refresh at a time), and walks again before answering once it is 30 s old. Listings that walk in under 500 ms are never cached, so small workspaces still see file changes immediately. On a 1M-path workspace this removes a ~3 s walk from every keystroke; the cached listing holds about 200 MB while it lives.apps/app/src/components/promptbox/mentions/MentionMenu.tsx): while newer mention results load behind the ones on screen (debouncing or fetching), the first section header shows a small spinner, labelled "Updating results" for screen readers. Its space is always reserved, so the rows never move.usePathSuggestions/usePromptMentionsexposeisRefreshing. The mention config passed to the composer (TypeaheadMentionConfig) gainsisRefreshing, and the mention menu's results state (MentionMenuState) gainsrefreshing.How you verified
Fixture: an untracked workspace with 1,020,204 paths under nested git clones, matching the issue's repro.
GET /api/v1/projects/:id/pathsmade the server logDaemon sent nothing within its lease; closing its socket, and the daemon disconnected with 1006 and reconnected./files/readprobes, after the fix: 0 lease, disconnect or stall log lines. All 20 file reads made during the burst returned 200, the slowest in 1.2 s.fuzzyMatchPathson the fixture: identical results for 10 queries. Specific queries got 5–28× faster, for examplerepo-7/pkg-42/file-13went from 3.7 s to 0.13 s. Broad queries (p,packages/) are unchanged.packages/searches aborted after 1 s, then a real search. With the cancel send disabled: 504 after 30 s, daemon at 100% CPU. With this PR: 200 in 1.7–2.0 s, daemon CPU 0.1%.pkg-42/file-3→file-→file-2→file-→file-1: first search 3.3 s (walks once), then 0.24–0.38 s per keystroke, including while a background refresh runs. Before the cache, every keystroke took ~3 s.file-1results while typing@pkg-42/file-2, then clears, and the rows stay in the same place.host-rpc.cancel.usePromptMentionsreportsisRefreshingwhile newer results load behind the current ones.pnpm exec turbo run typecheck: all tasks pass.pnpm exec turbo run test --filter=@bb/host-daemon: 779 passed.--filter=@bb/app: 5,693 passed;--filter=@bb/client-core: 279 passed.--filter=@bb/server: 3,469 passed.--filter=@bb/fuzzy-match: 32 passed.--filter=@bb/host-daemon-contract: one failure,payload-size.test.ts(gzip byte snapshot). It fails the same way on the base commit on this machine (JSON byte counts match; only the gzip counts differ) and is unrelated.Known limit: broad queries that genuinely match a large share of paths are still slow. On the fixture,
pkg-file-2matches 190,000 paths and takes ~1.7 s to rank, most of it inside fzf's scoring.Follow-ups not in this PR: ranking chunks in parallel worker threads for broad queries, a watcher-driven listing cache, cheaper structured matching, and per-project excludes /
.bbignore.Fixes #5385
🤖 Generated with Claude Code