Repository navigation
Description
Summary
A bb server that runs a plugin making steady RPC calls grows its heap without bound. Each call that carries a caller signal links that signal to the plugin's long-lived stopping signal with AbortSignal.any, and nothing unlinks it when the call finishes. Expected: a finished call leaves nothing behind on the plugin's stopping signal.
Versions and environment
- Observed in production on a downstream fork of bb 0.49.0 (version string
0.49.0+aleph.0.10.0, installed from a source build), Node 22.23.4, Ubuntu 24.04.5 LTS, Linux 6.8. The leaking line is unchanged in bbmainat da3e60b, so this is not fork-specific. - Mechanism reproduced on Node 22.23.4, Ubuntu 24.04.5 LTS, against bb source at da3e60b.
- No provider involved.
Steps to reproduce
Steps to reproduce
Repro status: the mechanism reproduces in isolation (below) and with a unit test at the code path. A stock bb release server was not run for hours to measure it end to end; the production numbers in Evidence come from the fork build above.
- Run this isolated script with Node 22.23.4. It does not start bb or read application data. The loop uses the same composition as invokeWrapped.
node --expose-gc --input-type=module <<'JS'
import { getHeapSnapshot } from "node:v8";
import { setTimeout as delay } from "node:timers/promises";
async function count() {
for (let i = 0; i < 5; i++) {
global.gc();
await delay(20);
}
const chunks = [];
for await (const chunk of getHeapSnapshot()) chunks.push(chunk);
const heap = JSON.parse(Buffer.concat(chunks).toString());
const fields = heap.snapshot.meta.node_fields;
const width = fields.length, name = fields.indexOf("name");
let cells = 0;
for (let i = 0; i < heap.nodes.length; i += width)
if (heap.strings[heap.nodes[i + name]] === "system / WeakCell") cells++;
return cells;
}
const lifetime = new AbortController();
const before = await count();
for (let i = 0; i < 5000; i++)
AbortSignal.any([new AbortController().signal, lifetime.signal]);
const after = await count();
console.log(JSON.stringify({before, after, delta: after-before, lifetimeAborted:lifetime.signal.aborted}));
JS- To see it in a server: keep a plugin loaded, make repeated plugin RPC calls that pass a caller signal, then compare V8 heap snapshots after GC and inspect the WeakCell retainers that target that plugin instance's stopping signal.
Narrowing: a plugin reload is not needed to see it. Per the code at the link above, calls without a caller signal use the stopping signal directly and create no composite (read from the code, not measured).
Expected vs actual
## Expected vs actual
Expected: finished calls leave no per-call bookkeeping on the plugin's live stopping signal.
Actual (isolated script, verbatim):
{"before":12,"after":5012,"delta":5000,"lifetimeAborted":false}
Counts vary by Node/V8 version. The five GC/wait rounds let finalization callbacks clean up temporary cells before counting.
Evidence
Observed:
- A production heap snapshot after 10.5 hours of uptime had about 1.40 million WeakCells; 98% targeted one plugin stopping signal through this composition. The plugin made about 36 RPC calls per second. Measured with a V8 heap snapshot and a retainer count; at an estimated 176 bytes per call that is about 20 MB per hour (an estimate from the cell count, not a measured before/after slope).
- With the composition replaced by a removable link that is disposed when each call ends, the isolated script's WeakCell delta over 5,000 calls was zero.
Cause (inferred from the code): every invocation with a caller signal creates an AbortSignal.any composite against the same long-lived signal at plugin-runtime.ts#L908-L914, and completion never unlinks it.
Investigation and the fork's fix: mistakeknot#240 (links the two signals with removable listeners, keeps abort reasons, and disposes the link in invokeWrapped's finally). One behavior change to note: the link then covers only an active call, so a handler that keeps the signal after returning no longer receives later caller or plugin aborts through it. A fix PR for bb with cancellation, disposal, repeated-call and RPC settlement tests will follow and link this issue.
What you ruled out
- Not a duplicate of Reloading a plugin in place keeps every replaced instance alive through loadOne's
previous#6858: that is retention across plugin reloads; this happens with no reload. - Not No heap ceiling policy and no memory diagnostics on the bb server #4162: that asks for general memory diagnostics, not this composition.
- Related but different: Let in-flight plugin tool calls finish when the plugin reloads #7336 (letting in-flight plugin tool calls finish on reload) and Plugin RPC:
bb.sdk.plugins.callRpcgives up after 75 s, but the handler keeps running and has no way to learn the caller is gone #4941 (callRpc giving up while the handler runs). Neither covers per-call cleanup of the link. - Still present on
mainat da3e60b. - The isolated repro needs no provider, database, network or application data.
Suggested priority and effort (optional)
Hits any long-running server whose plugins make frequent RPC calls with caller signals; memory grows until restart, which is the only workaround. No data or work is lost. Effort is small: a ready fix of about 30 lines plus tests.
Checks
- I reproduced this on the latest release or on
main, or I say above that I could not. - I searched open and closed issues for the same problem.
- If an agent wrote this, the body ends with
> AGENT GENERATEDand links the thread or report.
AGENT GENERATED
Activity
bb-slop-cop commentedon Nov 15, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilotplugins,perf,confirmed-repro. All classifications were missing and are now applied; no existing values were replaced.da3e60b81each retained 256 additional WeakCells after 256 completed signalled RPCs; 256 control calls without caller signals retained none. The plugin stayed loaded and unaborted.AbortSignal.anycomposition registers bookkeeping against the long-lived plugin stopping signal; invocation settlement does not dispose that composition.plugin-invocation-retention.test.ts, and its expected failure in both checkouts. Production memory-growth rates were not measured.