Repository navigation
Description
Environment. bb 0.43.3 (desktop, macOS arm64), server running under ELECTRON_RUN_AS_NODE=1
(Node 24 / V8 15.2 in Electron 44). Plugin installed from a path: source (the Factory plugin, github.com/mattwyckhouse/bb-plugin-factory); server entry is a
TypeScript tree of 112 modules (5.15 MB of source) loaded through jiti.
Symptom. Server heap grows by a fixed step on every POST /api/v1/plugins/reload (and on
every disable + enable) of a path-installed plugin and never comes back after a full GC. On a
host that reloaded the plugin 40 times in 18.9 h the server died with
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed after a last-resort Mark-Compact that freed
nothing (3038.2 (3192.8) -> 3038.0 MB). A process restart is the only way to reclaim.
Evidence (installed bundle server/dist/start-server.js).
- Path and source-builtin plugins are loaded with
createJiti(import.meta.url, { moduleCache: false, alias })
andawait jiti.import(entry)(334276–334281) behind aregisterHooksresolve hook that stamps
?bbPluginLoad=<rootId>.<epoch>onto everyfile:URL under the plugin root (333099–333125,
stamp at 333120).bumpMutableRootGeneration(333173) mints a new epoch per load. The source
comment (plugin-runtime.ts) explains why: "Node's ESM registry keys modules by resolved URL
forever", so without the stamp a reload would return the stale module. - The cost is the mirror image: every generation's modules stay in the ESM registry with no
eviction API.disposePluginInstance(334391–334440) closes websockets, disposes the host
worker, aborts tool calls and interactions, stops services, runs dispose hooks, drains
invocations and closes every tracked database handle — and cannot touch the registry.
evictCommonJsCache(333161) does reclaim the CommonJS half.setEnabled(id, false)→
disposeOne(334441) never callsforgetMutableRoot;remove(336472) only deregisters the
resolve hook. Sodisable/enableretains exactly like a reload. resolveServerEntry(333775–333779) returnsmanifest.serverEntryforpath:sources and
only checksdist/server.jsfor other source kinds, so apath:plugin is always transpiled
from source.
Measurement (out of process, reproducible). Harness: bb's bundled jiti 2.7.0, bb's exact
options, a faithful copy of the resolve hook, --expose-gc, eight forced GCs before each sample,
metric used_heap_size + external_memory. Node 26.8.2.
| Entry | Steady-state retention per load |
|---|---|
server.ts source tree (112 modules), hook active |
73.5 MB (loads 3–4; 73.4–73.5 across two independent 4–10 load runs) |
prebuilt single-file ESM dist/server.js (4.7 MB), hook active |
6.4 MB |
| same source tree, resolve hook made a pass-through (control) | 0.1 MB after load 2 — the registry returns the cached module |
prebuilt bundle as CommonJS (no "type":"module") |
0.1 MB |
40 × 73.5 MB = 2.94 GB, within 3 % of the 3,038 MB live heap at the failing GC. (The reload term
is not the whole story: a reload-free process on the same host also grows under load, so the
issue is a pace-setter, not the sole retainer.)
Reproduction. Install any path: plugin whose server entry imports a few MB of TypeScript.
Call POST /api/v1/plugins/reload 20 times. Watch process.memoryUsage().heapUsed (or the
process footprint) step up by a constant each time and never drop after a forced GC. Repeat with
disable then enable: same step.
Proposed fix (any one helps).
- Key the generation stamp on a per-file content hash instead of a per-reload counter, so a
reload mints new URLs only for files whose content changed. Keeps the freshness guarantee and
turns a ~73 MB reload into roughly the size of the changed files. - Honour a prebuilt
dist/server.jsforpath:sources too (opt-in manifest flag), since
resolveServerEntryalready prefers it for every other source kind and it retains 11× less. - Structurally: evaluate the plugin server graph in a worker or child process whose termination
frees everything, the waydisposePluginHostalready frees the host artifact.
Also useful: count generations per plugin, warn past a threshold, and expose the count in
GET /api/v1/plugins.
Filed from an audit of bb 0.43.3 by the Factory plugin (github.com/mattwyckhouse/bb-plugin-factory). Method, re-derived numbers and the adversarial review of this report: plans/076-host-sustainable-line/bb-core-issues/REVIEW.md in that repository.
Activity
bb-slop-cop commentedon Sep 23, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilotBug · High priority · High effort. Applied
plugins,perf, andpartial-repro; no existing classification was replaced.Reproduction and root-cause report: PARTIALLY REPRODUCED, high confidence in the native ESM root cause. Generation-stamped URLs retain prior module state after root deregistration. Two clean-checkout loader runs retained eight distinct states (~16.36 MiB); the control retained one (~2.2 MiB). The report includes the repeatable test and failing reclamation assertion.
The reported TypeScript amplification and Electron crash remain unverified; the small TypeScript fixture did not reproduce retention on Node 22. No PR: reclaiming module graphs safely requires a lifecycle/architecture decision beyond the simple-fix gate.
luketraas commentedon Sep 29, 2026
Re-checked on
main66bbc1a with Node 22.22.3 on macOS: in-processcreatePluginService, a generated path plugin of 110 TypeScript modules,--expose-gc, 8 forced GCs per sample.server.cjsfromrequire.cacheby its unresolved path while Node keys the cache by real path. Evict compiled plugin modules by their resolved filename #4494 fixes that. With a non-symlinked data directory the same capped run completes.So the mechanism reported here no longer applies to the default loader on Node 22. The leak I could reproduce is the symlink case. I did not test the Electron runtime from the report.
Evict compiled plugin modules by their resolved filename (#4494)
ymichael commentedon Sep 30, 2026
Resolved for the default plugin loader by #3681 and #4494, both present in adbce96.
Verified on Node 22.23.1:
The original Electron runtime and the optional legacy JITI loader were not verified in this run. Closing based on the default-loader fixes and verification above; a reproduction on the current default loader would warrant reopening.