Skip to content

fix(core): detach disposed MCP registrations from root scope#37660

Merged
rekram1-node merged 1 commit into
v2from
mcp-registration-scope
Jul 19, 2026
Merged

fix(core): detach disposed MCP registrations from root scope#37660
rekram1-node merged 1 commit into
v2from
mcp-registration-scope

Conversation

@rekram1-node

Copy link
Copy Markdown
Collaborator

Follow-up to #37308, addressing known trade-off #8 (no-op finalizers accumulate in the root scope).

register() previously piped integration.transform(...) with Scope.provide(root), parking the transform's cleanup finalizer on the layer's root scope. Disposing a registration (on add() replacement or remove()) made the transform inert but could not unregister that finalizer, so every replaced or removed remote OAuth server left one dead closure on the root scope until process exit — a slow, unbounded memory leak once add/remove become programmatically callable (HTTP endpoints, config reconciler).

Fix: fork one child scope per registration and make entry.registration.dispose close that scope. Closing the child runs the transform's dispose finalizer (identical registry cleanup and reload behavior as before) and detaches the scope from root, so nothing accumulates. Closing an already-closed scope is a no-op, preserving dispose idempotency.

No behavior change beyond the leak fix. Existing suite passes (18/18), typecheck clean.

@rekram1-node
rekram1-node merged commit cbcf191 into v2 Jul 19, 2026
10 checks passed
@rekram1-node
rekram1-node deleted the mcp-registration-scope branch July 19, 2026 04:38
github-actions Bot pushed a commit to ReStranger/opencode that referenced this pull request Jul 19, 2026
* upstream/v2:
  mini: fix shell tool output display (anomalyco#37711)
  fix(core): detach disposed MCP registrations from root scope (anomalyco#37660)
  fix(core): preserve the first terminal failure (anomalyco#37705)
  fix(core): continue after malformed tool input (anomalyco#37701)
  fix(core): safely recover malformed tool input (anomalyco#37698)
  fix(simulation): render screenshot symbol glyphs (anomalyco#37691)
  fix(core): authorize relative external paths (anomalyco#37689)
  fix(tui): auto-approve permissions in auto mode
  feat(core): allow MCP Code Mode opt-out (anomalyco#37681)
  fix(codemode): stop leaking undefined into tool arguments (anomalyco#37652)
  fix(tui): style interrupted compaction neutrally (anomalyco#37655)
  fix(cli): harden managed service election (anomalyco#37645)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant