Repository navigation
fix: consume Codex per-call _meta.threadId in the MCP shim (#2024) - #2026
Conversation
Codex >=0.160 stamps the real thread id on every tools/call via _meta.threadId (codex-rs core/src/mcp_tool_call.rs with_mcp_tool_call_ids_meta; its sessionId is a transient run id and is deliberately not consumed). The shim ignored it and kept routing through the stale BILI_CONVERSATION_ID baked into the generated MCP config, so Code Mode compress calls failed with 'unknown plugin conversation'. - src/mcp.ts: consume strictly-validated per-call _meta.threadId (non-empty string after trim; malformed/absent metadata leaves the legacy channels untouched), per call only — never written back to the global binding; flag host-stamped origin as nativeCaller in the POST body; extend the #841 search-target exception so a native caller keeps args.conversation_id read-only even without a default binding. - src/plugin.ts: routing ladder rung 0 — a host-stamped nativeCaller outranks a conflicting unique outbound witness (a collision, not truth); unmarked ids keep the exact #1685 precedence; an unresolvable native id fails loudly (404 + #1158 diagnostic) with no witness rescue and no sibling adoption. - tests/mcp-native-thread.test.ts: shim contract against a mock proxy capturing POST bodies, proxy routing policy on a real startServer, and the incident-shape e2e leg (real server + real shim over stdio, interleaved main/child threads). - CLIENTS.md / CLIENTS.zh-CN.md: document the new channel for codex.
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2060-pr.2026.346d089This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2026.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 已完成开发并提 PR:**https://github.com/ranxianglei/billion-context/pull/2027**(Closes #2024)。分支 结构化七问
判定:可合并。PR #2027 已开(base=master |
What & why
Codex ≥0.160 stamps the real thread id on every
tools/callvia_meta.threadId(codex-rs core/src/mcp_tool_call.rswith_mcp_tool_call_ids_meta; itssessionIdis a transient run id and is deliberately NOT consumed). The MCP shim ignored it entirely and kept routing through the staleBILI_CONVERSATION_IDbaked into the generated Codex MCP config — so in Code Mode (where the inner compress call never appears as an independent upstreamfunction_call, hence no outbound witness either) every compress/decompress/status/cache/search call failed withunknown plugin conversation. Incident evidence + reproducible PoC: #2024.Fix at the shared tool entry (all five tools), not a compress special-case:
src/mcp.ts— consume strictly-validated per-call_meta.threadId(non-empty string after trim; anything else is treated as ABSENT so malformed metadata can never shadow the legacy channels). Per-call only: never written back to the shim's globalconversationId(main/sub-agent threads sharing one MCP process must not clobber each other's binding). The host-stamped origin is flagged to the proxy asnativeCallerin the POST body. The feat: 支持search_context显式查询历史 session #841 search-target exception is extended so a native caller keepsargs.conversation_idas a read-only cross-session target even when NO default binding exists (previously the target would have been mistaken for the caller).src/plugin.ts— routing ladder gains rung 0: a host-stampednativeCalleroutranks a conflicting unique outbound witness (a collision, not truth — the issue's explicit boundary). Unmarked ids keep the exact 零注入会话身份:移除模型可见 conversation_id,以出站 tool_use 环见证路由 MCP 工具调用(fixes #1611 的非注入路线) #1685 precedence (witness still beats model-transcribed/static ids — flipping that would regress stale-model-id cases). An unresolvable native id fails loudly (404 + 方式一安装的dsh 原生插件:llm-pi-ai 传输(OpenAI SDK + options.fetch 注入)绕过 globalThis.fetch 拦截,模型请求不进代理、压缩完全不生效 #1158 diagnostic) — no witness rescue, no sibling adoption.tests/mcp-native-thread.test.ts— three layers: shim contract (realsrc/mcp.tsover stdio against a mock proxy capturing the exact POST bodies), proxy routing policy (realstartServer: native-vs-conflicting-witness, unmarked-control, loud-failure legs), and the incident-shape e2e leg (real server + real shim over stdio with a stale env id, interleaved main/child threads, meta-less call still failing against the untouched residue).CLIENTS.md/CLIENTS.zh-CN.md— document the new channel for codex (zh/en synced).Behavior changes (old → new, all intentional)
nativeCalleronPOST /__bili/plugin/tool— set ONLY by the MCP shim and ONLY when the id came from_meta.threadId. Old proxies ignore the unknown field; old shims never send it. Not a config surface (no env/config.json/CLI changes).search_contextwithout any default binding + valid_meta.threadId: before,args.conversation_idwas the routing fallback (then stripped); now the call routes to the native thread and the target stays read-only in args. Only affects hosts sending Codex-style per-call metadata (new capability); legacy hosts unchanged.warnlog line on a witness/native conflict; execution log can now readrouted by native.Verification
38536f4c: reproduced — "published bridge ignores native threadId" (5/5 baseline checks show the stale-env failure shape); after the fix the PoC trips its ownPublished bridge changedguard, as designed.npm run typecheckclean.tests/mcp-native-thread.test.ts8/8; neighbors 67/67 (e2e-plugin-tool-routingtest: e2e the #1685 plugin tool routing ladder + MCP shim lane #1773,issue760-percall-conversation,search-context-cross-session,tool-ring,tool-witness-pipes,plugin-protocol,zcode-mcp-degraded).dist/mcp.jsover stdio routes_meta.threadIdnatively and keeps the legacy env binding when meta is absent (2/2).Closes #2024