Skip to content

fix: bound pending plugin mention searches - #8003

Merged
ymichael merged 2 commits into
mainfrom
slopcop/issue-8002
Nov 23, 2026
Merged

ymichael merged 2 commits into
mainfrom
slopcop/issue-8002

Conversation

@bb-slop-cop

@bb-slop-cop bb-slop-cop Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

🚨 SLOP COP 🚨 · new-issue-autopilot

Human comments

What was wrong

A plugin mention search races a 2 s response timeout, but the timeout doesn't stop the underlying work. On main, every request starts a fresh call to every provider, so a provider that hangs piles up one stuck call per keystroke. In #8002, File Manager's directory scans hung on a macOS iCloud authorization prompt, and the stuck calls filled all four libuv filesystem workers.

The first version of this PR skipped any provider whose search was still running. That bounded the stuck work, but it also dropped healthy providers that were merely slower than the 120 ms typing debounce: the query the user stopped on got no results from them.

Report: https://get-bb.github.io/reports/issues/8002.html

What changed

  • New apps/server/src/services/plugins/plugin-mention-search-slots.ts lets each provider registration run at most one search at a time:
    • A query that arrives while a search is running is queued, replacing any older queued query (that older request returns without the provider's results). The queued query runs as soon as the current search settles, inside the request's own time box.
    • Once a running search outlives the time box, the provider is skipped right away until that search settles, so a hung provider never accumulates calls and no longer costs every request the full 2 s.
  • searchMentions in plugin-service.ts routes every provider call through these slots. PluginMentionProviderRecord is now exported from plugin-api.ts so the service can type them.
  • There are no wire, SDK, CLI, or protocol changes. The SDK, CLI, and HTTP search entry points all share this service path. This bounds stuck work; it cannot cancel a syscall that is already blocked.

How you verified

  • New tests in plugin-mention-providers.test.ts load a real plugin into a migrated-SQLite plugin service:
    • keeps one pending search per registration through timeout and fulfill/reject: fails on main (Expected: "1", Received: "6") and passes here.
    • runs only the latest query typed while a provider is still searching: fails on main (the superseded query still runs) and on this PR's first version (the latest query gets no results), and passes here.
  • pnpm exec turbo run test --filter=@bb/server -- test/services/plugins/plugin-mention-providers.test.ts test/services/plugins/plugin-instance-lifecycle.test.ts test/services/plugins/plugin-service.test.ts: 73 passed.
  • pnpm exec turbo run typecheck lint:type-aware --filter=@bb/server: all 7 tasks pass.
  • Live check on a pnpm start:worktree server with a QA plugin that has a 400 ms provider and a provider that never resolves. Six queries were sent 120 ms apart over HTTP. The hung provider was called once in total, the slow provider returned results for the last query of each burst, and once the hung provider passed its time box, a later search came back in about 400 ms instead of 2 s.

Fixes #8002

AGENT GENERATED

🤖 Generated with Claude Code

Skipping any provider with a search in flight dropped it from the results
for the query the user actually stopped on whenever its search took longer
than the 120 ms typing debounce. Each provider registration now runs at
most one search: a query that arrives while it is busy waits as the single
queued search (replacing any older queued query) and runs when the current
one settles. Once a running search outlives the time box, the provider is
skipped immediately until it settles, so a hung provider still never
accumulates work.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit 23bf9ec into main Nov 23, 2026
32 checks passed
@ymichael
ymichael deleted the slopcop/issue-8002 branch November 23, 2026 18:43
ymichael added a commit that referenced this pull request Nov 23, 2026
## Human comments

## What was wrong

The composer already cancels a stale mention search request when the
person types past it, but the plugin was never told. `GET
/api/v1/plugins/mentions/search` dropped the request signal, and
`PluginMentionSearchContext` had no signal, so a provider couldn't stop.
The 2s time box also stopped waiting without aborting anything. Since
#8003 limited each provider to one running search, a slow provider's
stale search held up the newest query until it finished on its own.

## What changed

- **Route:** `apps/server/src/routes/plugins.ts` forwards
`context.req.raw.signal` to `searchMentions`, which takes a required
`signal`.
- **Search slots** (`plugin-mention-search-slots.ts`):
- Each running search gets one signal that aborts when its request
disconnects, when its time box runs out, or when the plugin unloads (the
last through `invokeWrapped`'s existing caller-signal link, the same
path RPC handlers use).
  - A waiting query whose request disconnects never starts.
- A request that disconnects returns right away, without logging a
plugin error.
- **SDK:** new `PluginMentionSearchContext.experimental_signal`
(required; the host always supplies it). The `search` JSDoc now
describes one-search-at-a-time queueing. `@get-bb/plugin-sdk` is bumped
to 0.6.183.
- **Docs plugin:** stops scanning further vaults once its search is
aborted. It's the only in-repo provider with async work; the others
search synchronously.
- **Documentation:** a new `docs/api_to_audit.md` entry, and
`backend-ui-lifecycle.md` now shows a `fetch` example and describes
queueing and abort.
- **Tests:** in-repo test calls to `provider.search(...)` (Docs, Tasks,
GitHub) now pass a signal. Third-party test code that calls `search`
directly will need the same change after upgrading the SDK.
- No host daemon or protocol changes.

This can't interrupt a filesystem call that is already blocked (#8002).
File Manager needs its own change to check the signal between directory
reads.

## How you verified

- New tests in
`apps/server/test/services/plugins/plugin-mention-providers.test.ts`:
request disconnect aborts the provider's signal (through the HTTP
route), the time box aborts it, aborting the running search starts the
newest waiting query, and a waiting query whose caller left never
starts. All 4 fail on main and pass here. The file passes 21/21.
- New Docs test `stops scanning further vaults once the search is
aborted`: fails on main's Docs plugin and passes here. Docs 50/50, Tasks
4/4.
- `pnpm exec turbo run typecheck lint:type-aware` for `@bb/server`,
`@get-bb/plugin-sdk`, `bb-plugin-simple-notes` and `bb-plugin-tasks`,
plus `typecheck` for `bb-plugin-github`: all pass. The plugin authoring
doc example and docs tests pass.
- Live check on a `pnpm start:worktree` server: a QA plugin with a 400
ms provider that honours the signal, and six queries sent 120 ms apart
over real HTTP, each cancelling the previous request the way the
composer does. The plugin log shows each stale search aborted before the
next started (`start:r abort:r start:re abort:re … start:readme
done:readme`). The final query returned in about 400 ms, and the
plugin's error count stayed at 0.

Follow-up to #8003.

> AGENT GENERATED

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

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

Timed-out plugin mention searches accumulate work and can exhaust filesystem workers

2 participants