Skip to content

[PR] MCP shim: wait for a cold-starting proxy before answering tools/list (#5001) - #5008

Open
ranxianglei wants to merge 12 commits into
masterfrom
2026-10-28_mcp-cold-start-wait
Open

ranxianglei wants to merge 12 commits into
masterfrom
2026-10-28_mcp-cold-start-wait

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

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) serves tools/list almost 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 called compress and got No 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 -32003 after the bounded wait rather than hanging the handshake forever. The tools/list error text now reads "even after waiting for a cold start".

Because this lives in the shared shim, every runMcpStdio lane (claude/codex/zcode/…) inherits it. Degraded mode is untouched (it returns {tools: []} before ever calling ensureManifest).

Behavioral change (disclosed)

  • Old: on an unreachable proxy, tools/list returned -32003 immediately (one fetch attempt, ≤5s timeout).
  • New: it polls up to 15s before returning -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 (the tools/list success response is byte-identical to before). No kernel / persistence / config-schema touch.

Tests

New tests/issue5001-mcp-cold-start.test.ts pins all four directions of the gate via a mocked fetch:

  • cold start: N refused connections then ready → manifest served (the regression pin — the old single-shot fetch rejected on attempt one);
  • warm proxy: answered on the first attempt, no re-poll;
  • non-ok status (503) retried, not treated as final;
  • dead proxy: bounded — rejects instead of looping forever.

Existing src/mcp.ts consumer suites green (issue2752, issue1875, claude-mcp-entry) plus the broader MCP-surface suites. typecheck + build clean on the rebased head (origin/master 9b6ec2345).

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

…/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.
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-28_mcp-cold-start-wait (8a14505)

Latest build — install this exact version

npm install -g billion-context@0.0.9237-pr.5008.3176840

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Recent builds (commit → version)

commit version build
8a14505 billion-context@0.0.9237-pr.5008.3176840 build
45eb856 billion-context@0.0.7416-pr.5008.5c76228 build
8eb5f95 billion-context@0.0.7244-pr.5008.cd2b635 build
44e1f86 billion-context@0.0.7146-pr.5008.6c44c3f build
eaee6d5 billion-context@0.0.6883-pr.5008.153130c build
09dfa8a billion-context@0.0.6600-pr.5008.393aaa6 build
90924b6 billion-context@0.0.6588-pr.5008.59a7495 build
cc37732 billion-context@0.0.6580-pr.5008.28a11ed build
25d044c billion-context@0.0.6568-pr.5008.8547eb1 build
7e9cbad billion-context@0.0.6560-pr.5008.0d06d99 build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr5008.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title MCP shim: wait for a cold-starting proxy before answering tools/list (#5001) [PR] MCP shim: wait for a cold-starting proxy before answering tools/list (#5001) Oct 27, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(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)。

结构化八问

  1. 是什么问题:按消息型宿主(CloudCLI)每条消息都是全新 claude.exe 进程,SessionStart hook 在独立子进程拉起 proxy(2.3–3.6s 才监听),而 MCP shim 几乎立即应答 tools/list;旧代码单次 fetch 遇 ECONNREFUSED 即终态返回 -32003,Claude Code 的重试预算(~250/500/1000ms)耗尽后整个进程放弃 → bili 工具从未注册,模型调 compress 全部 No such tool available。报告者数据:暖车道 18/18、冷车道 2/54。
  2. 什么原因导致:shim 与 proxy 是两个独立子进程,存在启动顺序竞态,而 fetchManifest() 把「首次连接被拒」当作终态——缺的是有界等待语义,不是网络本身的问题。
  3. 影响范围与严重程度:仅在「tools/list 到达时 proxy 尚未监听」的窗口内触发——按消息重启的宿主几乎每会话都中招;交互式用户首次启动后后续 attach 暖 proxy,基本不受影响。严重度:受影响窗口内压缩能力整体停摆(模型调用失败数轮后 nudge 自抑制),会话本身仍可用 → p1。
  4. 怎么修复的:fetchManifest() 从单次尝试改为有界轮询——默认 15s 预算 / 250ms 间隔 / 单次 3s 超时;暖 proxy 首试即返回(零附加延迟);非 ok 状态(如 503)重试至截止;真死的 proxy 到点后返回 -32003,不无限挂起握手;并发 tools/list 共享同一轮询循环(manifestPromise 缓存语义不变)。改动位于共享 runMcpStdio shim,claude/codex/zcode 等所有 MCP 车道自动继承;degraded 模式在 ensureManifest 之前就返回 {tools: []},不受影响。
  5. 是否有回归问题:逐项审过触碰路径的既有行为——① 暖路径:成功分支逐字未动,成功响应字节级不变,无多余轮询;② degraded 模式:旁路 ensureManifest,行为不变;③ 错误面:旧=立即 -32003,新=最多等 15s 后 -32003(PR 已披露,属有意变更);④ 持久非 ok origin(如误配永远 404):现在会耗满 15s 才报错而非立即报错——有意取舍,可接受;⑤ 一处作者未写细的披露项:单次尝试超时从 5s 变为 3s(总预算不受影响,但新值只给了 15s 总预算没单列——小措辞遗漏,不拦)。无 fail-fast 变吞错、无语义漂移、无阈值漂移超出上述范围。
  6. 是否破坏缓存:不涉及——不碰前缀缓存策略、重试策略、增量游标或去重键;成功响应字节级一致。
  7. 是否改了设计方向:没有。不碰 kernel/持久化/config schema/wire 形状;等待预算是模块常量而非配置项(符合 env 纪律)。报告者建议 fix: address all code review findings (condense, routing, session-id, dead code) #2(lane keep-alive knob)属 config surface + lifecycle 决策,正确地留待 owner 拍板,未混入本 PR。
  8. 是否引入新配置:无(无 env/config field/CLI flag)。

测试有效性:新增测试经 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 仅 test (windows-latest, 22, 4) 红。拉日志定位:not ok 376 fork receipts cut pinned fork_base checkpoints (#2960 ②) — TypeError: fetch failed @ tests/fork-replica-convergence.test.ts:55(~12.5s)。该测试属 storage/fork 子系统,与本 PR diff 零交集(文件内 mcp 引用为 0);本地定向复现 2/2 绿;master 9b6ec23 当时全绿(#4599 floor 356)→ 判定 Windows shard 环境 flake(该 harness 有 socket-teardown 前科 #3181),非本 PR 引入回归。已触发一次 rerun-failed-jobs(201),已在 #4599 留一行记录。

残余风险(诚实边界):修法成立的前提是宿主对「仍在 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.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

跟进:分支上新增 commit 25d044c32(test-only)已独立审过

审查期间作者侧推了一个后续提交:test: pin 60s keep-alive in fork-replica-convergence hermetic harness(tests/fork-replica-convergence.test.ts,+4 行)。独立复核结论:

  • 根因与我此前对 flake 的判定一致:该文件里同步 UnifiedStore 操作(second-handle open + deleteSession)阻塞事件循环,加载较重的 windows/node22 runner 上停摆超过 proxy 默认 5s idle-reap,连接池里的 socket 被中途回收 → 传输层 fetch failed。
  • 修法正确且位置正确:在 hermetic 测试进程内 pin BILI_KEEP_ALIVE_TIMEOUT_MS=60000,消除 reap 窗口;不改生产默认值(5s 保持),不掩盖任何产品行为——harness 本就不该依赖生产 reaper 在负载下宽松。
  • knob 真实存在:src/knobs.ts:160-162(env > file > default,默认 5000),env 在文件顶部模块加载期设置、先于 startServer 读取,生效路径成立。
  • 本地验证:更新后的 head(25d044c)上定向跑 tests/fork-replica-convergence.test.ts → 2/2 绿。

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。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

结论先行:CI 已转绿。 红的不是本 PR 的代码,是 tests/fork-replica-convergence.test.ts 在 windows/node22 高负载下的传输层竞态(stale keep-alive socket)。已在测试文件内钉住 keep-alive 预算(+4 行),新 head 25d044c32 全部 26 项 check 绿(含原红项 test (windows-latest, 22, 4))。查重:不重复——#4599 历史与全仓 issue 均无该测试的失败记录,属首次出现的负载相关 flake。

八问:

  1. 是什么问题:windows node22 shard 4 里 fork receipts cut pinned fork_base checkpoints…(#2960 ②) 报 TypeError: fetch failed(传输错误,非断言失败);同 shard 其余 1801 个测试全过,同 run 其他 10 个测试 leg 全绿。
  2. 什么原因导致的:该测试在进程内起代理,两次 HTTP 请求之间用第二个 store 句柄做同步 SQLite 操作(open → deleteSession → close)。高负载 runner 上这些同步调用阻塞事件循环约 9 秒(日志实测:代理最后一条日志到 fetch 失败间隔 ~9.8s),超过代理默认 5s 空闲 keep-alive 预算 → 代理在测试中途回收了客户端池化连接 → 下一次 fetch 写到死连接上即 'fetch failed'。为何此时才暴露:本 PR 新增一个测试文件改变了加权分片(shard 4 由 197→198 个文件、约 40 个文件换防),并发组合变了、负载更高;同一 commit 在 ubuntu 三片全过、本地 Linux 也过。本 PR 的 MCP 改动(仅 src/mcp.ts + 新增 mock 测试)与该路径零交集。
  3. 影响范围与严重程度:仅 CI 稳定性——windows/node22 高负载下的偶发 flake;生产行为零影响,无功能回归。
  4. 怎么修复的:在测试文件顶部钉 BILI_KEEP_ALIVE_TIMEOUT_MS=60000(既有已文档化 knob,默认 5s)。整个测试远小于 60s,服务端在测试期间不可能再回收池化连接,从根上消除竞态窗口——不是在客户端加重试掩盖症状。与该文件既有的 hermeticity 钉法同类(BILI_PERSIST_ZSTD / BILI_CONFIG_FILE / BILI_STORAGE_UNIFIED)。
  5. 是否有回归问题:无。改动仅为测试进程内的 env 赋值(node --test 每文件独立子进程,不影响任何其他测试);生产代码路径零触碰;typecheck 干净;本地定向跑该文件 2/2 + issue5001-mcp-cold-start 3/3 绿。
  6. 是否破坏缓存:不涉及(未触碰缓存/重试/游标逻辑)。
  7. 是否改了设计方向:不涉及。
  8. 是否引入了新的配置:不涉及——BILI_KEEP_ALIVE_TIMEOUT_MS 是 CONFIGURATION.md 已文档化的既有 knob,只在该测试进程内生效,用户可见配置面零变化。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(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).

ci-check added 8 commits October 28, 2026 10:59
…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.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

Conflict resolved and synced — new head 8a14505d4f pushed (regular push, no force-push; remote head verified unchanged before push).

What this run did:

  1. Fetched live state: branch head 45eb85685f, master c26c31ace4. The branch's merge base is the ci-fixes tip 06ad804ac (2026-10-31) — master has moved 342 commits past the branch's last sync.
  2. Merged refs/remotes/origin/master into the branch. One honest footnote: the first merge attempt accidentally merged a STALE local ref — this workdir carries local branches literally named master and origin/master (both at 33104b1f95, 38 commits behind), making the shorthand origin/master ambiguous. I detected the wrong second parent, reset, and redid the merge against the explicit ref refs/remotes/origin/master. The local branches were left in place (workdir hygiene, not mine to delete).
  3. Exactly ONE conflict against true master: tests/plugin-fork.test.ts. Resolved by union of intent — master's file (which carries post-sync updates the branch lacked: Zero-Inheritance Session Cloning: Unified Fix for Eight Independent Defects in the Fork Adoption Chain (Next Release Tar | 会话克隆零继承:fork 收养链上八类独立缺陷统一修复(下版目标) #4266 metering-mass exclusion from fork identity, the # Cache hit collapses to 1–12% for a whole generation, then the very next request returns to 100% — repeated 15× in one day #5608 timestamp-ledger fork test, # Cache hit collapses to 1–12% for a whole generation, then the very next request returns to 100% — repeated 15× in one day #5608-D removal of the cold-load refLedgerAligned expectation) + the PR's [Bug][fork] Cold restore cannot use an intact unified raw tail for a non-retained parent (#4266 item 4) #5140 dual-mode (["full", "shadow"]) loop, which is a strict superset of master's single-full-mode version.
  4. Verified the PR's footprint is intact after the merge — the branch differs from master by exactly its 4 files: src/mcp.ts (+74, the polling fix), tests/fork-replica-convergence.test.ts (+4 keep-alive pin), tests/issue5001-mcp-cold-start.test.ts (new, +82), tests/plugin-fork.test.ts (the loop).
  5. Local verification at the pushed head: typecheck clean; build clean; targeted suites green — plugin-fork 58/58 (the conflict file, including the two tests that fail on the naive "take ours" resolution: [PR] fix: classify FORK_PREFIX_CONFLICT rejections instead of failing blind (#3740) #3743 taxonomy and # Cache hit collapses to 1–12% for a whole generation, then the very next request returns to 100% — repeated 15× in one day #5608-D restart test), issue5001-mcp-cold-start 4/4, fork-replica-convergence 2/2, MCP consumer suites (claude-mcp-entry / issue2752 / issue1875) 56/56.
  6. CI status (honest boundary): the mirror check cache for this PR is frozen at 2026-10-31 (old head 45eb85685f, mergeable_state: dirty, 0 failed / 17 pending at that time — so the only recorded blocker was the conflict itself, no red CI items). The new head's CI is re-running; I cannot confirm its outcome from the cache in this run and will not assert green.

八问

  1. 是什么问题:PR 分支落后 master 342 个提交,与基线分支产生合并冲突(dirty),无法合并。
  2. 什么原因导致的:分支自 2026-10-31 最后一次同步后 master 持续推进,tests/plugin-fork.test.ts 两侧各自演进——master 侧带入了 Zero-Inheritance Session Cloning: Unified Fix for Eight Independent Defects in the Fork Adoption Chain (Next Release Tar | 会话克隆零继承:fork 收养链上八类独立缺陷统一修复(下版目标) #4266/# Cache hit collapses to 1–12% for a whole generation, then the very next request returns to 100% — repeated 15× in one day #5608/# Cache hit collapses to 1–12% for a whole generation, then the very next request returns to 100% — repeated 15× in one day #5608-D 的测试更新,PR 侧带入了 [Bug][fork] Cold restore cannot use an intact unified raw tail for a non-retained parent (#4266 item 4) #5140 双模式钉法,git 无法自动裁决。
  3. 影响范围与严重程度:仅阻塞本 PR 合并;产品行为零影响。
  4. 怎么修复的:把 refs/remotes/origin/master(c26c31ace4)merge 进 PR 分支;唯一冲突按意图并集解决(保留 master 全部测试更新 + PR 的 [Bug][fork] Cold restore cannot use an intact unified raw tail for a non-retained parent (#4266 item 4) #5140 full/shadow 双模式循环);PR 自身改动(mcp 冷启动轮询等 4 文件)逐字保留,合并后与 master 的 diff 恰好等于 PR 足迹。
  5. 是否有回归风险:逐项核过——冲突文件若简单取 PR 侧会丢掉 master 的 Zero-Inheritance Session Cloning: Unified Fix for Eight Independent Defects in the Fork Adoption Chain (Next Release Tar | 会话克隆零继承:fork 收养链上八类独立缺陷统一修复(下版目标) #4266/# Cache hit collapses to 1–12% for a whole generation, then the very next request returns to 100% — repeated 15× in one day #5608 测试更新(本地实测 2 个测试因此红,已按并集修正后 58/58 全绿);其余文件无冲突、自动合并;typecheck + build + 定向套件全绿。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:不涉及(纯同步合并,无新代码)。
  8. 是否引入新配置:无。

判定:冲突已解除,新 head 8a14505d4f 已推送,等 CI 对 new head 跑完即可(镜像缓存自 10-31 起冻结,本 run 无法确认 new head 红绿,不猜测)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

Verdict: APPROVE (at head 8a14505d4f, reviewed independently against PR body + issue #5001 + full diff vs true master c26c31ace4)

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 fetchManifest() racing the hook-spawned proxy — the fix removes that mechanism (bounded wait for readiness) at the right layer, and polling keeps the proxy's manifest as the single source of truth (better than the reporter's static-manifest alternative).

Regression audit (②) — existing behaviors on the touched paths, item by item:

  • Warm path: success branch byte-identical, single attempt, no re-poll (pinned by test) — preserved.
  • Degraded mode: still returns {tools: []} before ensureManifest — preserved.
  • tools/call / forwardTool, initialize, notifications/initialized: untouched — preserved.
  • manifestPromise cache semantics (shared promise, reset on failure): unchanged — preserved.
  • manifestMaxToolDurationMs learning ([Bug][dsh] plugin-tool bridge hard-codes a 60s timeout that contradicts the configurable externalSummary.budget — long summaries die with "timeout after 60000ms" #2652): same code, same effect — preserved.
  • Error path: old = immediate -32003 (1 attempt, ≤5s) → new = bounded wait (15s budget, 3s per attempt) then -32003, text now reads "even after waiting for a cold start". Disclosed in the PR body; intentional; still fails loudly (no fail-fast→swallow).
  • Success response {tools: [...]} byte-identical — no wire-shape change.

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), throw lastErr only reachable after ≥1 failure, bounded worst case (15s budget + one in-flight 3s fetch). ensureManifest export + _resetMcpManifestForTest seam follow the house pattern (_resetSessionsForTest et al.); the seam resets all mutable state incl. budget overrides (no cross-test leak). Local sleepMs matches the src/restart.ts:144 pattern. No as any / @ts-ignore / console.error.

Tests (④): tests/issue5001-mcp-cold-start.test.ts pins all four directions with a mocked fetch — cold recovery (the regression pin: the old single-shot fetch would reject on attempt one), warm single attempt (no re-poll), 503 retried, dead proxy bounded (elapsed < 5s with a 400ms budget, ≥2 calls). Assertions have teeth (call counts + elapsed bounds); deterministic (no real ports — the BILI_MCP_PROXY pin short-circuits resolveProxyOrigin at src/mcp.ts:65-67; sub-millisecond cadence). Style matches the closest sibling (issue1875). The plugin-fork #5140 dual-mode loop pins the storage mode explicitly (fixes the ambient-legacy-baseline CI flake) and adds shadow coverage — a strict superset of the old single-full test. The fork-replica-convergence keep-alive pin uses the existing documented knob BILI_KEEP_ALIVE_TIMEOUT_MS (src/knobs.ts:209-211, default 5000) scoped to the test process — no production default touched.

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 8a14505d4f (mirror cache 2026-11-12T03:48Z: 16 success, 14 skipped, 0 failed, 0 pending).

No small findings to fix on the spot. No kernel/ touch, no kernel-change: declaration → the human kernel tier does not gate this.

八问

  1. 是什么问题:按消息型宿主(CloudCLI)每条消息新起 claude.exe,SessionStart hook 在独立子进程拉起 proxy(2.3–3.6s 才监听),MCP shim 几乎立即发 tools/list;旧代码单次 fetch 遇 ECONNREFUSED 即终态回 -32003,Claude Code 重试预算(~1.75s)耗尽后整进程放弃 → bili 工具从未注册,模型调 compress 全部 No such tool available。
  2. 什么原因导致的:shim 与 proxy 是两个子进程的启动时序竞态,叠加 fetchManifest() 把「首次连接被拒」当终态——缺的是有界等待语义,不是网络本身的问题。
  3. 影响范围与严重程度:「tools/list 到达时 proxy 未监听」的窗口内触发;按消息重启的宿主几乎每会话中招(压缩能力整体停摆,会话本身仍可用);长驻宿主仅首进程受影响。报告者数据 warm 18/18、cold 2/54。
  4. 怎么修复的:fetchManifest() 从单次尝试改为有界轮询(15s 预算 / 250ms 间隔 / 单次 3s 超时);暖 proxy 首试即返回零附加延迟;非 ok 状态(503)重试不当终态;死 proxy 到点回 -32003 不挂死;并发 tools/list 共享同一轮询(manifestPromise 语义不变)。改在共享 shim,claude/codex/zcode 等所有 runMcpStdio 车道继承;degraded 模式在 ensureManifest 之前返回,不受影响。
  5. 是否有回归问题:逐项审过——暖路径字节级不变;degraded 模式不变;tools/call/initialize 未触碰;manifestPromise 缓存语义不变;[Bug][dsh] plugin-tool bridge hard-codes a 60s timeout that contradicts the configurable externalSummary.budget — long summaries die with "timeout after 60000ms" #2652 预算学习不变;错误面旧=立即 -32003 → 新=最多等 15s 后 -32003(PR 已披露,有意变更,仍 fail-loud 不吞错);成功响应字节级一致,无 wire 形状变化。无 fail-fast 变吞错、无语义漂移、无阈值漂移超出已披露范围。
  6. 是否破坏缓存:不涉及——不碰前缀缓存、ref/账本、重试游标、去重键。
  7. 是否改了设计方向:没有——仍是「hook 拉 proxy、shim 供工具」的分工,只是 shim 侧「等不到就放弃」改为「有界地等」;轮询保留 proxy manifest 单一事实来源(优于静态 manifest 方案)。
  8. 是否引入新配置:无——等待预算是模块常量(DEFAULT_MANIFEST_WAIT_MAX_MS 等),非 env/config/CLI,符合 env 稀缺纪律;测试 seam 是导出函数不是配置项。

判定:可合(CI 全绿、无回归、无小修项;按 §7.4 因默认时序变更归人工合并,不走 auto-merge)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

1 similar comment
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

1 participant