Skip to content

fix(core): keep plugin list consistent with live state during reload - #65909

Open
hearnadam wants to merge 1 commit into
anomalyco:devfrom
hearnadam:plugin-reload-list
Open

hearnadam wants to merge 1 commit into
anomalyco:devfrom
hearnadam:plugin-reload-list

Conversation

@hearnadam

@hearnadam hearnadam commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #64464

Type of change

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

What does this PR do?

During an in-place plugin reload, Plugin.activate deletes the outgoing suffix slots from active and closes their scopes (removing their tools and other scoped registrations) before loading replacements, preserving the stop-before-start lifecycle contract. Previously, Plugin.list returned a cached inventory array that was only rebuilt at the end of the reload, so callers reading plugin.list() mid-reload still saw the torn-down plugins as active while tool.list() no longer contained their tools.

This removes the cached inventory in packages/core/src/plugin.ts and computes snapshot() live in Plugin.list() (passing snapshot() directly to publish()). Because active.delete(id) runs before Scope.close(...) and active.set(...) runs only after replacement setup finishes, plugin.list() stays consistent with live registrations throughout reload without changing stop-before-start ordering.

How did you verify your code works?

  • Added a regression test in packages/core/test/plugin.test.ts that pauses mid-reload with a Deferred and asserts plugin.list() does not report the reloading plugin (or restarted trailing plugins) as active while their tools are absent from tool.list(). Verified it failed before the fix and passes after.
  • Ran bun run script/test.ts test/plugin.test.ts (24 pass, plus --rerun-each 10 --randomize on the new test), related plugin tests (plugin-failure.test.ts, plugin/supervisor.test.ts, plugin/supervisor-reload.test.ts, plugin/module.test.ts: 36 pass), bun typecheck in packages/core, bunx oxlint, and bunx prettier --check.

Screenshots / recordings

N/A — core/server fix.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Related: #59993

@hearnadam
hearnadam marked this pull request as ready for review November 23, 2026 22:36
@hearnadam
hearnadam marked this pull request as draft November 23, 2026 22:51
@hearnadam
hearnadam marked this pull request as ready for review November 24, 2026 00:06

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix looks right. I ran the new regression test against the base: it fails there (plugin.list() reports reloading/trailing as active while their tools are missing from tool.list()) and passes with this change. plugin.test.ts (24) and the related plugin, supervisor and module tests (36) all pass. I couldn't run the package typecheck script here (bun check isn't available), and tsc only showed build errors that are also on the base.

Reading list() live keeps stop-before-start ordering intact, and Plugin.Event.Updated still fires only after the reload. The state schema has only active/failed, so leaving restarting plugins out of the list is a reasonable way to keep both views consistent.

Public API: no schema, route or type changes. The only visible difference is that plugin.list (HTTP and ctx.plugin.list()) now leaves restarting plugins out while a reload is in progress, instead of showing them as active. Clients that refetch on plugin.updated are unaffected.

No blocking concerns.

Related: #59993

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new push is a rebase onto a newer dev. The PR's own diff is the same as before, and my earlier review left nothing open. I checked again on the new base: the regression test fails there and passes with this change. The related plugin tests pass (60/60). The public API is unchanged since my last review. No new concerns.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

plugin: a reloading plugin's tools leave ctx.tool.list() while ctx.plugin.list() says active (2.3.0)

1 participant