Skip to content

Search every folder the agent can use for @-mentions - #8076

Merged
ymichael merged 2 commits into
mainfrom
bb/composer-mentions-across-folders-thr_psx98pzvux
Nov 25, 2026
Merged

ymichael merged 2 commits into
mainfrom
bb/composer-mentions-across-folders-thr_psx98pzvux

Conversation

@ymichael

@ymichael ymichael commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Since #8007 a thread's agent can read and write the project's folders on its machine and the environment's additionalPaths, but the composer's @-mention search only looked in the main folder. GET /environments/:id/paths and GET /projects/:id/paths each ran one host.list_paths on the main folder, and results carried a path relative to it. Files in the other folders could not be mentioned, though the agent could open them.

What changed

Server.

  • searchWorkspaceFolderPaths (apps/server/src/services/projects/workspace-path-search.ts) sends one host.list_paths with the main folder and every extra folder as rootPaths. The extra folders are the project's folders for the machine plus the environment's additionalPaths: the same list the server builds for the agent. Both the turn's runtime config and the path routes get it from listEnvironmentExtraFolderPaths, so search and the agent's folders cannot drift.
  • It maps each result's rootPath to folderPath (null for the main folder). A folders=extra search with no extra folders returns empty without calling the host.
  • Both path routes use it. The project route (used by the new-thread composer before an environment exists) searches the project's folders for the chosen machine.

Daemon.

  • host.list_paths takes rootPaths: string[] (1–100) instead of path, and each entry carries its rootPath. The daemon lists every root in parallel, skips roots that do not exist, and ranks all candidates in one pass under one limit, so a search is one round trip however many folders the thread has, and scores are comparable across folders.
  • Ranking every root in one pass merges matches by item, not by relative path (mergeRankedMatches in @bb/fuzzy-match). Before this, README.md in three folders returned one result, because matches with the same path string were treated as one.
  • host.list_paths takes followRootSymlink, like host.list_files. Workspace folder search sets it, so a symlinked extra folder is searched through its target. Without it, the daemon rejected the whole search, and one symlinked folder hid every extra-folder result. The files and thread storage routes keep false.
  • The thread storage route drops rootPath from its response (unchanged shape). POST /files/paths passes the daemon result through, so it now also returns rootPath.
  • HOST_DAEMON_PROTOCOL_VERSION 283 → 284.

Contract and SDK.

  • Each result gains folderPath: null for the main folder, otherwise the absolute folder its relative path belongs to (WorkspaceSearchPathEntry).
  • Both routes take an optional folders query, main or extra. Absent means all folders.
  • sdk.environments.paths / sdk.projects.paths pass it through.
  • Plugin SDK 0.6.201 → 0.6.202.

CLI.

  • bb environment paths prints results from an extra folder as absolute paths. bb project paths prints JSON, which carries folderPath.

Composer.

  • usePathSuggestions sends the main-folder query and a separate folders=extra query, and merges them as they arrive. Main-folder results appear as fast as before, and extra-folder results join when ready. The extra-folder query counts toward the menu's loading and error state, so the menu does not say "No matching mentions" while extra-folder results are still loading or after they fail.
  • A result from another folder becomes its absolute path. The mention chip inserts @/abs/path, which the agent opens directly, and the menu shows the folder as the result's secondary text.
  • Clicking such a chip in the timeline or a new-thread draft opens it as a host file preview (ThreadDetailView, RootComposeView), since workspace previews only take relative paths.

Not changed.

  • The secondary panel's "open file" search (useFileSearchSuggestions) still searches the main folder and thread storage only (includeExtraFolders: false). Its workspace preview tab cannot open absolute paths.
  • Composer: path completion for absolute (/ and ~/) paths outside the workspace #7633 (completing any absolute path) does not fall out of this. Search covers the thread's folders, not arbitrary paths, and typing /Users/... still gives no completion. It needs a separate directory-browsing completion.

Performance

Measured on a real multi-folder project: the main folder is a bb checkout (about 9,000 files), with extra folders t3code (about 32,500 files) and bb-plugins. Requests used the composer's settings (limit=16, files and directories) against a pnpm start:worktree server, 12 runs per query after a warm-up. The machine was heavily loaded (load average 232–465), so absolute numbers are noisy; compare columns.

query main folder only (what main does), p50 / p95 ms composer first results (main, sent alongside extra), p50 / p95 all folders in (main + extra), p50 / p95 one combined request, p50
readme 45 / 117 64 / 98 414 / 1245 340
package.json 57 / 137 62 / 111 149 / 238 171
server 141 / 273 114 / 206 522 / 594 449
promptbox 33 / 126 34 / 169 133 / 194 114
usepath 24 / 101 18 / 47 50 / 104 50
zzqx (no match) 8 / 13 9 / 31 54 / 108 51

The first version sent one combined request. Because the daemon ranks large listings on one serial lane, main-folder results waited for the 32k-file folder, and in that first measurement the warm p50 for common queries went from about 210–330 ms (main folder only) to 1.3–2.6 s. Splitting the request keeps the first results at main-only speed. Extra-folder results add 50–520 ms p50, depending on how many entries the query matches.

The table was measured when the server still sent one host.list_paths per folder. Moving the multi-folder search into the daemon leaves the daemon's work about the same, and saves one host round trip for each extra folder beyond the first, which is about 180–250 ms per round trip on a remote host over bb Connect. Daemon-only timing on the same t3code + bb-plugins extra folders (limit=48, 15 runs, load average about 60):

query one call per folder, in parallel (p50 / p95 ms) one multi-root call (p50 / p95 ms)
readme 671 / 978 628 / 1074
package.json 304 / 371 274 / 391
server 865 / 1308 857 / 1492
promptbox 219 / 355 219 / 685
usepath 124 / 424 149 / 184
zzqx (no match) 84 / 240 101 / 227

How you verified

Live, same-named files and symlinked folders (pnpm start:worktree, new-thread composer). The project has a main folder plus extra folders extra-lib, extra-two, and linked-three, which is a symlink. Each folder has a README.md.

  • @readme lists all three READMEs, one per folder. Before the fix it listed two, and the API returned one for all folders together.
  • @yak finds yak-notes.md in the symlinked linked-three. Before the fix, adding that folder made @zebra (in extra-lib) show "No matching mentions", and the API returned invalid_path ... must not be a symlink.

Live (pnpm start:worktree, real Claude Code thread, Accept Edits), on the multi-folder project above:

  • Typing @turbo.json lists the main folder's turbo.json, then turbo.json /Users/michael/Projects/bb-plugins and other files from bb-plugins with their folder path.
  • Selecting the bb-plugins file inserts a turbo.json chip. The sent message is @/Users/michael/Projects/bb-plugins/turbo.json …, and the agent read the file and replied with its first line.
  • Clicking the chip in the timeline opens /Users/michael/Projects/bb-plugins/turbo.json in the side panel.
  • The new-thread composer for the project lists bb-plugins results too.

Tests:

  • public-environments.test.ts: the environment route sends the main and extra folders in one host.list_paths, maps rootPath to folderPath, honours folders=main|extra, and skips the host when there are no extra folders. The project route with hostId searches the project's folders.
  • workspace-path-list.test.ts (daemon, real temp folders): roots are ranked together under one limit, each result names its root, and a missing root is skipped.
  • workspace-path-list.test.ts: a file at the same relative path in three roots comes back three times, with and without a query. A symlinked root is searched with followRootSymlink: true and rejected with false.
  • fuzzy-match index.test.ts: distinct items that share a path are all returned. This test fails without the matcher change.
  • usePathSuggestions.test.ts: results from another folder become absolute paths and keep their folder.
  • environment.test.ts (CLI): bb environment paths prints an extra-folder result as an absolute path.
  • Suites: @bb/server, @bb/app, @bb/sdk, @bb/cli, @bb/server-contract, plus pnpm exec turbo run typecheck lint --filter='...[origin/main]'.

AGENT GENERATED

🤖 Generated with Claude Code

@ymichael
ymichael force-pushed the bb/composer-mentions-across-folders-thr_psx98pzvux branch from cc582d1 to 106b559 Compare November 24, 2026 06:08
ymichael added a commit that referenced this pull request Nov 24, 2026
…der each result is from

Squashed rebase of #8076 onto main after #8065. Extra folders now come
from main's mergeWorkspaceFolderPaths, so a project folder replaced by an
environment folder is searched through its replacement only. Plugin SDK
0.6.199 and host daemon protocol 284 for the host.list_paths rootPaths
change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael force-pushed the bb/composer-mentions-across-folders-thr_psx98pzvux branch from 489e6c8 to 5c4cab1 Compare November 24, 2026 22:36
ymichael and others added 2 commits November 24, 2026 15:59
…der each result is from

Squashed rebase of #8076 onto main after #8065. Extra folders now come
from main's mergeWorkspaceFolderPaths, so a project folder replaced by an
environment folder is searched through its replacement only. Plugin SDK
0.6.202 and host daemon protocol 284 for the host.list_paths rootPaths
change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…in @-mention search

Ranking all folders in one pass dropped every file whose relative path also
existed in another searched folder, because the fuzzy matcher merged matches
by path string. It now merges by item, so README.md from three folders gives
three results.

A symlinked extra folder made the daemon reject the whole multi-folder search,
which hid every extra-folder result and showed "No matching mentions".
host.list_paths takes followRootSymlink like host.list_files, and workspace
folder search follows it; the files and thread storage routes keep rejecting
symlinked roots. The composer now counts the extra-folder request in its
loading and error state.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael force-pushed the bb/composer-mentions-across-folders-thr_psx98pzvux branch from 2b535a7 to 664c551 Compare November 25, 2026 00:04
ymichael added a commit that referenced this pull request Nov 25, 2026
…ess start speed (#8147)

## Human comments

## What was wrong

Two tests in
`packages/agent-runtime/src/runtime.process-lifecycle.test.ts` fail at
random in `Tests (packages-host)` on loaded runners. Both depend on how
fast processes start under CPU load.

**`drains provider stderr before reporting process exit`** fails with
`expected null to be 'stderr-after-exit'`, for example on #8075's merge
run
([job](https://github.com/get-bb/bb/actions/runs/45507748534/job/138847431154),
2286 ms). The fake provider spawned a grandchild that inherits stderr,
then exited at once. The grandchild had to boot Node and wait 50 ms
before writing. After a provider exits, the runtime waits at most
`PROVIDER_PROCESS_CLOSE_GRACE_MS` (1 s) for stderr to close. On a loaded
runner, Node startup alone can take longer than that.

**`does not wait for stalled replacement initialization during full
shutdown`** times out at 15 s, followed by an unhandled `Provider "fake"
failed to start: spawn .../node ENOENT`
([job](https://github.com/get-bb/bb/actions/runs/45506198560/job/138847994142);
it failed on all three attempts of that branch, and took 12.1 s on
#8076's passing run). Before reaching its stalled replacement, the test
started and retired a full scripted-echo bridge. #8141 measured a full
start at 3.7–4.6 s under load, and stopping one can take up to 5 s plus
kill and stderr grace periods. On other PRs' loaded runs the test took
3–12 s. When it overran, Vitest timed the test out but its body kept
running. `afterEach` removed `tmpDir`, and the replacement then spawned
into the missing cwd, which Node reports as `spawn <node> ENOENT`. The
ENOENT is a consequence of the timeout, not its cause. #8136 and #8141
fixed the sibling retirement tests the same way; this one was left.

## What changed

`runtime.process-lifecycle.test.ts` only. No runtime code changes.

- **stderr drain:** the grandchild reports ready over IPC, the provider
exits only after that, and the grandchild writes to stderr 50 ms after
the IPC channel disconnects, which happens when the provider exits. The
write still lands after the exit, but Node startup no longer counts
toward the 1 s grace period.
- **stalled shutdown:** the first process is the idle child
(`process.stdin.resume()`, no post-initialize requests) that the sibling
tests use. The adapter it uses is pulled out into a `createIdleAdapter`
helper that `createIdleProviderManager` now shares. The replacement
still uses the real fake adapter on the raw stalled script, so it
receives `initialize` and holds its reply for 3 s, which is the behavior
under test.

## How you verified

CPU starvation locally: the test runs at background QoS (`taskpolicy
-b`) next to 32 busy-loop processes on a 16-core Mac. This reproduces
both CI failures.

| Test | Before | After |
|---|---|---|
| stderr drain | 2 CI-assertion failures before I stopped it | 6 of 6
pass |
| stalled shutdown | 2 of 4 time out (18.9 s, 21.4 s); passes took 13.1
s and 2.3 s | 4 of 4 pass in 198–358 ms |

Both tests still catch the bugs they guard:

- stderr drain: with `PROVIDER_PROCESS_CLOSE_GRACE_MS` temporarily set
to 0, the new test fails 3 of 3.
- stalled shutdown: with `shutdown()` temporarily changed to await
in-flight provider starts, the new test fails.

`pnpm exec turbo run typecheck lint test --filter=@bb/agent-runtime`:
pass (316 tests, 1 skipped).

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit 5767e99 into main Nov 25, 2026
53 checks passed
@ymichael
ymichael deleted the bb/composer-mentions-across-folders-thr_psx98pzvux branch November 25, 2026 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant