Repository navigation
feat(adapters): codex-recovery-proxy — mneme's first host adapter - #9
Merged
Merged
Conversation
Adds `adapters/codex-recovery-proxy/`: a stdio↔Streamable-HTTP shim that lets Codex Desktop keep using mneme through the known MCP session wedge bug ([openai/codex#32470](openai/codex#32470)). Problem ------- Codex Desktop's Streamable HTTP MCP client can lose a `completion` event after a tool call. Once that happens, every subsequent call on that long-lived session hangs forever (no timeout, no error). mneme itself is healthy — the failure is entirely on codex's completion-tracking layer — but the user sees "mneme is dead" until they restart the codex task. Fix (in the adapter, not in mneme server) ----------------------------------------- Do not patch codex (upstream will). Instead, keep the bug from propagating: - Codex sees a normal stdio MCP server (`chinatsu-memory`). - Internally the proxy opens a **fresh Streamable HTTP session** for every `tools/list` and every `tools/call`, DELETEs the session as soon as the call completes, and enforces a bounded per-call timeout. - Tool calls are **never automatically retried** — at-most-once semantics are preserved so a lost response cannot become a duplicate `store_memory` write. - `Authorization: Bearer <token>` is forwarded per-call unmodified; the mneme server sees an identical bearer to direct-connect. Result: a single wedged call pollutes only that call. The next call opens a brand-new session and is unaffected. Adapter charter --------------- - Only host-specific glue (`adapters/<host-name>/`). Never modifies mneme server code. - Independent README explains: which upstream bug, how to install, when to archive. - When upstream fixes the wedge and stabilises, this adapter can be archived (kept for future reference) and codex reconfigured to talk to mneme HTTP directly. Files ----- - `adapters/codex-recovery-proxy/proxy.mjs` (~245 lines) — the stdio↔HTTP shim. Boot-time refuses C0/DEL bytes in the bearer (blocks CRLF / ANSI-escape smuggling into stderr or on-wire headers). `safeError()` redacts the token from every error string before it reaches stderr; `redactMcpError()` rebuilds server-side JSON-RPC errors with redacted message + data before rethrow so a bearer-echoing auth layer cannot leak into the JSON-RPC envelope codex sees. `tools/list` and `tools/call` both wrapped in try/catch. Server-side JSON-RPC McpError code+data preserved (method-not-found, invalid-params, auth failure); transport-layer failures (ConnectionClosed -32000, RequestTimeout -32001) flatten to `isError` so at-most-once retry stays intact. The transport-code set is documented as a today-observation, not a protocol invariant. - `adapters/codex-recovery-proxy/proxy.test.mjs` (~305 lines) — three scenarios: 1. 60-shot fault-injection matrix: fresh sessions per call, hanging tool call must isolate, subsequent calls must succeed, no session leak on the remote, no retry on failure. 2. Connect-leg hang: a remote that accepts TCP but never writes anything — proves the `client.connect()` / initialize-leg timeout surfaces an error to codex within the configured window. 3. Post-init hang: a remote that answers initialize normally then stalls every subsequent JSON-RPC request. This is the exact shape of upstream codex#32470 — session establishes fine, later call wedges. Proves the tools/list / tools/call timeout path works, not just the initialize leg. - `adapters/codex-recovery-proxy/smoke.mjs` — real-mneme end-to-end smoke that also checks for remote session leak via `/health`. - `adapters/codex-recovery-proxy/README.md` — install, config, archive plan. - `.github/workflows/ci.yml` — new step runs the adapter's three-scenario test alongside the existing mneme test suite. Fanout self-review — two rounds -------------------------------- Round 1 on a personal fork (MXAntian/mneme#1, closed as wrong-target). Surfaced 5 P1 findings, all folded in before opening here: README false claims about source_host/quarantine dropped (concepts that live in an unmerged private mneme branch, not OSS mneme); bearer redaction in safeError() + control-char guard at boot; tools/list wrapped in try/catch; McpError shape preserved for server-side errors; CI step added; hanging-remote test added. Round 2 on this org PR. Surfaced 2 P0 + 2 P1 + 3 P2 — all P0/P1 folded in as part of this commit: - P0-1: README table description still contained "source_host" residual from the same drift pattern round 1 caught. grep -r source_host now returns zero hits. - P0-2: `throw error` on the "preserve server-side McpError" path was bypassing safeError() redaction. If a server auth layer ever echoed the Authorization header into an McpError.message or .data, the bearer would reach codex. redactMcpError() now rebuilds message + data through the same redact() pipeline before rethrow. - P1-3: {-32000, -32001} carve-out was comment-asserted as a protocol invariant. It's a today-observation about SDK-only usage; those codes sit in JSON-RPC's Server-error reserved range and a future server could legitimately use them. Comment now says so + notes the caveat. - P1-4: Original hanging-remote test only covered the connect() leg because withFreshRemote runs connect() before operation() — under that server, the initialize POST stalls first and operation() is never reached. Added scenario 3 above. - P2-2 (opportunistic): control-char guard widened from /[\r\n\x00]/ to /[\x00-\x1f\x7f]/, blocking ANSI ESC and the rest of C0. Verified locally after each round: - proxy.test.mjs: PASS fresh sessions=60, calls=59, live sessions=0 - proxy.test.mjs: PASS hanging remote surfaced error in ~680ms (<3000ms) - proxy.test.mjs: PASS post-init hang surfaced error in ~445ms (<3000ms, sessions established=1) - smoke.mjs vs real [email protected]:18792: active_sessions 0 → 0 [prediction] 修复: codex Desktop 遇到 mneme MCP session wedge 时不再永久 失效;用户体感"mneme 挂了"从"重启 codex task"降级为"下次调用自动是新 session";at-most-once + JSON-RPC 错误 shape 保留 + bearer 不进任何输出 路径(stderr / JSON-RPC error envelope 都覆盖) [prediction] 风险: TRANSPORT_ERROR_CODES 硬编码 -32000/-32001。若 SDK 或未来的 server 在 -32099..-32000 范围加新 error code,会被错误分类 为 transport 层失败。文件属 adapter scope,mneme server 侧不受影响 [prediction] 验证: CI 跑 adapters/codex-recovery-proxy/proxy.test.mjs 三 个 PASS 行;codex 侧下次真遇到 mneme 短时不可达时看 codex UI 报 "tool failed" 而不是"MCP error -32001" Co-Authored-By: Claude Opus 4.7 <[email protected]>
MXAntian
force-pushed
the
codex-recovery-proxy-for-org
branch
from
July 21, 2026 11:12
04e155d to
89902ef
Compare
MXAntian
marked this pull request as ready for review
July 21, 2026 11:13
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.
Summary
Adds
adapters/codex-recovery-proxy/: a stdio↔Streamable-HTTP shim that lets Codex Desktop keep using mneme through the known upstream MCP session wedge bug (openai/codex#32470).Problem. Codex Desktop's Streamable HTTP MCP client can lose a
completionevent after a tool call. Once that happens, every subsequent call on that long-lived session hangs forever (no timeout, no error). mneme itself is healthy — the failure is entirely on codex's completion-tracking layer — but the user sees "mneme is dead" until they restart the codex task.Fix (in the adapter, not in mneme server). Codex sees a normal stdio MCP server (
chinatsu-memory). Internally the proxy opens a fresh Streamable HTTP session for everytools/listand everytools/call, DELETEs the session as soon as the call completes, and enforces a bounded per-call timeout. Tool calls are never automatically retried — at-most-once semantics preserved so a lost response cannot become a duplicatestore_memorywrite.Adapter charter (new pattern for the repo)
adapters/<host-name>/= host-specific glue only. Never modifies mneme server code.Files
adapters/codex-recovery-proxy/proxy.mjs(~245 lines) — the stdio↔HTTP shimadapters/codex-recovery-proxy/proxy.test.mjs(~305 lines) — 60-shot fault matrix + connect-leg hang + post-init hangadapters/codex-recovery-proxy/smoke.mjs— real-mneme end-to-end +/healthsession-leak checkadapters/codex-recovery-proxy/README.md— install, config, archive plan.github/workflows/ci.yml— new step wires the three-scenario matrix into CISecurity / correctness notes
safeError()redacts the token from any error text before it reaches stderr.redactMcpError()rebuilds server-side JSON-RPCMcpErrorwith redactedmessage+databefore rethrow, so a bearer-echoing server auth layer cannot leak into the JSON-RPC envelope codex sees.tools/listandtools/callwrapped in try/catch — no transport throw can wedge the proxy loop.McpErrorcode+data preserved (method-not-found, invalid-params, auth failure). Transport-layer failures (ConnectionClosed -32000, RequestTimeout -32001) flatten toisErrorso at-most-once retry semantics stay intact. The transport-code set is documented as a today-observation, not a protocol invariant — those codes sit inside JSON-RPC's Server-error reserved range and a future server could technically use them.Authorization: Bearer <token>is forwarded — no additional headers, no caching, no rewriting.Test plan
proxy.test.mjsscenario 1: PASSfresh sessions=60, calls=59, live sessions=0(60 tool calls across 60 fresh HTTP sessions; thehangtool call yieldsisError: trueand does not poison the next call; 8 concurrent calls all succeed on distinct sessions)proxy.test.mjsscenario 2: PASShanging remote surfaced error in ~680ms (<3000ms ceiling)— proves the connect() / initialize-leg timeoutproxy.test.mjsscenario 3: PASSpost-init hang surfaced error in ~445ms (<3000ms ceiling, sessions established=1)— proves the tools/list / tools/call timeout leg (exact shape of upstream codex#32470)smoke.mjsvs real mneme@127.0.0.1:18792:active_sessions 0 → 0(no session leak)node --checkon both.mjsfilesNot in this PR
index.mjs,mcp-server.mjs, migrations).@modelcontextprotocol/sdkwhich is already a prod dep).Review history (fanout status)
Round 1 on a personal fork (MXAntian/mneme#1, closed as wrong-target). Surfaced 5 P1 findings, all folded in before opening here.
Round 2 on this org PR (independent claude pass, source-traced against actual SDK internals in
node_modulesrather than trusting comments). Surfaced 2 P0 + 2 P1 + 3 P2:grep -r source_hostnow returns zero hits.throw erroron the "preserve server-side McpError" path bypassed safeError() redaction. If a server auth layer ever put the bearer into anMcpError.message/data, it would leak to codex uncensored.redactMcpError()— rebuilds the error with redactedmessage+databefore rethrow.\r\n\x00, not the rest of C0.[\x00-\x1f\x7f].P2-1 (fallback error text imprecise for Zod schema-reject sub-case) and P2-3 (no repo-wide lint enforcing "adapters/** never touches mneme server code") acknowledged but out of scope for this PR.
🤖 Generated with Claude Code