Repository navigation
Unlink a plugin call's signal from the plugin instance when the call finishes - #7641
Merged
Merged
Conversation
…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
This was referenced Nov 17, 2026
Merged
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
invokeWrappedinapps/server/src/services/plugins/plugin-runtime.tsgives each plugin call with a caller signal the signalAbortSignal.any([callerSignal, lifetime]).lifetimeis 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 locallinkCallSignal(caller, lifetime)makes anAbortController, addsabortlisteners to both sources, and returns anunlinkfunction that removes them.invokeWrappedcallsunlinkwhen the execution settles. Calls without a caller signal still getlifetimedirectly, as before.plugin-instance-lifecycle.test.ts: akeepRPC 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
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/serverpasses.vitest run test/services/pluginsinapps/server: 59 files, 588 tests pass.oxfmt --checkpasses on the changed files.Not checked: the heap of a long-running server after the fix.
Fixes #7595