Repository navigation
[PR] MCP shim: wait for a cold-starting proxy before answering tools/list (#5001) - #5008
ranxianglei wants to merge 12 commits into
Conversation
…/list (#5001) A per-message host (e.g. CloudCLI) spawns a fresh claude.exe each turn; its SessionStart hook brings up the claude-lane proxy in a SEPARATE child while the MCP shim's first tools/list has already fired. The old single-shot manifest fetch hit ECONNREFUSED, the shim answered -32003 immediately, and Claude Code's ~250/500/1000ms retry budget ran out before the proxy finished booting (2.3-3.6s measured) — so the bili tools were lost for the whole process ("No such tool available: mcp__bili__compress"). fetchManifest now polls until the proxy answers (bounded: 15s default budget, 250ms cadence) instead of failing on the first refused connection, so a warm proxy is still served on the very first attempt while a cold one is waited for; a genuinely dead proxy still surfaces -32003 after the bounded wait rather than hanging the handshake forever. Export ensureManifest + add _resetMcpManifestForTest for the regression suite, which pins cold-start recovery, warm single-attempt, non-ok retry, and the bounded timeout all four directions of the gate.
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.9237-pr.5008.3176840This exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr5008.tgz
npm install -g packageInstall instructions are refreshed on each push. |
(ai: vllm-qwen/qwen3.8-27b) 查重: 不重复 —— 独立检索了 open+closed 的 issue/PR(按失败签名与关键词两次搜索,MCP shim / tools/list / fetchManifest / cold-start polling 均无并行工作);本 PR 是 #5001 的唯一修复。 标签: bug + claude-code + scope/wiring + p1(claude 车道协议接线缺陷;对按消息重启的宿主冷启动期压缩工具整体不可用 → p1,与同家族 #4641/#4994/#4893 既有标签口径一致;已打在镜像 #5008)。 结构化八问
测试有效性:新增测试经 mock fetch 钉住 gate 四向(cold N 次拒绝→ready = 回归钉;warm 首试返回不再轮询;503 重试不当终态;dead proxy 有界不循环)——断言有牙(调用次数 + elapsed 上界),bug 回归时抓得住。本地定向验证:新测试 + issue1875/issue2752/claude-mcp-entry/zcode-mcp-entry/zcode-mcp-degraded/codex-mcp-shell 共 75/75 绿;typecheck + build 在 rebased head(origin/master 9b6ec23)clean(build-info commit=7e9cbadc6)。 CI 状态:30 项 check 仅 残余风险(诚实边界):修法成立的前提是宿主对「仍在 pending 的原始 tools/list 请求」接受迟到响应——stdio MCP 请求挂在子进程管道上不撤,理论上成立,但 PR 内没有真实 Claude Code 的端到端验证(单测 mock 了 fetch)。建议报告者发版后在 CloudCLI 实测一次冷启动确认工具注册;若 CC 实际会丢弃 pending 请求,则需建议 #2(keep-alive)兜底——这正是它留给 owner 决策的原因。 结论:可合(待 rerun 转绿确认即可合并;若 flake 再红,证据链已表明与本 diff 无关,owner 确认后放行)。 |
The file's synchronous UnifiedStore work (second-handle open + deleteSession) blocks the event loop; on a loaded windows/node22 runner the stall exceeded the proxy's default 5s idle-reap, which destroyed the client's pooled socket mid-test and surfaced as a transport-level 'fetch failed' in the #2960 ② test (PR #5008 CI, run 40579161549). Pinning BILI_KEEP_ALIVE_TIMEOUT_MS=60000 for this hermetic process removes the reap window entirely.
(ai: vllm-qwen/qwen3.8-27b) 跟进:分支上新增 commit 审查期间作者侧推了一个后续提交:
CI 状态(诚实边界):新 head 的 run 因我的 rerun 被新 push 取代而取消后重新触发,但当前无法从本环境确认其最终红绿——镜像缓存自 21:17Z 起对该 PR 冻结(刷新停滞),GitHub 共享 API 配额已耗尽(两次单点拉取均 403 rate-limit,按纪律不再重试)。本地可验证项全部为绿(75/75 定向套件 + 本测试 + typecheck/build @ 7e9cbad + 2/2 @ 25d044c)。 结论维持:可合。代码面(两个 commit)审核完毕、无回归发现;合并前请 owner 在配额恢复后看一眼新 head 的 check 全绿即可(或等镜像缓存自愈)。若 win(22,4) shard 仍红,证据链已表明与本 diff 无关,属 runner 负载类 flake。 |
(ai: vllm-qwen/qwen3.8-27b) 结论先行:CI 已转绿。 红的不是本 PR 的代码,是 八问:
|
(ai: vllm-qwen/qwen3.8-27b) Synced origin/master (through 9563c1b) into the branch — clean auto-merge, no conflicts (PR's cold-start wait and master's #4580 toolCallId channel coexist in src/mcp.ts); local typecheck + build + targeted mcp/fork-replica tests green; pushed head 90924b6, PR no longer behind (mergeable_state: blocked, CI running, 0 failures so far). |
…unified mode The broad-corpus CI baseline (tests/preload-storage-baseline.mjs) forces BILI_STORAGE_UNIFIED=legacy for the whole file. The #5140 regression pin did not pin its own mode, so under the legacy baseline the unified index does not exist, reconstructRawTailForFork fails closed, and the test deterministically failed with 409 !== 200 in every CI shard/OS while passing locally (default-full ambient). Pin both unified modes like the sibling tests in this file; legacy is structurally out of scope for this recovery path. Rides PR #5008 branch to clear the inherited red on test lanes ubuntu22-s3/ubuntu24-s3/windows22-s4.
…anxianglei/billion-context into 2026-10-28_mcp-cold-start-wait # Conflicts: # tests/plugin-fork.test.ts
…x reds (#4599) Brings in the sentinel-converged fixes for the two red lanes on head 44e1f86: #5103 win32 warning separator (shadow.ts path.join) and #4739 EBUSY teardown (closeQuietly before rmrf), plus the #4788 persist.ts ref-tracking root fix (PR #5262) and inc-canonical-pointers settle hardening. Conflict in tests/plugin-fork.test.ts resolved by keeping this branch's two-mode (full+shadow) #5140 pin loop — strict superset of the ci-fixes single-full pin. No new content of this PR touched.
(ai: vllm-qwen/qwen3.8-27b) Conflict resolved and synced — new head What this run did:
八问
判定:冲突已解除,新 head |
[ework] CI fix verified green ✓ |
(ai: vllm-qwen/qwen3.8-27b) Verdict: APPROVE (at head Direction (①): #5001 is real and well-evidenced (warm 18/18 vs cold 2/54; measured cold boot 2.3–3.6s vs Claude Code's ~1.75s retry budget). Root cause is the shim's fail-fast single-shot Regression audit (②) — existing behaviors on the touched paths, item by item:
Code (③): the loop is correct — deadline computed once, non-ok statuses retried (a starting proxy's 503 is not treated as final — right call), one stderr notice (no log spam), Tests (④): Diff (⑤): exactly the claimed 4-file footprint vs master (177+/45-); branch 0 behind master; no unrelated churn. CI: 30/30 checks green at head No small findings to fix on the spot. No 八问
判定:可合(CI 全绿、无回归、无小修项;按 §7.4 因默认时序变更归人工合并,不走 auto-merge)。 |
[ework] CI fix verified green ✓ |
1 similar comment
[ework] CI fix verified green ✓ |
What & why
A per-message host (e.g. CloudCLI) spawns a fresh
claude.exe --resume=<id>for every message and exits after replying. Each process's SessionStart hook (claude-native-bootstrap.js) brings up the claude-lane proxy in a separate child, while the MCP shim (claude-mcp-entry.js) servestools/listalmost immediately. The proxy takes 2.3–3.6s to start listening, but Claude Code's MCP client retries its handshake only ~250/500/1000ms and then gives up for the whole process. So on every cold start the shim's single-shot manifest fetch hit ECONNREFUSED, answered-32003, and the bili tools were never registered — the model calledcompressand gotNo such tool available: mcp__bili__compress. Reporter data: warm lane 18/18 got tools, cold lane 2/54.Fix
fetchManifest()(src/mcp.ts) now polls until the proxy answers instead of failing on the first refused connection — bounded to a 15s default budget at 250ms cadence. A warm proxy is still served on the very first attempt (no added latency); a cold one is waited for; a genuinely dead proxy still surfaces-32003after the bounded wait rather than hanging the handshake forever. Thetools/listerror text now reads "even after waiting for a cold start".Because this lives in the shared shim, every
runMcpStdiolane (claude/codex/zcode/…) inherits it. Degraded mode is untouched (it returns{tools: []}before ever callingensureManifest).Behavioral change (disclosed)
tools/listreturned-32003immediately (one fetch attempt, ≤5s timeout).-32003. The warm path is unchanged (single attempt). Rationale: bridge the gap between Claude Code's ~1.75s retry budget and the measured 2.3–3.6s cold boot so the tools are delivered instead of permanently lost.No new env var / config field / CLI flag — the wait budget is a module constant (
DEFAULT_MANIFEST_WAIT_MAX_MS). No wire/message-shape change (thetools/listsuccess response is byte-identical to before). No kernel / persistence / config-schema touch.Tests
New
tests/issue5001-mcp-cold-start.test.tspins all four directions of the gate via a mocked fetch:Existing
src/mcp.tsconsumer suites green (issue2752, issue1875, claude-mcp-entry) plus the broader MCP-surface suites. typecheck + build clean on the rebased head (origin/master9b6ec2345).Not included here
The reporter's optional suggestion #2 (a knob to keep the claude lane alive across per-message hosts / configurable idle grace) is a config-surface + lifecycle decision, left for owner sign-off rather than bundled into this fix — the bounded wait already removes the hard failure it was working around.
Fixes #5001