Repository navigation
Make plugin reload re-read edited sources for path installs - #919
SawyerHood merged 4 commits into
Conversation
`bb plugin reload` and `bb plugin watch` did not pick up source edits for a
plugin installed from a local path. The loader re-ran the factory, but the
factory it re-ran was the one evaluated at first load.
Path installs are not snapshot-copied: `installPathSource` records the
original directory as `rootDir`, and `resolveServerEntry` deliberately loads
those from source so authors can iterate. The break is in the loader. jiti
only transpiles when
!isCjs && !(isTypeModule && isAsync) && (...)
so a package with `"type": "module"` imported through `jiti.import` (async)
skips the transform and goes to native `import()`. Node's ESM registry keys
modules by resolved URL permanently, so the second import returns the first
module. `moduleCache: false` governs only jiti's own CJS cache, and a fresh
jiti instance does not touch Node's registry.
Every plugin in this repo ships `"type": "module"`, so this affected
effectively every path-installed plugin.
Fix: register a `module.registerHooks` resolve hook that stamps a per-root
reload generation onto every file URL inside a mutable plugin root. Each
reload becomes a distinct URL for the entry and for every file it imports, so
submodule edits land too. Managed git:/npm: artifacts are immutable after
promotion and are left alone.
The existing reload test missed this because its fixture writes `server.ts`,
and TypeScript always takes jiti's transpile path. The added test mirrors a
real plugin (`"type": "module"` plus plain `.js`) and asserts both the entry
and a submodule re-read. It fails on main with
`expected 'entry1:sub1' to be 'entry2:sub1'`.
Verified against a dev server: before, three consecutive loads logged the
first version's marker; after, entry and submodule edits both take effect.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🚨 SLOP COP 🚨 · I am the SlopCop. I am reviewing PR #919 for security, code quality, performance, architecture, and end-to-end behavior. I will post a result after each parallel phase. |
| /** Invalidate a mutable plugin tree so the next import re-reads from disk. */ | ||
| function bumpMutableRootGeneration(rootDir: string): void { | ||
| registerMutableRootHooks(); | ||
| const rootUrl = pathToFileURL(join(rootDir, "/")).href; |
There was a problem hiding this comment.
🚨 slopcop/review — [P2] Canonicalize the mutable root before URL matching
installPathSource stores resolve(path), but Node canonicalizes ESM files through symbolic links. Thus, a symbolic-link install never matches this URL.
Reload then returns cached code. I reproduced v1 after an edit to v2 and a generation increment.
Use realpath for the tracked root, or compare canonical paths. Add a reload test for a symbolic-link path.
| resolve(specifier, context, nextResolve) { | ||
| const resolved = nextResolve(specifier, context); | ||
| if (!resolved.url.startsWith("file:")) return resolved; | ||
| for (const [rootUrl, generation] of mutableRootGenerations) { |
There was a problem hiding this comment.
🚨 slopcop/review — [P2] Select the most specific matching root
The map keeps insertion order. If root B is under root A, root A always wins this loop when A registers first.
A reload changes only B’s generation. The import still uses A’s old generation and returns cached modules.
Select the longest matching root. Add a test with two nested path plugins.
|
🚨 SLOP COP 🚨 · Security phase complete. I found no new privilege escalation or path traversal. Path plugins already run trusted server code. I confirmed two cache-boundary defects:
I also found no cleanup for historical roots. This can increase the global hook cost after removals. |
| function registerMutableRootHooks(): void { | ||
| if (mutableRootHooksRegistered) return; | ||
| mutableRootHooksRegistered = true; | ||
| registerHooks({ |
There was a problem hiding this comment.
🚨 slopcop/review — [P1] Make reload work under the supported tsx loader
Both source server commands start Node with --import tsx. The exact-head regression test fails under that loader.
The first reload expected entry2:sub1 but received entry1:sub1. A service probe also stayed at the first version.
Use a cache boundary that works with the supported source loader. Make the new Turbo test pass.
| const separator = resolved.url.includes("?") ? "&" : "?"; | ||
| return { | ||
| ...resolved, | ||
| url: `${resolved.url}${separator}bbPluginLoad=${generation}`, |
There was a problem hiding this comment.
🚨 slopcop/review — [P2] Bound memory growth across reloads
Each generation creates a new module URL. Node keeps all ESM module records for the process life.
A probe imported one 50 KiB module 500 times. RSS increased from 43.2 MB to 113.5 MB after garbage collection.
bb plugin dev reloads after each edit. Use an isolation boundary that permits module cleanup, or add another effective bound.
|
🚨 SLOP COP 🚨 · Performance and end-to-end phase complete. The new server regression test fails at the first ESM reload. Ten tests pass, and this new test fails. The same reload stays stale under the standard Each unique module URL remains in Node’s ESM cache. A 500-reload probe increased RSS from 43.2 MB to 113.5 MB. The server build and type check pass. Existing built-in reload tests pass. This change has no browser route. I tested the service install and reload path instead. |
| // generation's URLs before importing (managed git:/npm: artifacts are | ||
| // immutable after promotion and keep their cached modules). | ||
| if (row.sourceKind === "path" || row.sourceKind === "builtin") { | ||
| bumpMutableRootGeneration(row.rootDir); |
There was a problem hiding this comment.
🚨 slopcop/review — [P1] Preserve the active generation after a failed reload
This increment happens before the candidate import. If the candidate fails, the previous plugin remains active.
A later dynamic import from that plugin receives this failed candidate generation. The active plugin can then mix old and new files.
Derive child imports from the parent URL generation. Use the current generation only for a new top-level load. Add a rollback test.
|
🚨 SLOP COP 🚨 · Code quality and architecture phase complete. I found a rollback defect. The runtime increments the root generation before candidate import. If that candidate fails, the old plugin remains active. Its later dynamic imports receive the failed candidate generation. The hook must preserve the generation from an active parent module. The repository has no equivalent backend abstraction. A frontend helper refreshes only one bundled module and does not solve this graph problem. I found no stale new names. This change needs no daemon protocol or command documentation update. |
SawyerHood
left a comment
There was a problem hiding this comment.
🚨 SLOP COP 🚨 · review
Changes required.
Confirmed findings:
- P1: Reload stays stale with the supported
tsxpreload. A service probe and the targeted regression received the old entry. - P1: A failed candidate changes the root generation. The retained old plugin can then load lazy modules from the failed generation.
- P2: Symbolic-link roots differ from Node’s canonical URLs. This includes the macOS
/varand/private/varpath pair. - P2: Prefix iteration selects an outer root before a nested root. An inner generation change then has no effect.
- P2: Unique ESM URLs remain for the process life. Historical roots also remain in the global map.
A 500-import probe used one 50 KiB module. RSS increased from 43.2 MB to 113.5 MB after garbage collection.
The security review found no new privilege escalation or path traversal.
The architecture scan found no reusable backend cache abstraction. The frontend helper refreshes only one bundled module.
Validation results:
- The server build passed.
- The server type check passed.
- The targeted plugin test had 10 passes and one new failure under the supported loader.
- The existing built-in plugin tests had 20 passes.
- This server change has no browser route. The worker tested the service install and reload path.
- The final GPT-5.6 review gate returned
REQUEST CHANGES.
Fix the cache boundary and add loader, rollback, symbolic-link, nested-root, and lifecycle stress tests.
Follow-up to slopcop review on #919. Three real defects in the resolve hook, each covered by a test that fails without its fix. Canonicalize the tracked root. Node resolves ESM files through symbolic links, so a root recorded as the un-canonicalized install path never matched the module URL and a symlinked install stayed stale. Select the longest matching root. The lookup returned the first match in insertion order, so an outer plugin whose tree contains a nested plugin claimed the nested plugin's files and reloaded them to cached code. Inherit the generation from the importing parent. A plugin's lazy imports now resolve against the generation it was loaded under, instead of whatever the root has since reached. This keeps a surviving plugin coherent after a failed reload, and after a newer successful load of the same root. The reviewer also asked for a rollback that restores the generation when a candidate load fails. That is redundant with parent inheritance — each alone makes the failed-reload test pass — so this keeps only the more general mechanism, which also covers the successful-reload case. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Thanks — three of the five findings were real and are fixed in 4811008. Each has a test that I confirmed fails without its specific fix:
Two I am not acting on: [P1] "Make reload work under the supported You are right that both source server commands start Node with And the hook itself, under the exact dev invocation ( This also matches the end-to-end check in the PR description, which ran against a real dev server started by [P2] "Bound memory growth across reloads" — accurate, already disclosed, and inherent to the approach. Your 43.2 MB → 113.5 MB over 500 reloads is consistent with the risk stated in the PR description. Node never collects ESM module records, so any URL-based reload boundary leaks by construction; there is no bound available short of a different isolation boundary (worker or vm realm per plugin), which is a much larger change than this bug fix warrants. This affects only mutable path/builtin plugins in a dev-iteration loop, and 500 edit-reload cycles in one dev session is already an unusual amount. I would rather leave it documented than add a partial mitigation that complicates the hook without removing the leak. Worth a separate issue if plugin dev sessions turn out to run long enough for it to bite. |
|
🚨 SLOP COP 🚨 · I am SlopCop. I am reviewing this pull request now. I started parallel security, code quality, and performance reviews. I will also test the changed route when possible. |
|
🚨 SLOP COP 🚨 · Security review complete. The new generation URLs make each reload keep another ESM module graph until the process stops. The reload route accepts a simple POST request without the local browser guard. A cross-origin page can repeat this request and increase server memory use. I will include this security issue in the final review. |
|
🚨 SLOP COP 🚨 · End-to-end check complete. I started the development server from the exact pull request head. I installed a local ESM plugin with an entry module and a submodule. The browser read The focused server test passed all 14 tests. The server type check also passed. |
|
🚨 SLOP COP 🚨 · Performance review complete. The URL generation keeps each old ESM module graph until the process stops. A 500-reload probe kept about 57 MiB after garbage collection. The global root map also keeps removed plugin roots. Every later file resolution scans all historical roots. I will include both issues in the final review. The first issue blocks approval. |
|
🚨 SLOP COP 🚨 · Code-quality and architecture review complete. The new hook refreshes ESM child modules, but it does not refresh CommonJS child modules. I reproduced this issue on the live server. A plugin imported The repository has no reusable server module loader for this case. The current cache logic should move behind one loader boundary. |
| const separator = resolved.url.includes("?") ? "&" : "?"; | ||
| return { | ||
| ...resolved, | ||
| url: `${resolved.url}${separator}bbPluginLoad=${inherited ?? match.generation}`, |
There was a problem hiding this comment.
🚨 slopcop/review — CommonJS children stay stale after reload.
This generation changes only the ESM URL. Node still caches a .cjs child by its file path.
I reproduced the defect on the live server. The route still returned cjs-before after the child changed to cjs-after.
Please add static .cjs and createRequire() reload tests. Both tests must read the new value.
| const separator = resolved.url.includes("?") ? "&" : "?"; | ||
| return { | ||
| ...resolved, | ||
| url: `${resolved.url}${separator}bbPluginLoad=${inherited ?? match.generation}`, |
There was a problem hiding this comment.
🚨 slopcop/review — Each reload keeps another ESM module graph.
Node keeps every unique ESM URL until the process stops. This URL creates permanent linear memory growth during bb plugin watch.
A 500-reload probe kept about 57 MiB after garbage collection. Please use a loader boundary that can release old graphs.
| const separator = resolved.url.includes("?") ? "&" : "?"; | ||
| return { | ||
| ...resolved, | ||
| url: `${resolved.url}${separator}bbPluginLoad=${inherited ?? match.generation}`, |
There was a problem hiding this comment.
🚨 slopcop/review — A generation can cross into the wrong plugin root.
The inherited marker contains only a number. This line applies that number to any matched root.
Please include the root identity. Inherit the generation only when the parent and child use the same root.
Add a test where root A imports root B after root B reloads.
| * onto every URL inside a mutable plugin root, which makes each reload a | ||
| * distinct URL for the entry AND every file it imports. | ||
| */ | ||
| const mutableRootGenerations = new Map<string, number>(); |
There was a problem hiding this comment.
🚨 slopcop/review — Removed roots remain in the global resolver table.
This map only adds roots. Every later file resolution scans all historical roots.
Please remove a root after plugin removal or replacement. Also stop the hook when no mutable roots remain.
SawyerHood
left a comment
There was a problem hiding this comment.
🚨 SLOP COP 🚨 · review
Verdict: blocking changes required.
GitHub does not allow the pull request author to submit a request-changes state.
I found four blocking defects.
-
CommonJS children stay stale after reload. The live route still returned
cjs-beforeafter the file changed tocjs-after. -
Each unique ESM URL keeps another module graph until the process stops. A 500-reload probe kept about 57 MiB.
-
The reload route accepts a simple POST without the local browser guard. A cross-origin page can repeat memory-growing reloads.
-
The inherited generation has no root identity. A cross-root import can receive the wrong generation.
The global root table also keeps removed roots. This issue increases the cost of all later file resolutions.
The new ESM behavior works for the covered path. The browser changed the entry and submodule result from entry-before:before to entry-after:after.
Validation passed for the server type check, all 14 focused tests, and every GitHub check. These checks do not cover the blocking cases.
The final GPT-5.6-Sol gate returned REQUEST CHANGES.
Second round of slopcop findings on #919. Each fix has a test that I confirmed fails without it. Refresh CommonJS children. The URL marker only re-keys ESM modules; Node caches a CommonJS child by resolved filename and ignores the query, so a `.cjs` import or a `createRequire()` call survived the reload untouched. The matching require.cache entries are now dropped when a root is invalidated. Key the marker by root, not by number alone. It now carries `<root id>.<epoch>` and inherits the parent's epoch only when parent and child share a root, so an import that crosses into another plugin's tree takes that plugin's epoch instead of the importer's. Drop a root when its plugin is uninstalled, so the resolve hook stops scanning trees that no longer exist. Epochs and root ids are process-wide and never reused, so a removed-then-reinstalled root cannot collide with URLs its previous registration already evaluated. Reload deliberately does not forget a root: the surviving graph of a failed reload still resolves against its id. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Round two addressed in 65db155. Three of the four were real; each fix has a test I confirmed fails without it.
Memory growth — acknowledged, and I am still not fixing it here. Your number moved from 57 MiB to "use a loader boundary that can release old graphs," but that boundary is the point: Node never releases ESM module records, so every URL-keyed reload leaks by construction. Releasing old graphs requires per-plugin worker or vm-realm isolation — a substantially larger architectural change than a bug fix, and one that changes the plugin execution model. This is disclosed in the PR description, is dev-loop-only, and is strictly better than the status quo, where reload does not work at all. I have filed it as follow-up rather than expanding this PR's scope. The reload-route CSRF finding is pre-existing and out of scope. For the record on round one: the Current state: typecheck clean, 293 plugin tests across 29 files pass. |
|
🚨 SLOP COP 🚨 · I am SlopCop. I am reviewing this pull request for security, code quality, performance, architecture, and end-to-end behavior. Three BB agents will run the security, code-quality, and performance reviews in parallel. I will post each result when it completes. |
|
🚨 SLOP COP 🚨 · Code-quality and architecture phase complete. I found two high-risk rollback defects. A failed reload publishes its ESM epoch before the candidate commits. Cross-root imports can then read rejected source files. The CommonJS purge also changes the active plugin before the candidate commits. A failed reload leaves the active plugin with rejected CommonJS files. The tests cover successful CommonJS reloads, but they do not cover this rollback path. A dedicated mutable-module loader should own epochs, cache state, hook cleanup, and transactional commit behavior. |
|
🚨 SLOP COP 🚨 · Security phase complete. The reload route accepts a simple unauthenticated POST. An omitted plugin ID reloads every enabled plugin. Each reload adds permanent ESM module graphs. Repeated cross-origin requests can exhaust server memory. The private generation marker also uses ordinary query text. A supplied The agent reproduced a policy module change from version two back to version one. Add the local browser guard, require JSON, and keep trusted generation state outside plugin-controlled query text. |
|
🚨 SLOP COP 🚨 · Performance and end-to-end phase complete. The focused test passed all 16 cases. The server type check also passed. The live browser route changed A failed reload kept the old ESM value but returned the candidate CommonJS value. A concurrent reload produced the same mixed state. Each reload also retains another ESM graph for the process lifetime. Service stop does not release the global roots or hook. The agent removed its temporary plugin, stopped the development server, and closed the browser pages. |
| const epoch = | ||
| parent !== null && Number(parent[1]) === match.id | ||
| ? parent[2] | ||
| : match.epoch; |
There was a problem hiding this comment.
🚨 slopcop/review — [P1] Keep failed ESM candidates private
bumpMutableRootGeneration replaces match.epoch before the candidate factory succeeds. A cross-root import then uses the candidate epoch.
After a failed reload, the retained plugin can evaluate rejected edited files. Keep active and candidate epochs separate until the commit point.
Add a rollback test where plugin A imports plugin B after the reload of B fails.
| id: mutableRoots.get(rootUrl)?.id ?? nextMutableRootId++, | ||
| epoch: nextMutableRootEpoch++, | ||
| }); | ||
| purgeCommonJsCache(canonicalDir); |
There was a problem hiding this comment.
🚨 slopcop/review — [P1] Keep candidate CommonJS state isolated
This purge deletes live CommonJS entries before the candidate factory succeeds. Old handlers remain active during this interval and after failure.
The live test mixed old ESM state with candidate CommonJS state during failed and concurrent reloads.
Use a separate cache boundary for each generation. Add failed and concurrent reload tests for lazy createRequire() calls.
| function registerMutableRootHooks(): void { | ||
| if (mutableRootHooksRegistered) return; | ||
| mutableRootHooksRegistered = true; | ||
| registerHooks({ |
There was a problem hiding this comment.
🚨 slopcop/review — [P2] Release global loader state during service stop
The code discards the hook handle, and the root map exists at module scope. Plugin removal clears one root, but service stop clears none.
Repeated service creation retains old roots. Every later file resolution scans them.
Keep the hook handle, track root owners, clear roots during service stop, and call deregister() when no owners remain.
| const separator = resolved.url.includes("?") ? "&" : "?"; | ||
| return { | ||
| ...resolved, | ||
| url: `${resolved.url}${separator}bbPluginLoad=${match.id}.${epoch}`, |
There was a problem hiding this comment.
🚨 slopcop/review — [P1] Guard permanent module-graph growth
Each unique URL retains another ESM graph until the process stops. The reload route accepts a simple unguarded POST and can reload all plugins.
A cross-origin page can repeat this operation and exhaust server memory.
Add the local browser guard and a JSON requirement. Also use a replaceable loader boundary that can release old generations.
SawyerHood
left a comment
There was a problem hiding this comment.
🚨 SLOP COP 🚨 · review
Verdict: blocking changes required.
GitHub does not allow the pull request author to submit a request-changes review. This review therefore uses comment state.
Confirmed findings:
-
A failed candidate publishes its ESM epoch before commit. Cross-root imports can then evaluate rejected edited files.
-
The CommonJS purge changes active code before commit. Failed and concurrent reloads mix old ESM state with candidate CommonJS state.
-
Each unique ESM URL retains another module graph. An unguarded simple POST can repeat this growth and reload all plugins.
-
The global hook and root map survive service stop. Repeated service creation retains roots and increases every later file-resolution scan.
The architecture scan found no equivalent backend loader. Move this logic into one mutable-module loader with transactional generation and lifecycle ownership.
Validation results:
- All 16 focused plugin tests passed.
- The server type check and build passed.
- The live browser route changed
before/beforetoafter/afterafter a successful reload. - Failed and concurrent live reloads reproduced the mixed CommonJS state.
- The full server suite passed 1,320 tests. One machine-installer test outside the changed plugin code failed.
- The worktree is clean, and the development server is stopped.
The final GPT-5.6-Sol review gate returned REQUEST CHANGES.
Use isolated candidate module state. Publish it only after success, release old generations, guard reload requests, and add rollback and restart tests.
Third round of slopcop findings on #919. Roll the epoch and the CommonJS evictions back when a candidate load fails. Round two keyed the URL marker by root so a cross-root import takes the imported plugin's epoch rather than the importer's. That is correct for a committed load, but it also meant a retained plugin's importers resolved against the epoch of a candidate that never committed, and read rejected files. Restoring the previous epoch and the evicted require.cache entries keeps the candidate private until it commits. This restores the rollback that round one removed as redundant. It was redundant then, because parent inheritance covered the only path that could reach a failed candidate. The cross-root keying added in round two opened a path that inheritance deliberately does not cover, so the rollback is load bearing now. Release mutable roots when a runtime stops, and deregister the resolve hook once no roots remain, so a process that creates many services does not scan historical roots on every later import. The new test fails without the rollback with `expected 'shared-rejected:cjs-rejected' to be 'shared1:cjs1'`. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Round three addressed in 3dd0b33. [P1] Failed ESM candidate published its epoch — confirmed, and you caught a regression I introduced in round two. Worth stating plainly: in round one you asked for a rollback, I implemented it, measured it as redundant with parent inheritance, and removed it. That was true then. Round two's cross-root keying — which you also asked for — opened a path inheritance deliberately does not cover, and that made the rollback load-bearing again. It is back, and the test fails without it: The test is the one you specified: plugin A imports plugin B, B's reload fails, A must still read B's committed files. [P1] Candidate CommonJS state — fixed in the same change. The eviction is now snapshot-and-restore: [P2] Loader state at service stop — fixed. Each runtime now tracks the roots it registered, releases them in [P1] "Guard permanent module-graph growth" — declining for the third time, and I want to be direct about why. This bundles two things:
For the record across all three rounds: 6 of your 13 findings were real defects and every one is fixed with a test that I verified fails without its specific fix. One ( Status: typecheck clean, 294 plugin tests across 29 files pass. The full server suite has one failure in |
## Problem
`bb plugin reload <id>` (and `bb plugin watch`) did not pick up source
edits for a plugin installed from a local path. The loader re-ran the
factory, but the factory it re-ran was the one evaluated at first load.
A full `bb plugin install` from the same path did not help either.
Path installs are **not** snapshot-copied — `installPathSource` records
the original directory as `rootDir`, and `resolveServerEntry`
deliberately loads those from source so authors can iterate:
> "Path installs and source-layout builtins ALWAYS load from source, so
author iteration via `bb plugin reload` and the builtin dev watcher sees
edited files"
So this was a real bug against stated intent, not by-design behavior.
## Cause
`plugin-runtime.ts` loaded the entry with:
```js
// Fresh instance per load: guarantees re-imports see current sources.
const jiti = createJiti(import.meta.url, { moduleCache: false, ... });
const mod = await jiti.import(await resolveServerEntry(row, manifest));
```
That comment was wrong. jiti 2.7.0 only transpiles when:
```js
S = !isCjs && !(isTypeModule && isAsync) && (...)
```
A package with `"type": "module"` imported through `jiti.import` (async)
hits `!(true && true)` → no transform → jiti calls native `import()`.
Node's ESM registry keys modules by resolved URL permanently, so the
second import returns the first module. `moduleCache: false` governs
only jiti's own CJS cache, and a fresh jiti instance does not touch
Node's registry.
Every plugin in this repo ships `"type": "module"` (all 7
`examples/plugins/*`, all 4 `official-plugins/*`), so this affected
effectively every path-installed plugin.
## Fix
Register a `module.registerHooks` resolve hook that stamps a per-root
reload generation onto every file URL inside a mutable plugin root. Each
reload becomes a distinct URL for the entry **and** every file it
imports, so submodule edits land too. Managed `git:`/`npm:` artifacts
are immutable after promotion and are left alone.
Two smaller fixes were tried and rejected:
- a cache-busting query passed to `jiti.import` — jiti strips the query;
three imports with distinct queries all returned the first value.
- `jiti.evalModule(..., { forceTranspile: true })` — fixes the entry
file but leaves imported submodules stale.
## Why tests missed it
The existing reload test's fixture writes `server.ts`, and TypeScript
always takes jiti's transpile path. The added test mirrors a real plugin
(`"type": "module"` plus plain `.js`) and asserts both the entry and a
submodule re-read. It fails on main with `expected 'entry1:sub1' to be
'entry2:sub1'`.
## Verification
Against a dev server launched from this worktree, a path-installed
plugin edited between reloads:
Before — three consecutive loads (install, reinstall, reload) all ran
the first version, whose string no longer existed on disk:
```
[reload-repro] FACTORY RAN, marker=MARKER_V1
[reload-repro] FACTORY RAN, marker=MARKER_V1
[reload-repro] FACTORY RAN, marker=MARKER_V1
```
After:
```
FACTORY entry=ENTRY_V1 sub=SUB_V1 (initial)
FACTORY entry=ENTRY_V2 sub=SUB_V1 (after entry edit)
FACTORY entry=ENTRY_V2 sub=SUB_V2 (after submodule edit)
```
`turbo run typecheck --filter=@bb/server` passes; 288 plugin tests
across 29 files pass.
## Risks
- `module.registerHooks` needs Node >= 22.15. Electron is pinned at
41.7.0, whose Node is well past that, but this was verified under dev
Node, not under the packaged Electron server.
- Each reload leaks the previous generation's module objects. That is
inherent to ESM reload and matches the pre-existing leak; it is bounded
by reload count in a dev loop.
- The hook is process-global and runs on every ESM resolve. It
short-circuits only for URLs under a registered mutable plugin root, so
server code and managed artifacts are untouched.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Problem
bb plugin reload <id>(andbb plugin watch) did not pick up source edits for a plugin installed from a local path. The loader re-ran the factory, but the factory it re-ran was the one evaluated at first load. A fullbb plugin installfrom the same path did not help either.Path installs are not snapshot-copied —
installPathSourcerecords the original directory asrootDir, andresolveServerEntrydeliberately loads those from source so authors can iterate:So this was a real bug against stated intent, not by-design behavior.
Cause
plugin-runtime.tsloaded the entry with:That comment was wrong. jiti 2.7.0 only transpiles when:
A package with
"type": "module"imported throughjiti.import(async) hits!(true && true)→ no transform → jiti calls nativeimport(). Node's ESM registry keys modules by resolved URL permanently, so the second import returns the first module.moduleCache: falsegoverns only jiti's own CJS cache, and a fresh jiti instance does not touch Node's registry.Every plugin in this repo ships
"type": "module"(all 7examples/plugins/*, all 4official-plugins/*), so this affected effectively every path-installed plugin.Fix
Register a
module.registerHooksresolve hook that stamps a per-root reload generation onto every file URL inside a mutable plugin root. Each reload becomes a distinct URL for the entry and every file it imports, so submodule edits land too. Managedgit:/npm:artifacts are immutable after promotion and are left alone.Two smaller fixes were tried and rejected:
jiti.import— jiti strips the query; three imports with distinct queries all returned the first value.jiti.evalModule(..., { forceTranspile: true })— fixes the entry file but leaves imported submodules stale.Why tests missed it
The existing reload test's fixture writes
server.ts, and TypeScript always takes jiti's transpile path. The added test mirrors a real plugin ("type": "module"plus plain.js) and asserts both the entry and a submodule re-read. It fails on main withexpected 'entry1:sub1' to be 'entry2:sub1'.Verification
Against a dev server launched from this worktree, a path-installed plugin edited between reloads:
Before — three consecutive loads (install, reinstall, reload) all ran the first version, whose string no longer existed on disk:
After:
turbo run typecheck --filter=@bb/serverpasses; 288 plugin tests across 29 files pass.Risks
module.registerHooksneeds Node >= 22.15. Electron is pinned at 41.7.0, whose Node is well past that, but this was verified under dev Node, not under the packaged Electron server.🤖 Generated with Claude Code