Skip to content

fix(mcp): report reconnect as pending while closing - #2958

Open
shenyankm wants to merge 1 commit into
MoonshotAI:mainfrom
shenyankm:sheny/issue-2956-mcp-reconnect-state
Open

fix(mcp): report reconnect as pending while closing#2958
shenyankm wants to merge 1 commit into
MoonshotAI:mainfrom
shenyankm:sheny/issue-2956-mcp-reconnect-state

Conversation

@shenyankm

Copy link
Copy Markdown

Related Issue

Resolve #2956

Problem

During MCP reconnect, both connection managers awaited the previous client's asynchronous close() before publishing the pending state. Because closeClient() clears the active client synchronously, get() could still report connected with the previous tool count while resolved() already returned undefined.

What changed

  • Start closing the previous client, immediately clear the resolved tool state, and emit pending before awaiting the close in both agent-core v1 and v2.
  • Preserve the existing reconnect attempt guard before starting the replacement connection.
  • Add mirrored regression tests that block the previous stdio client's close and verify the public state and status event.
  • Add a patch changeset for @moonshot-ai/kimi-code.

Validation:

  • Focused connection-manager tests: v1 44 passed; v2 42 passed.
  • Full package tests: v1 4143 passed; v2 5067 passed.
  • v1/v2 typecheck, v2 import-boundary lint, and type-aware oxlint on the four changed TypeScript files passed.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Aug 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 686ed94

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@shenyankm
shenyankm marked this pull request as ready for review August 16, 2026 00:15
@shenyankm

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 686ed94d58

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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.

BUG: MCP reconnect reports connected status after clearing the active client

1 participant