Skip to content

fix(mcp): retry failed connections on later tool calls - #2481

Merged
vastsa merged 2 commits into
vastsa:mainfrom
Linuxdazhao:fix/mcp-auto-reconnect-2471
Nov 21, 2026
Merged

vastsa merged 2 commits into
vastsa:mainfrom
Linuxdazhao:fix/mcp-auto-reconnect-2471

Conversation

@Linuxdazhao

@Linuxdazhao Linuxdazhao commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2471.

问题

MCP 断线后的第一次恢复握手如果再次失败,连接条目会一直缓存为 failed。即使服务器随后恢复,后续工具调用仍直接返回 UNAVAILABLE,只能编辑配置或手动点击 Test connection。

修复

  • 保留现有会话组装限流:故障服务器不会在每次 session assembly 时重复拨号。
  • 后续显式工具调用会重新握手,服务器恢复后无需手动测试即可继续调用。
  • 状态探测失败但旧 transport 仍存活时,也会先安全关闭空闲 transport 再重连;进行中的旧调用不会被中断。
  • 不会自动重放失败的 tools/call,避免重复执行已经发生过的写操作。
  • 更新 MCP 管理规范及 E2E-100 的自动恢复预期。

验证

Task candidate: b908d601bdf6
Base main: 5d480b7c936e
Environment: macOS, Node.js v26.13.1

  • PASS: node --test apps/desktop/test/user-mcp.test.mjs apps/desktop/test/plugin-mcp.test.mjs(72/72)。
  • PASS: 真实 stdio MCP 子进程断线场景。第一次恢复握手失败后重新启动服务,下一次工具调用自动完成第三次进程启动,状态恢复 ready,调用返回 ok,无需手动 Test connection。
  • PASS: 回归测试在修复前以 2 !== 3 失败,证明后续显式调用没有触发握手;修复后通过。
  • PASS: node scripts/check-pr-base-main.mjs --base upstream/main --head HEAD。
  • PASS: git diff --check upstream/main...HEAD。
  • PASS: GitHub Actions 6/6,包括 JS build / typecheck / lint / architecture / test、Docs check、PR base、Rust host-core、Windows E2E 和 Trusted extensions Electron E2E。
  • NOT RUN: Windows 完整 UI 旅程。E2E-100 当前在仓库中标记为 unit-covered,完整 UI journey 仍为 Draft;本次运行了其对应运行时测试和真实 stdio 恢复场景。

兼容性与剩余风险

不改变 MCP 协议、持久化数据、权限或作用域检查。故障服务器仍可能让每次显式重试支付一次连接超时,但不会再无限期卡在陈旧失败状态。

A failed recovery previously remained cached until the user edited the server or ran Test connection. Let explicit tool calls re-handshake while keeping session assembly from repeatedly dialing unavailable servers.
Incorporate the latest upstream main before candidate validation and PR creation.

@aiuo-codepilot aiuo-codepilot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

AIUO CodePilot · Preliminary review

Diff-only preliminary review of the failed-MCP-connection retry change in UserMcpRuntime, with the related tests and spec updates. The pin/failed-transport handling, active-call preservation, and no-session-assembly-redial behavior appear internally consistent in the shown hunks; no concrete added-line defect is evidenced. Verification is limited to the supplied diff text, with no runtime, typecheck, or repository access.

No evidenced findings in the supplied diff.

Head: b908d60
Base: 5d480b7
CI: success; mergeable: true.

Validation: code/tests NOT EXECUTED. Diff-only preliminary analysis; not approval. Human review and repository gates remain required.

@vastsa
vastsa merged commit 46f1e31 into vastsa:main Nov 21, 2026
6 checks passed
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失败后无法自动重连

2 participants