fix: 会话过期恢复体系增强(callTool 重试/404 识别/前端句柄)+ 本地部署与 E2E 验证工具链 - #7
Merged
Conversation
- tool-router 的 callTool 遇到 -32001 会话过期错误时作废连接并重试(最多 maxConnections+1 次),非会话错误与工具级错误仍快速失败 - server-mode 将失效的 mcp-session-id 视为句柄按原 id 重建会话,不再返回 404/-32001;会话清理空闲超时调整为 30 分钟 - session-manager 支持 createSession 传入显式 id 重建会话 - 补充 tool-router / session-manager 单元测试及集成测试,改用全局 fetch mock 替代 node-fetch
- 新增 src/routing/session-error.ts:统一会话过期(-32001/规范型 HTTP 404) 与可重连连接错误的分类,供路由与 TUI 共用 - callTool 与发现路径重试条件扩展至可重连错误(stdio 崩溃、SSE 断流、 RESPONSE_STREAM_ENDED),首调即透明恢复;超时/网络不可达保持快速失败 - 修正 404 过期识别:doSend 会将 HTTP_REQUEST_FAILED 二次包装为 HTTP_SEND_FAILED,按真实传播形态匹配 - findTool 复用发现缓存(60s TTL),每次调用减少一次后端 tools/list 往返 - TUI discovery-worker:会话过期自动重试(懒重建)+ HTTP 404 识别 - SessionManager 会话数上限护栏(10k,最旧空闲驱逐) - 新增单测 13 个、集成用例 3 个(404 恢复 / discovery-worker 三场景)
- deploy:local:clean+build → npm pack → tarball 全局真实安装(install-shape
硬校验,防软链式假安装)→ 安全重启 :5625 daemon → initialize 冒烟
- verify:local:自包含 E2E 回归,10 场景 15 断言
- 正常 N1-N6:HTTP 连接复用 / stdio / SSE / 标签过滤 / ping+DELETE / 诊断端点
- 恢复 F1-F4:HTTP -32001 与 404 过期重建(/__expire 控制端点触发)、
stdio 崩溃 respawn、前端会话句柄重启重建
- 共享安装管道 scripts/lib/install-local.mjs(构建产物新鲜度断言)
- build 脚本显式前置 clean,杜绝历史产物残留
- 文档:CLAUDE.md 收敛为唯一规范源并新增 E2E 场景回归规则;删除 AGENTS.md;
README 更新场景清单
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
延续 #2([MERC-3] 后台 server 模式连接断开问题)的修复,补全会话过期恢复体系的剩余缺口,并建立本地部署与端到端验证机制。
恢复体系增强
src/routing/session-error.ts:统一会话过期(-32001/ 规范型 HTTP 404)与可重连连接错误(stdio 进程退出、SSE 断流、RESPONSE_STREAM_ENDED等)分类,路由与 TUI 共用doSend会将HTTP_REQUEST_FAILED二次包装为HTTP_SEND_FAILED,按真实传播形态匹配(E2E 实测发现)findTool复用发现缓存(60s TTL):每次调用减少一次后端tools/list往返,过期重建频率减半Mcp-Session-Id同 id 透明重建,客户端无需重新握手;TTL 5→30 分钟降级为 GC;会话数 10k 上限护栏本地部署与 E2E 验证工具链
npm run deploy:local:clean+build →npm pack→ tarball 全局真实安装(install-shape 硬校验,防软链式假安装)→ 安全重启 daemon → 冒烟npm run verify:local:自包含端到端回归,10 场景 15 断言-32001与 404 过期重建(/__expire控制端点触发)、stdio 崩溃 respawn、前端会话句柄重启重建build显式前置 clean + 产物新鲜度断言,杜绝历史产物残留文档
关联 Issue
验证结果
Test plan
npm test全量回归npm run deploy:local本地部署冒烟npm run verify:local端到端 10 场景回归-32001