GeezerVison is showing github.com — fix(core): isolate teardown defects from plugin activation by ccclucky · Pull Request #62133 · anomalyco/opencode
Conversation
ccclucky
commented
Nov 5, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Issue for this PR
Closes #62068
Type of change
What does this PR do?
When an npm plugin is updated, its cache generation is swapped and pruned. A plugin whose shutdown hook lazily imports a file from the old generation (e.g. opencode-mem's lifecycle.js) then dies during teardown. In Plugin.activate, the replaced plugins' scopes are closed inside the activation batch, so that defect propagated through Scope.close and aborted the whole activation: the old registrations (providers, commands) were already gone and the replacement generation never loaded. The location kept serving built-ins until the next reload trigger, which matches the reported failed to reload plugins / ENOENT log and the silent provider loss.
This PR closes each replaced plugin's scope under its own catchCause, logging a warning and letting the activation continue. This mirrors the existing failed to clean up disabled plugin handling in the transform-failure worker. A teardown fault is now confined to the plugin that caused it, and the new generation (including the custom providers it registers) activates normally.
How did you verify your code works?
- New regression test in
packages/core/test/plugin.test.ts: activating a replacement over a plugin whose teardown dies. Before the fix the activation dies with the defect; after the fix the replacement and its siblings activate and the inventory is correct.
bun run script/test.ts test/plugin.test.ts test/plugin-failure.test.ts: 31 pass / 0 fail (the previously failing GUI-bundle case passes on Bun 1.4.4).
bun run script/test.ts test/plugin/ before and after: identical failure set on Bun 1.3.14, and all green on Bun 1.4.4.
bun run check passes (35/35 tasks).
Visual
<svg xmlns="http://www.w3.org/2000/svg" width="240" height="72" viewBox="0 0 240 72">
<style>
.t { font: 9px ui-sans-serif, sans-serif; fill: currentColor; }
.dim { opacity: .55; }
.row { font: 8px ui-monospace, monospace; fill: currentColor; }
.ok { opacity: .9; }
.lost { animation: blink 1.6s steps(1) infinite; }
@keyframes blink { 0%, 45% { opacity: .15; } 50%, 100% { opacity: .8; } }
</style>
<text class="t dim" x="14" y="16">before</text>
<text class="t dim" x="130" y="16">after</text>
<rect x="10" y="24" width="104" height="40" rx="5" fill="none" stroke="currentColor" stroke-opacity=".25"/>
<rect x="126" y="24" width="104" height="40" rx="5" fill="none" stroke="currentColor" stroke-opacity=".25"/>
<text class="row lost" x="20" y="40">mem: provider ✕ lost</text>
<text class="row dim" x="20" y="54">reload: ENOENT ✕</text>
<text class="row ok" x="136" y="40">mem: provider ✓</text>
<text class="row dim" x="136" y="54">reload: ok</text>
</svg>
Screenshots / recordings
Not a UI change.
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
A defect thrown by a replaced plugin's teardown (e.g. a shutdown hook
lazily importing a file from an npm cache generation that the update
already pruned) propagated through Scope.close and aborted the whole
activation. The old registrations were already gone and the replacement
generation never loaded, so the location kept serving built-ins until
the next reload trigger (anomalyco#62068). Close each replaced plugin's scope
under its own catchCause, mirroring the disabled-plugin cleanup path.
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks for tracking this down and adding a regression test! I think this duplicates #57096. It makes the same change in Plugin.activate: each replaced plugin's Scope.close gets its own catch, so a failing teardown is logged instead of stopping the reload. It also lets interruptions pass through instead of swallowing them.
If your test for #62068 (a teardown that dies while a replacement is loading, with sibling plugins and the inventory staying correct) covers something #57096's tests don't, please suggest it there or help review and test it. The other cause in #62068 is still open: the npm cache cleanup in packages/util/src/npm.ts deletes cache folders that a running plugin still uses. A focused pull request for that would be welcome.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
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.