Repository navigation
fix(mcp): guard stdio stdout frame parsing against oversized-buffer crash - #119379
Conversation
|
Codex review: needs maintainer review before merge. Reviewed August 4, 2026, 11:15 PM ET / August 5, 2026, 03:15 UTC. ClawSweeper reviewWhat this changesThe PR catches oversized MCP stdio stdout frames, reports a transport error, and closes that MCP server connection instead of allowing the OpenClaw host to crash. Merge readinessKeep open: this is a necessary, narrow repair with no actionable patch defect found. Current main still lets the stdout buffer append escape its stream callback; the PR contains a focused guard and real subprocess before/after proof, while exact-head checks are still running. Priority: P1 Review scores
Verification
How this fits togetherOpenClaw launches configured MCP servers as subprocesses and parses their stdout into protocol messages for agent tools. The stdio transport mediates parser failures before the MCP runtime marks a server disconnected and schedules recovery. flowchart LR
A[Configured MCP server] --> B[Child process stdout]
B --> C[OpenClaw stdio transport]
C --> D[Frame buffer and parser]
D --> E{Frame accepted?}
E -->|yes| F[Agent MCP runtime]
E -->|oversized or invalid| G[Transport error and close]
G --> F
F --> H[Server reconnect on next request]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +5, Tests +19. Total +24 across 2 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land the narrow transport-boundary guard after exact-head CI completes, preserving the existing disconnect-and-reconnect lifecycle for only the misbehaving MCP server. Do we have a high-confidence way to reproduce the issue? Yes, at source level: current main retains the unguarded stdout callback, and the PR supplies a real child-process before/after run using an oversized frame. This review did not rerun the untrusted branch locally. Is this the best way to solve the issue? Yes. The append call is outside the parser catch, so guarding it at the child stdout transport boundary and closing only that transport is the narrowest maintainable repair; the claimed upstream byte match was not independently inspected. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 1f3d45b76f51. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
|
@clawsweeper re-review Head moved: added Discord package |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
cd4939c to
5baefb3
Compare
|
Maintainer land decision for ClawSweeper re-review option: ClawSweeper recommended splitting the Discord Adopting this PR as the single vehicle (ClawSweeper alternate option): keep the Discord metadata commit here with co-author credit to Vincent Koc, land the MCP crash guard with green exact-head CI, then close #119391 as superseded once this merges. |
|
@clawsweeper re-review Head is MCP guard + Discord doctorCapabilities (same as #119391) after maintainer decision to adopt this PR as the single vehicle and supersede #119391. Please review exact head |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
…rash An MCP server whose stdout frame exceeds the SDK ReadBuffer 10 MiB cap makes ReadBuffer.append throw synchronously inside the child stdout data callback. The handler had no try/catch, so the error escaped as an uncaughtException and took down the host process, killing every concurrent session. The frame size is driven by tool-result data a lower-privileged sender can influence, not by the operator who chose the server. Wrap append and processReadBuffer in the same try/catch the upstream SDK transport uses: route the error to onerror and close the transport so the MCP runtime handles it as a server disconnect. This matches the existing stdin (openclaw#75438) and stderr (openclaw#99803) guards in this file; stdout was the missed path.
e5299b9 to
5dfb202
Compare
|
Rebased onto latest
|
|
@clawsweeper re-review Rebased onto main. MCP-only tip |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Merged via squash.
|
* origin/main: fix(channels): honor explicit preview streaming settings refactor(telegram): consolidate outbound contracts and targets (#119438) fix(qa): retry transport cleanup and always stop owned labs (#119442) fix(mcp): guard stdio stdout frame parsing against oversized-buffer crash (#119379) refactor(auto-reply): centralize delivery deduplication and routing (#119436) fix(qa): preserve scenario isolation in serial suites (#119439) perf(xai): lazy-load optional capability runtimes (#119374) refactor(browser): consolidate browser CLI and normalization helpers (#119432) fix(qa): require ready transport accounts (#119431) refactor(media): share image and video geometry normalization (#119416) fix(config): preserve plugin metadata for missing config (#119421) fix: retry delivery when outbound adapter is unavailable (#119371) fix(cli): retire invalid secret flags and prove doctor recovery (#118926) refactor(signal): share outbound and reaction transport (#119415)
…rash (openclaw#119379) …rash An MCP server whose stdout frame exceeds the SDK ReadBuffer 10 MiB cap makes ReadBuffer.append throw synchronously inside the child stdout data callback. The handler had no try/catch, so the error escaped as an uncaughtException and took down the host process, killing every concurrent session. The frame size is driven by tool-result data a lower-privileged sender can influence, not by the operator who chose the server. Wrap append and processReadBuffer in the same try/catch the upstream SDK transport uses: route the error to onerror and close the transport so the MCP runtime handles it as a server disconnect. This matches the existing stdin (openclaw#75438) and stderr (openclaw#99803) guards in this file; stdout was the missed path. Co-authored-by: Tak Hoffman <[email protected]>
Summary
An MCP stdio server whose stdout frame exceeds the SDK
ReadBuffer10 MiB cap crashes the whole OpenClaw host process, taking down every concurrent session with it. The frame is emitted by the server subprocess, but its size is driven by tool-result payload data (file contents, a fetched page, a database row) that a lower-privileged message sender can influence, not by the operator who chose which server to run.Root cause
src/agents/mcp-stdio-transport.tshandles child stdout with an unguarded synchronous call into the SDK read buffer:ReadBuffer.appendthrowsReadBuffer exceeded maximum size of 10485760 bytessynchronously once the accumulated buffer passesSTDIO_DEFAULT_MAX_BUFFER_SIZE(10 MiB).processReadBufferhas its own inner try/catch aroundreadMessage, butappendis called outside it. The throw runs inside the Node streamdatacallback, on a different stack from the per-server isolation the MCP runtime builds, so nothing catches it. It escapes as an uncaughtException and terminates the host process. There is no MCP server quarantine that survives the exit (serverBackoffis an in-memory map that dies with the process), so this is a deterministic, remotely influenced gateway kill.Fix
Wrap the two calls in the same guard the upstream SDK
StdioClientTransportuses for this exact code:The oversized frame is now reported through
onerrorand the transport closes, which the MCP runtime already handles as a normal server disconnect. The host stays up.Why this is the right boundary
The transport owns the child stdio read path, and this file already guards its sibling surfaces at exactly this boundary: stdin write errors (#75438), the stdout
errorevent, and stderr pipe errors (#99803). stdoutdatawas the one path left unguarded. The fix mirrors the upstream SDK behavior byte-for-byte (onerror+close), so a correctly framed stream is unaffected and existing message delivery is unchanged. No sibling transport is left one-sided.Verification
node scripts/run-vitest.mjs src/agents/mcp-stdio-transport.test.ts-> 10 passed, including the newreports an oversized stdout frame without an unhandled error crashcase. The new case fails on pristinemain(the frame throws out of the handler) and passes with the patch.oxlintandoxfmt --checkon both changed files -> clean.run-tsgo.mjs -p tsconfig.core.jsonand-p test/tsconfig/tsconfig.core.test.json-> no errors.@modelcontextprotocol/[email protected], the version pinned by the current lockfile (the 10 MiB cap exists there).Real behavior proof
Behavior addressed: an MCP stdio server emitting a single stdout frame larger than 10 MiB kills the entire host process instead of failing just that server connection.
Real environment tested: the real
OpenClawStdioClientTransport(no stub) spawns a real Node subprocess that writes one oversized line to stdout, parsed by the real@modelcontextprotocol/[email protected]ReadBuffer. Nothing is mocked: realchild_process.spawn, real stdio pipes, real read buffer. Run on pristine mainfb81d03and on the patched tree with an identical subprocess and identical input.Exact steps or command run after this patch:
tsxhost script instantiatesOpenClawStdioClientTransport({ command: node, args: [oversized-server.mjs] }), registers aprocess.on("uncaughtException")recorder plusonerror/onclosehandlers, callsstart(), and reports whether the host survives.Evidence after fix:
Observed result after fix: the oversized frame is delivered to
onerrorand the host keeps running and exits cleanly, where before it escaped to the top level and terminated the host with a non-zero exit.What was not tested: no live third-party MCP server was driven (a local subprocess stands in for the oversized emitter); the full production build was not run.