GeezerVison is showing github.com — fix(plugin): only call function return values when tearing down a plugin by holny · Pull Request #57775 · anomalyco/opencode
Conversation
holny
commented
Oct 21, 2026
•
edited by opencode-agent
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Issue for this PR
Closes #57719
Type of change
What does this PR do?
A plugin's setup() runs as JavaScript, so it may return anything. The teardown that runs when the previous plugin generation is released only checked the returned value for truthiness and then called it:
(cleanup) => (cleanup ? Effect.promise(() => Promise.resolve(cleanup())) : Effect.void)
A plugin whose setup() returns an object therefore hits cleanup() and the reload dies with TypeError: o is not a function, which surfaces as opencode reload failing against the background service.
Only a real function counts as a cleanup callback now, so a plugin that returns something else is simply left without a teardown hook.
This is a different layer from #57096: that PR isolates a cleanup that throws so one plugin cannot abort the whole activation, while this one avoids calling a value that was never a cleanup function in the first place. The two are complementary — a plugin can still return a well-formed cleanup that throws, and #57096 covers that.
How did you verify your code works?
- New regression test in
packages/core/test/plugin/supervisor-reload.test.ts loads a local plugin whose setup() returns an object, then triggers a reload and asserts the new generation replaces the old one instead of the reload dying. Red/green checked: the previous truthiness check fails that case, the fix passes it.
bun test test/plugin/supervisor-reload.test.ts is 9/9.
bun test test/plugin/ is 396/397, with the single failure being a pre-existing timeout in module.test.ts that reproduces on the base commit.
bun typecheck clean in packages/core and packages/plugin.
Screenshots / recordings
N/A, not a UI change.
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
Added by the opencode bot (AI-generated).
Related: #57089
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
A plugin's setup() is JavaScript at runtime, so it may return anything. The
teardown that runs when the previous plugin generation is released checked
the returned value for truthiness and then called it, so a plugin whose
setup() returned an object aborted the whole reload with
"TypeError: cleanup is not a function".
Only a real function counts as a cleanup callback now.
Regression test in test/plugin/supervisor-reload.test.ts drives a reload
against a plugin whose setup() returns an object and asserts the new
generation replaces the old one. Red/green checked: the previous
truthiness check fails that case, the fix passes it.
Verification: `bun test test/plugin/supervisor-reload.test.ts` is 9/9;
`bun test test/plugin/` is 396/397 with the single failure being a
pre-existing timeout in module.test.ts that reproduces on the base
commit; `bun typecheck` clean in packages/core and packages/plugin.
|
The following comment was made by an LLM, it may be inaccurate:
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix works. I ran the #57719 reproduction from source on both checkouts. On the base, with a plugin whose setup() returns an object, opencode reload fails with TypeError: cleanup is not a function (adapter.ts:621). With this PR every reload prints Configuration reloaded. The new test in supervisor-reload.test.ts fails on the base and passes here. The rest of that file shows one failure, which also fails on the base. Type checks are clean in packages/plugin and packages/core.
Public API: unchanged. A non-function value returned from setup() is now ignored instead of called as a cleanup function, so existing plugins are unaffected.
No concerns. The fix is in the right place (the adapter, where the cleanup is called) and complements #57096, which handles a cleanup that throws.
Related: #57089
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Closing for now to free an open-PR slot — the branch stays put and I'll reopen if the teardown guard still needs a home after the current cleanup cycle.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Closing this in favour of the direct fix that landed in dev: #63548 (ec263d6) guards the teardown cleanup with typeof cleanup === "function" on the same acquireRelease line in adapter.ts, and additionally keeps a failing finalizer from aborting the plugin swap in plugin.ts. Same semantics, so keeping a duplicate open isn't useful.
If anyone picking up issue #57719 wants the supervisor-reload regression test from this branch, feel free to lift it.
|
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.
|