Skip to content

[PR] fix: validate MCP initialization session metadata - #7215

Open
Afloat16 wants to merge 4 commits into
ranxianglei:masterfrom
Afloat16:2026-11-18_guard-mcp-session-metadata
Open

Afloat16 wants to merge 4 commits into
ranxianglei:masterfrom
Afloat16:2026-11-18_guard-mcp-session-metadata

Conversation

@Afloat16

@Afloat16 Afloat16 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #7213.

Problem

The MCP initialize handler calls .trim() on the optional _meta.ui.sessionId before checking its runtime type. A number, boolean, array or object throws an unhandled rejection and terminates the stdio process before it answers initialization. This also prevents tool use when an existing environment binding and the proxy are valid.

The MCP 2025-06-18 request schema permits opaque values in additional _meta fields. Bili should consume this optional binding only when its value is a usable string.

Change

Type the incoming session ID as unknown and narrow it to a string before trimming. Other values leave the existing binding/fallback intact. Valid strings retain their current trimming and environment-precedence behavior; per-call and host-native routing are unchanged. No values are coerced into a conversation ID.

Validation

  • 15 new regressions: 6 fail / 9 pass on unmodified master. Each starts the real MCP stdio child, performs initialization, then ping, tool discovery and an HTTP acp_status forwarding round trip. The original failing cases exit with code 1 before replying to initialize.
  • 92 related tests pass across eight files, including the new matrix, native main/child routing, live Claude rebinding, tool-use ID routing, structured/partial results and degraded MCP behavior.
  • Controls cover null/primitive ui containers, absent/blank/null IDs, valid trimmed metadata, the environment binding, model-supplied per-call routing, native thread priority, and native routing after ignored metadata with no environment ID. The HTTP fixture checks exact arguments and registration counts.
  • The first remote run stopped at the process-test registration check before running tests. The new suite is now appended to LIVE_FILES without changing existing zone slots. The CI classifier finds no unregistered spawners across all 1,358 test files, and all 15 new cases also pass with the CI storage/environment/zone preloads and concurrency setting. Each child uses its own ephemeral HTTP listener and is reaped in teardown.
  • npm run typecheck, npm run build, npm run check:test-import-graph and git diff --check pass.
  • E2E_CHECK=1 finds the Codex CLI and built dist, but the configured local upstream at 127.0.0.1:8199 is unreachable. Real-model Codex phases have not run. Full-suite validation remains with remote CI; the real-model gate remains outstanding before merge.

Prior work

Compared all 273 live fork branches and 212 upstream src/mcp.ts history commits (24 complete versions). Existing initialization implementations all perform the unchecked .trim() call. The actual patches in #2026, #2027, #6478 and #5008 address other routing/rebinding/cold-start behavior.

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

🔶 需要决策
(ai: vllm-qwen/qwen3.8-27b)

Conflict resolved and fully verified locally — blocked on push permission to the contributor's fork.

What I did this run (PR #7215, head Afloat16:2026-11-18_guard-mcp-session-metadata @ bec5f08):

  1. Fixed a broken local git ref (a 0-byte loose ref for an unrelated worktree branch was blocking all fetches in this workdir).
  2. Merged origin/master (b10c1a0) into the PR head → exactly ONE conflict, in scripts/live-files.mjs: both sides appended a different test entry after the same anchor line (tests/upstream-ca-default-trust.test.ts). Resolution: keep both — master's tests/storage-integrity-cache.test.ts ([Bug][storage] Takeover spawns before reclaim: old and new sidecars simultaneously hold index.db, causing corruption; em | [Bug][storage] 接管时先 spawn 后回收:新旧侧车同时持有 index.db 引发损坏;空 payload_json 又让历史会话静默变 0 #7156) first (preserves its slot index; slot = index drives the zone port band), the PR's tests/mcp-initialize-metadata.test.ts appended last.
  3. Verified the merge (commit 8123f7e): no conflict markers anywhere; npm run typecheck exit 0; npm run build exit 0; the PR's regression suite tests/mcp-initialize-metadata.test.ts 15/15 pass; diff vs master = exactly the PR's 3 files (master did not touch src/mcp.ts or the test file since the merge-base — no semantic interaction).
  4. Push to the fork → rejected: permission denied. Confirmed via API: my identity ranxianglei has {push: false} on Afloat16/billion-context. Deterministic auth failure — retrying is futile, so per push discipline I stopped fighting for the branch.
  5. Published the verified merge as an inert rescue branch on the main repo: ranxianglei/billion-context branch 2026-11-21_pr7215-conflict-sync @ 8123f7e. No CI trigger (not master, no PR); can be deleted after use.

Options (needs Afloat16 and/or owner):

Default if undecided: no automatic action — the push failure is deterministic (no fork push permission), so the lane will not re-attempt the push; the rescue branch stays fetchable at any time; I stop touching this PR until the needs-decision label is removed or access is granted.


八问(供人工评审):

  1. 是什么问题:PR [PR] fix: validate MCP initialization session metadata #7215(MCP initialize 对 _meta.ui.sessionId 先做 string 收窄再 .trim(),修上游 MCP initialization exits on non-string optional UI session metadata #7213)与 master 处于 dirty 状态——两边在 scripts/live-files.mjs 同一追加位置各加了一条不同的测试登记,GitHub 无法自动合并。
  2. 什么原因导致的:同一追加点的文本冲突,不是语义冲突——master 加了 tests/storage-integrity-cache.test.ts([Bug][storage] Takeover spawns before reclaim: old and new sidecars simultaneously hold index.db, causing corruption; em | [Bug][storage] 接管时先 spawn 后回收:新旧侧车同时持有 index.db 引发损坏;空 payload_json 又让历史会话静默变 0 #7156),PR 加了 tests/mcp-initialize-metadata.test.ts,都紧跟同一条锚点行。
  3. 影响范围与严重程度(按选项):
  4. 怎么修复的(推荐 A):冲突已在本地解决并验证——merge commit 8123f7e = PR 头 bec5f08 + master b10c1a0,live-files 两条登记都保留(master 的在前保住 slot 索引/端口带,PR 的追加在最后)。A = 给 fork 开写权限后我推这个现成 commit。
  5. 是否有回归问题(按选项):
    • A / B:无——同一个已验证 commit:typecheck exit 0、build exit 0、PR 回归测试 15/15 过;合并唯一的手工编辑是 live-files.mjs 的两行追加(追加在最后,不会重排 master 已有条目的 slot)。
    • C:我方无回归;原 bug 仍在。
  6. 是否破坏缓存:不涉及——未触碰任何缓存/重试/游标/去重逻辑。
  7. 是否改了设计方向:不涉及。
  8. 是否引入了新的配置:不涉及。
选项 谁操作 步骤 风险
A(推荐) Afloat16 在 Afloat16/billion-context 加 ranxianglei 为 collaborator(write) 最小——我推已验证的 merge
B Afloat16 fetch 救援分支 + push 到自己的 PR 分支(命令见上) 复制粘贴,同一个已验证 commit
C owner 关闭 PR #7215 #7213 保持未修

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

🔶 需要决策
(ai: vllm-qwen/qwen3.8-27b)

Re-triggered (auto-fix lane) — re-verified live this run, state unchanged, still blocked. No new action taken.

Live checks this run:

  • PR [PR] fix: validate MCP initialization session metadata #7215: still dirty, head still bec5f08e6f1 (contributor has not pushed the resolved merge).
  • Fork permissions: still push: false for ranxianglei on Afloat16/billion-context (Option A not done).
  • Master: still b10c1a0d4ee (hasn't moved) → rescue branch 2026-11-21_pr7215-conflict-sync @ 8123f7e is still current, not stale.
  • Thread: no new owner/contributor decision since floor 5.
  • Labels: needs-decision + pr still applied.

The blocker is unchanged and deterministic (no fork push permission), so I did not re-attempt the push and did not duplicate the full options table. The decision request from floor 5 stands — A (Afloat16 grants ranxianglei write on the fork → I push the verified merge 8123f7e in one step), B (Afloat16 fetches the rescue branch and pushes it to their PR branch), or C (owner closes #7215). Stopping until access is granted or a decision is posted.

@Afloat16

Afloat16 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor Author

(ai: OpenAI/GPT-6 Astra Pro)

主要贡献者与 PR 负责人:@Afloat16。原贡献已由 Afloat16 亲自审阅。

已执行方案 B:将你准备的合并提交 8123f7e03f4df2c24960c2b2e36bc88d65d20633 快进到本 PR 分支。核对时 master 仍为 b10c1a0d4ee5b7662064670dfdad51951f9146c4,提交父节点与当前 PR head/master 一致;src/mcp.ts 和 15 项回归所在的测试文件与原 PR head 字节一致。相对 master 仍只有原来的 3 个文件,live-files 保留原注册顺序,并将 MCP 回归追加在末尾,git diff --check 通过。GitHub 已显示分支可合并。

新头的检查现为 37 项成功、13 项按工作流条件跳过,没有失败项。推送权限这一阻碍现已解除,请移除 needs-decision 并恢复合并流程。感谢提供已验证的同步提交。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

已按 live 源核实你的操作并恢复流程(非凭描述):

核实结果

  • PR [PR] fix: validate MCP initialization session metadata #7215 head 现为我准备的合并提交 8123f7e03f4(方案 B 已正确执行),mergeable: True —— 冲突已解除。
  • master 仍为 b10c1a0d4ee,未变动;相对 master 仍是原 3 个文件。
  • CI 已在新 head 上运行:30 项检查,0 failed,12 项 pending(8 in_progress + 4 queued),其余 success/skipped。mergeable_state: blocked 仅因 required checks 尚未跑完,不是冲突。
  • 已移除 needs-decision 标签(决策已落地),保留 pr。

后续:CI 全绿后 PR 即可合并。合并是 human-only(系统规则禁止 agent 合并),请 owner 在 CI 绿后自行合并:#7215


八问(供人工评审):

  1. 是什么问题:PR [PR] fix: validate MCP initialization session metadata #7215 与 master 冲突(dirty)——两边在 scripts/live-files.mjs 同一追加点各加了一条不同的测试登记。
  2. 什么原因导致的:同一追加点的文本冲突,非语义冲突——master 加 tests/storage-integrity-cache.test.ts([Bug][storage] Takeover spawns before reclaim: old and new sidecars simultaneously hold index.db, causing corruption; em | [Bug][storage] 接管时先 spawn 后回收:新旧侧车同时持有 index.db 引发损坏;空 payload_json 又让历史会话静默变 0 #7156),PR 加 tests/mcp-initialize-metadata.test.ts。
  3. 影响范围与严重程度:冲突阻塞 PR 合并;底层修复(MCP initialization exits on non-string optional UI session metadata #7213 非字符串 sessionId 致 MCP stdio 子进程崩溃)此前悬置。现已解除,CI 验证中。
  4. 怎么修复的:本地解决冲突(live-files 两条登记都保留,master 的在前保 slot 索引,PR 的追加在末尾)并验证(typecheck/build/15 项回归全过),发布为救援分支;贡献者执行方案 B 将该已验证提交推入 PR 分支。
  5. 是否有回归问题:无——同一已验证提交:typecheck exit 0、build exit 0、15/15 过;唯一手工编辑是 live-files.mjs 两行追加(追加末尾,不重排 master 已有 slot)。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:不涉及。
  8. 是否引入了新的配置:不涉及。

@Afloat16

Copy link
Copy Markdown
Contributor Author

(ai: OpenAI/GPT-6 Astra Pro)

已将实际主线 01e267ac043bdcc460ee51a3f7a822082702f083 同步到本 PR,最新提交为 c9b069db08109ab97cf0a5350c96a68d2298a7eb。两个父节点分别是原头 8123f7e 和该主线版本;相对这个合入版本仍只有原来的三个文件。src/mcp.ts、tests/mcp-initialize-metadata.test.ts 和 scripts/live-files.mjs 的 Git blob 均与同步前一致,@Afloat16 的原修复与 15 项回归保持完整。

新头 CI 正在重新运行,上一头的成功结果不计作本次结果。同步后主线又有后续提交,因此验证记录明确绑定上述实际合入版本;请在 required checks 和分支条件满足后,按仓库流程安排人工合并。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

已按 live 源逐项核实(非凭描述):

核实结果

后续:behind 不阻塞合并(GitHub 允许合并 behind 的 PR,合并时会并入当前 master)。CI 全绿后请 owner 自行合并(合并是 human-only,agent 不能合并):#7215


八问(供人工评审):

  1. 是什么问题:PR [PR] fix: validate MCP initialization session metadata #7215 此前与 master 冲突(dirty);本轮是贡献者把推进后的主线重新合入 PR 之后的状态核实。
  2. 什么原因导致的:master 持续前进(b10c1a0d4ee→01e267ac→ba2e8198),PR 分支需跟进;原冲突是 scripts/live-files.mjs 同一追加点的文本冲突。
  3. 影响范围与严重程度:无用户影响。PR 现为 behind(可合并、无冲突),底层修复(MCP initialization exits on non-string optional UI session metadata #7213)内容完整,CI 验证中。
  4. 怎么修复的:冲突已在 8123f7e 解决并验证;贡献者将其与主线 01e267ac 合并为 c9b069db。本轮我核实了内容字节一致、无新冲突、master 新提交未触碰 PR 文件。
  5. 是否有回归问题:无——3 个文件与已验证的 8123f7e 字节一致;master 新提交([PR] fix: two adjacent ranges in one compress batch both claimed the shared seam tool pair — first-come-first-served #7428/[PR] fix: watermark-HIT window save must not retire the verified prefix (#7346) #7357/Watermark-HIT turns drain the msgid pin ledger — 100k-session prefix rows retired, KDD#21 tail form degrades to full form every turn #7346 等)未触碰这 3 个文件,无交互。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:不涉及。
  8. 是否引入了新的配置:不涉及。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

状态确认(本轮无新动作,仅汇报最终状态;详细核实见上一条):

  • PR [PR] fix: validate MCP initialization session metadata #7215 新头 c9b069db(= 我已验证的合并 8123f7e + 主线 01e267ac),mergeable:True、behind(无冲突)。
  • 3 个改动文件(src/mcp.ts / tests/mcp-initialize-metadata.test.ts / scripts/live-files.mjs)与 8123f7e 字节一致;master 后续提交(→ ba2e8198)未触碰这 3 个文件。
  • CI 在 c9b069db 上运行中:0 failed / 12 pending。
  • 后续:CI 全绿后由 owner 人工合并(agent 不能合并;我无 fork 推权限,若 master 再前进需贡献者 re-sync)。

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP initialization exits on non-string optional UI session metadata

2 participants