GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(core): keep the generation swap when a plugin cleanup throws by Veld101 · Pull Request #57096 · anomalyco/opencode

Conversation

@Veld101

@Veld101 Veld101 commented Oct 19, 2026 •
edited by opencode-agent Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Issue for this PR

Closes #57089

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Plugin.activate closes the previous generation before loading the new one, and the close loop had no per-plugin isolation. A plugin whose finalizer throws aborted the whole activation. By then the old builtins had already been closed — they are last in activation order, so the reverse close loop reaches them first — and the new generation never loaded, so their transforms were never re-registered:

T2  reload fails: `failed to reload plugins` with the plugin's ReferenceError
T3  `opencode.config.compaction` is gone, SessionCompaction rebuilds from `{ auto: true }`
    and auto-compaction runs despite `compaction: { auto: false }`

Each old slot now closes independently:

if (slot.activation && !slot.activation.failure)
  yield* Scope.close(slot.activation.scope, Exit.void).pipe(
    Effect.catchCause((cause) => Effect.logError("failed to close plugin", { "plugin.id": id, cause })),
  )

A teardown failure is logged with the plugin id and cause instead of aborting the swap, so the new generation still loads and builtin registrations survive. load() already isolates setup failures; this closes the corresponding gap on the teardown path.

This is the minimal option from the report. Two larger options remain open and are not attempted here: staging the new generation before closing the old (plugins hold process-wide resources), and separating builtins from user-plugin generations so a user change cannot unload them. Either would make the swap transactional rather than best-effort.

How did you verify your code works?

One case in packages/core/test/plugin-failure.test.ts: broken mirrors the user plugin and builtin is last in activation order, like internal.post. Generation 2 replaces both, and the case asserts the swap succeeds and the builtin transform is re-registered with the new revision.

The throwing finalizer is registered only for the revision being replaced. That is deliberate: it keeps the surviving generation healthy so teardown at the end of the test does not add an unrelated failure. (With a finalizer that always throws, the fixed behaviour loads the broken plugin successfully and the case then fails at teardown instead, which would be testing the wrong thing.)

Against the current code the case fails: the ReferenceError escapes Plugin.activate and the builtin command is gone.

bun test test/plugin-failure.test.ts              # pass
bun test test/plugin test/plugin-failure.test.ts test/plugin.test.ts   # 420 pass, 0 fail
bun typecheck                                     # packages/core, clean
prettier --check                                  # clean
bun run lint                                      # exit 0, no new findings

Screenshots / recordings

Not applicable; no 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: #49982, #52618

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@github-actions

github-actions Bot commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

opencode-agent[bot]
opencode-agent Bot reviewed Oct 19, 2026
View reviewed changes

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

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 is sound. On the base, the reproduction from #57089 fails: when a plugin's cleanup throws, activate() fails and the builtin's command is gone afterwards. With this PR the swap succeeds and the builtin's new revision is registered. Your new test fails without the fix and passes with it. The plugin test suites (422 tests) and the packages/core typecheck pass.

The new handling copies what the file already does when cleaning up disabled plugins (catchCause + log), so it fits. Interruption isn't a concern here, because Scope.close runs finalizers in a way that can't be interrupted.

Public API: unchanged.

No blocking concerns.

Related: #49982, #52618

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Jun516
Jun516 reviewed Oct 20, 2026
View reviewed changes

@Jun516 Jun516 left a comment

Copy link
Copy Markdown

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.

One edge case in the new catch: Effect.catchCause also turns an interruption from a cleanup finalizer into successful activation. Could this use the existing Effect.catchCauseIf((cause) => !Cause.hasInterrupts(cause), ...) pattern used later in this file, and add an interruption regression?

I checked with the real PluginTestLayer and Bun 1.4.2 using this test body:

Effect.gen(function* () {
  const plugins = yield* Plugin.Service
  yield* plugins.activate([
    { id: "interrupted", revision: "1", effect: () => Effect.addFinalizer(() => Effect.interrupt) },
  ])
  const activation = yield* plugins.activate([]).pipe(Effect.forkChild({ startImmediately: true }))
  const exit = yield* Fiber.await(activation)
  expect(Exit.isFailure(exit)).toBe(true)
  if (Exit.isFailure(exit)) expect(Cause.hasInterrupts(exit.cause)).toBe(true)
})

From packages/core: bun run script/test.ts test/plugin-failure.test.ts --test-name-pattern "preserves interruption during plugin cleanup".

The check passes on the pre-fix source, fails with the exact plugin.ts blob from this PR's 10e87b9 (Expected: true; Received: false), and passes with catchCauseIf. This is a local focused check, not a full-suite result. AI assistance was used for the test and analysis.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
anqiang.ex
fix(core): keep the generation swap when a plugin cleanup throws
536dc02
`Plugin.activate` closes the previous generation before loading the new one, and
the close loop had no per-plugin isolation. A plugin whose finalizer throws
aborted the whole activation: the old builtins had already been closed, the new
generation never loaded, and their transforms were never re-registered. Builtin
state then fell back to defaults, so a user plugin's broken cleanup silently
re-enabled `compaction.auto` despite `compaction: { auto: false }` (anomalyco#57089).

Each old slot now closes independently, logging `failed to close plugin` with the
id and cause. One plugin's teardown failure is reported instead of aborting the
swap, so the new generation still loads and builtins keep their registrations.

Adds a case with a finalizer that throws only for the revision being replaced, so
the surviving generation tears down normally and the assertion covers the swap
alone. It fails without the change: the error escapes `Plugin.activate` and the
builtin command is gone.
@Veld101
Veld101 force-pushed the plugin-swap-cleanup branch from 10e87b9 to 536dc02 Compare October 20, 2026 12:44
@Veld101

Veld101 commented Oct 20, 2026

Copy link
Copy Markdown
Author

Good catch — adopted. Scope.close now uses Effect.catchCauseIf((cause) => !Cause.hasInterrupts(cause), ...) so a cleanup interruption propagates instead of being logged and swallowed, and I added your interruption regression as preserves interruption during plugin cleanup in plugin-failure.test.ts. Verified: bun test test/plugin-failure.test.ts -> 10 pass / 0 fail, packages/core typecheck clean. Pushed in 536dc02. Thanks for the exact repro — it made the distinction obvious: a throwing cleanup must not abort the swap, but an interruption is not a plugin failure.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@opencode-agent opencode-agent Bot mentioned this pull request Oct 21, 2026
cli: opencode reload against the background service crashes with TypeError in ServerProcess.start / Worktree.refresh (2.1.2, Windows); --standalone reload works #57719
Open
@holny holny mentioned this pull request Oct 21, 2026
fix(plugin): only call function return values when tearing down a plugin #57775
Closed
3 tasks done
@opencodejr opencodejr Bot mentioned this pull request Nov 5, 2026
fix(core): isolate teardown defects from plugin activation #62133
Closed
3 tasks done
@ccclucky ccclucky mentioned this pull request Nov 5, 2026
fix(core): pin npm cache generations while a plugin instance uses them #62146
Closed
3 of 6 tasks
@github-actions

github-actions Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot closed this Nov 19, 2026
@github-actions github-actions Bot added the automated-pr-cleanup label Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@opencode-agent opencode-agent[bot] opencode-agent[bot] left review comments
+1 more reviewer
@Jun516 Jun516 Jun516 left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

automated-pr-cleanup

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

A throwing plugin cleanup during reload aborts the generation swap and silently drops builtin registrations

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@Veld101 @Jun516
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.