Repository navigation
fix: consume Codex per-call _meta.threadId in the MCP shim (#2024) - #2027
Closed
ranxianglei wants to merge 1 commit into
Closed
ranxianglei wants to merge 1 commit into
ranxianglei wants to merge 1 commit into
Conversation
Codex >=0.160 stamps the real thread id on every MCP tools/call via _meta.threadId; the shim ignored it and kept routing through the stale BILI_CONVERSATION_ID baked into the generated config, so in Code Mode (no outbound witness) every tool call failed with 'unknown plugin conversation'. mcp.ts: strictly validate per-call _meta.threadId (malformed => absent), apply per-call only (never overwrite the shared binding), flag host-stamped calls as nativeCaller. Extend the #841 search-target exception so a native caller keeps args.conversation_id read-only even without a default binding. plugin.ts: routing ladder gains rung 0 — a flagged nativeCaller outranks a conflicting unique outbound witness; unmarked calls keep exact #1685 precedence. Unresolvable native id fails loudly (no witness rescue/adoption). tests/mcp-native-thread.test.ts: shim contract + proxy policy + incident e2e. CLIENTS.md/CLIENTS.zh-CN.md: document the channel (zh/en synced).
Contributor
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2061-pr.2027.32bd87bThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2027.tgz
npm install -g packageInstall instructions are refreshed on each push. |
This was referenced Nov 18, 2026
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.
Closes #2024
What & why
Codex >=0.160 stamps the REAL thread id on every MCP
tools/callvia_meta.threadId(codex-rscore/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.The fix lands at the SHARED tool entry (all five tools), not a compress special-case.
Changes
src/mcp.ts — consume strictly-validated per-call
_meta.threadId(non-empty string after trim; anything else treated as ABSENT so malformed metadata can never shadow the legacy env/meta/per-call channels). Applied 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). Host-stamped calls are flagged to the proxy asnativeCallerin the POST body. The #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.src/plugin.ts — the routing ladder gains rung 0: a host-stamped
nativeCalleroutranks a conflicting unique outbound witness (a collision, not truth — the explicit boundary in #2024). Unmarked ids keep the exact #1685 precedence (witness still beats model-transcribed/static ids). An unresolvable native id fails loudly (404 + #1158 diagnostic) — no witness rescue, no sibling adoption.tests/mcp-native-thread.test.ts — three layers: (1) shim contract (real
src/mcp.tsover stdio against a mock proxy capturing the exact POST bodies); (2) proxy routing policy (realstartServer: native-vs-conflicting-witness, unmarked-control, loud-failure legs); (3) 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.search_contextwithout a 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; the execution log can now readrouted by native.Config surface
None changed.
nativeCalleris a wire field set only by the MCP shim — no new env var, noconfig.jsonfield, no CLI flag.Verification
npm run typecheckclean.tests/mcp-native-thread.test.ts: 7/7 pass.npm run buildsuccess.ec95a6d4) before running these checks; full-suite regression left to CI.