Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

fix(plugin): let a Promise plugin's cleanup disposals join the reload batch - #68589

Open
opencodejr[bot] wants to merge 1 commit into
devfrom
opencodejr/issue-fix-68514
Open

opencodejr[bot] wants to merge 1 commit into
devfrom
opencodejr/issue-fix-68514

Conversation

@opencodejr

@opencodejr opencodejr Bot commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #68514

Type of change

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

What does this PR do?

See #68514. When a Promise plugin's cleanup disposed its own registration (e.g. an MCP server added with ctx.mcp.transform), a hot reload tore down that server even though the replacement registers the same config. Any in-flight MCP tool call failed with Connection closed. The adapter ran the cleanup through Effect.acquireRelease, which uses the context from when the plugin was set up. registration.dispose() also used that setup-time context, whose State.batch had already ended, so the removal notified straight away instead of joining the host's reload batch, and the MCP reconcile stopped the server before the new activation re-registered it. The adapter now registers the cleanup with Scope.addFinalizer, so it runs in the unloading fiber's context. While the cleanup runs, registration.dispose() uses that context, so the disposal joins the reload batch like the host's own scope-owned disposals. A regression test covers a Promise plugin that disposes its registration in cleanup and re-registers after an await.

How did you verify your code works?

Reproduction (opencode-drive with the simulated model, a minimal stdio MCP server with a 12 s sleep tool, and a Promise plugin listed in plugins that registers the server with ctx.mcp.transform after a 500 ms wait and calls registration.dispose() in its cleanup; touch the plugin entrypoint 3 s into the call): on dev 045e9e3 without the fix the server's stdin closed ~1 ms after the cleanup, a new server pid started, and the tool returned MCP tool "sleep" on server "sleepy" failed: Connection closed (same on the 2.4.3 release). With the fix the same pid stayed up, the call completed and returned slept 12. New test keeps a Promise plugin's registrations through a reload when its cleanup disposes them in packages/core/test/model-plugins.test.ts fails without the fix and passes with it. bun test test/plugin test/model-plugins.test.ts test/mcp in packages/core: 894 pass, 14 fail; the same 14 (GitLab OAuth tests and one test/mcp/stdio.test.ts case) also fail with the fix stashed. The packages' typecheck script (bun check) is not available in the sandbox's Bun, so I ran tsc directly: tsc --noEmit in packages/plugin and tsc -b tsconfig.tests.json in packages/core both report no errors.

Screenshots / recordings

The reproduction on #68514 has the recording and script, where there is one.

Checklist

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

Opened by the bot from its reproduction of #68514 (simulated), fixed in a sandbox and reviewed in a separate session. A maintainer should review it before merging.


Added by the opencode bot (AI-generated).

Related: #55934

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This looks right to me. I ran the #68514 drive script on base and with this change: base closed the MCP server's stdin about 3 ms after the plugin cleanup and the in-flight call failed with Connection closed. With the change, the same server process stayed up and the call returned slept 12.

The cause checks out: in effect 4.1.0, acquireRelease runs its release step with the context from setup time, so a dispose() made from the cleanup used a batch that had already ended. With Scope.addFinalizer, the cleanup runs with the context of whatever is unloading the plugin, so the disposal joins the reload batch the same way the host's own disposals do. The disposal also joins a shutdown batch now, which is an improvement. The new test fails on base and passes here. The other plugin and MCP test failures are the same 14 that fail on base. tsc --noEmit in packages/plugin is clean.

Public API: unchanged. The plugin API's signatures and behaviour stay the same, except that a disposal made from a cleanup now joins the host's batch.

No blocking concerns.

Related: #55934

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.

MCP server stdio pipe torn down when plugin entrypoint is rewritten mid-call, dropping in-flight tool calls ("Connection closed")

0 participants