Skip to content

Unlink a plugin call's signal from the plugin instance when the call finishes - #7641

Merged
ymichael merged 1 commit into
get-bb:mainfrom
lanjak:fix-7595-plugin-rpc-signal
Nov 17, 2026
Merged

ymichael merged 1 commit into
get-bb:mainfrom
lanjak:fix-7595-plugin-rpc-signal

Conversation

@lanjak

@lanjak lanjak commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Human comments

What was wrong

invokeWrapped in apps/server/src/services/plugins/plugin-runtime.ts gives each plugin call with a caller signal the signal AbortSignal.any([callerSignal, lifetime]). lifetime is the plugin instance's stopping signal, which lives until the plugin unloads. Nothing disposes the composed signal when the call finishes, so every finished call leaves bookkeeping on the stopping signal. The triage report measured 256 extra WeakCells after 256 calls (#7595).

What changed

  • plugin-runtime.ts: a local linkCallSignal(caller, lifetime) makes an AbortController, adds abort listeners to both sources, and returns an unlink function that removes them. invokeWrapped calls unlink when the execution settles. Calls without a caller signal still get lifetime directly, as before.
  • plugin-instance-lifecycle.test.ts: a keep RPC in the fixture that stores its signal and returns. The new test makes three calls with a caller signal, disables the plugin, and checks that the stored signals are not aborted.

The existing tests for in-flight calls still pass: a caller disconnect aborts the signal, and a reload aborts the signal of a call that is still running.

Contract question for review. After this change, a handler that keeps its signal after it returns does not see an abort when the plugin is later disabled or reloaded. The triage report did not apply a fix for this reason. The SDK doc for experimental_signal (backend-contract.ts) says it "aborts when the caller stops waiting or this plugin instance is reloaded, disabled or removed". This PR reads that as the life of the call. Work that must continue after the handler returns can use the plugin's own lifetime instead. If the signal must stay linked after the call, this PR is the wrong fix.

No wire, CLI or documentation change.

How you verified

  • Before the fix, the new test fails with expected [ true, true, true ] to deeply equal [ false, false, false ]. After the fix, it passes.
  • pnpm exec turbo run typecheck lint lint:type-aware --filter=@bb/server passes.
  • vitest run test/services/plugins in apps/server: 59 files, 588 tests pass.
  • oxfmt --check passes on the changed files.

Not checked: the heap of a long-running server after the fix.

Fixes #7595

AGENT GENERATED

…finishes

invokeWrapped composed each caller signal with the plugin's long-lived stopping signal through AbortSignal.any. Nothing disposed that composition, so every finished call with a caller signal left bookkeeping on the stopping signal until the plugin unloaded. Link the two signals with listeners and remove them when the call settles.

Fixes get-bb#7595
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.

Plugin RPC calls retain AbortSignal.any WeakCell bookkeeping after completion

2 participants