Repository navigation
fix(mcp): recover expired SSE sessions and speed up parsing - #155497
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 22, 2026, 12:01 PM ET / 16:01 UTC (Revision 10). ClawSweeper reviewWhat this changesRecover expired SSE tool-server connections without replaying failed calls, accelerate response scanning, and add recovery tests and documentation. Merge readiness✅ Ready for maintainer review Keep open: the SSE POST-404 recovery remains missing from current main and the latest release. The introduced patch has no actionable correctness or security findings. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw’s MCP clients discover and call tools on external servers for embedded agents and paired node hosts. The HTTP transport reports failures to the existing lifecycle owners, which retire connections and refresh available tools. flowchart TD
A[Agent or node tool request] --> B[MCP HTTP transport]
B --> C[External tool server]
C --> D[Bounded response scanning]
C --> E{Session expired?}
D --> F[Tool result]
E -->|Yes| G[Retire connection and report failure]
G --> H[Fresh connection and tool discovery]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +41, Tests +227, Docs +5. Total +273 across 9 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep session replacement within the existing lifecycle owners, preserving original failures, no automatic replay, and bounded response parsing. Do we have a high-confidence way to reproduce the issue? Yes, from source: an established legacy SSE connection whose message POST returns 404 produces a plain SDK error that current main does not classify as session expiration. No runtime reproduction was executed during this review. Is this the best way to solve the issue? Yes. Preserving the transport error’s type lets both existing lifecycle owners recover without duplicating retry policy or replaying potentially mutating calls. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ddbbc80aac5a. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (9 earlier review cycles; latest 8 shown)
|
55f9d24 to
fc2e52a
Compare
fc2e52a to
f5ad38a
Compare
|
Merged via squash.
|
* commit 'f3327bde3c6052a4ed6d487bb09fbe1e11c0cd35': (25 commits) fix(test): pass the fixture lifetime to launcher fixtures (#155825) fix(test): prepare history benchmark before child deadlines (#155780) refactor(config): derive tool contracts from schemas (#155484) chore(deps): update fs-safe to 0.18.1 (#155771) fix(doctor): allow repair with retained deleted-agent sessions (#155752) fix(setup): await inference probe cleanup (#155407) fix(mcp): recover expired SSE sessions and speed up parsing (#155497) fix(release): forward the stable soak waiver through the candidate helper (#155798) feat: calibrate Gateway plugin resources through retirement (#155792) fix: preserve the invoked launcher when restarting Node (#147621) fix(sessions): stop repeated failed worker exit cleanup (#154720) fix(ui): preserve active replies and tools after failed steering (#155746) fix(ci): retain missing-load-path baseline diagnostics (#154861) fix(gateway): keep session lists responsive during activity updates (#155767) fix: keep plugin queues bound to their selected session (#155714) chore(i18n): refresh native locales (#155571) fix(ci): wait for reset hook entry and join fixture cleanup (#155770) test: move subagent fixtures to module boundaries (#155727) fix(gateway): retain question requester authority through settlement (#155335) perf(gateway): move progress-card reads off the main thread (#153857) ...
Related: #68187
What Problem This Solves
Legacy SSE MCP servers can stay stuck after their message endpoint returns HTTP 404. The stale connection survives failed tool calls and tool-list refreshes, so later requests keep using an expired session. Large SSE responses also spend unnecessary CPU time scanning every byte in JavaScript.
User Impact
Embedded and node-host MCP runtimes retire expired SSE sessions and discover tools on a fresh connection. Failed tool calls retain their original error and are never replayed. Large HTTP/SSE responses are processed faster with the same message-size limits.
Why This Change Was Made
The SDK drops legacy SSE POST status codes into a plain error. The transport now preserves expiration as a typed error for the existing lifecycle owner, including catalog refresh. Ordinary HTTP 500 errors and stateless Streamable HTTP 404 errors remain distinct. The response limiter searches monotonically for line delimiters while preserving CR/LF, comment, and multiline-event accounting.
Evidence
f5ad38af9c0382d8e02d044c6e33e3102c7df711: 117 successful jobs, 16 skipped, zero failures, including the required CI gate and every previously failing lane. Native landing merged this head as824ab3fead2e67d01e30d8624a0e8cae5c69d1a4.callToolpath, 64 KiB chunks, and 15 measured requests per size after warmup. Median-of-medians latency fell from 52.0 to 13.7 ms for 8 MiB responses (74% reduction) and 1.99 to 0.66 ms for 256 KiB responses. These are synthetic local transport measurements, not overall agent-turn latency. Peak RSS varied: baseline 396–460 MiB, candidate about 416 MiB; no memory improvement is claimed.pnpm test <file> --maxWorkers=1wall times: HTTP transport 13.68 seconds (22 tests), embedded SSE recovery 12.26 seconds (4 tests), and node-host recovery 14.06 seconds (17 tests). Their test bodies took about 650 ms, 41 ms, and 1.8 seconds respectively. Cold graph preparation dominates command time. New cases reuse existing fixtures or an in-memory transport; no per-test Gateway/process boots or real sleeps were added. Hosted CI selected the broad core/SDK fallback. In CI run 35731555320, rounded case durations totaled 660 ms for the 22 HTTP cases, 29 ms for the four embedded SSE cases, and 1.384 seconds for the 17 node recovery cases. Their successful covering jobs took 624 seconds (HTTP and embedded) and 694 seconds (node), including other files and setup; standalone CI file wall times were not available.Previous CI failures and remaining proof limits
Earlier runs exposed shared fixture and tooling failures. The base includes the canonical placement-clock repair (#155530), SSH pairing-order repair (
f87f23c483b4c5130f42f2451f0b03e36ea0effe), and typed CLI-shim contract (80b9608a25e191a17e1466d750c2f76a38a38507). The MCP patch retains the same stable patch ID across refreshes.Run 35719486744 observed a started Gateway delivery after its 15-second assertion window. The base includes the readiness change
9a7984ef3daee304a4b684961964ddfbe687b7ff; that shard passed in the following MCP run. Our earlier original 23-file/325-test Linux replay and one diagnostic run also passed, the latter settling 7.038 seconds after release. Those were non-reproductions, not root-cause proof; Testbox RAM was 16.56 GB versus CI's 8.22 GB. No timeout or assertion was changed, and diagnostic edits were reverted.Run 35731555320 passed the MCP test jobs and the Gateway delivery shard, but two archive-placement cases failed their one-second readiness poll and left unjoined requests that later reported revoked reads. The current base contains the owning repair #155751 and the related terminal-persistence fixture correction in
bb2d479926adb23fb30737e2fd3e5af63969dc84(#152057). An equivalent local placement correction independently changed a pristine-main result of 2 failures / 22 passes / 2 unhandled errors into 24 passes with no unhandled errors, and passed selected checks and independent review; it was superseded without duplicate publication. The canonical archive repair's original 40-file replay retained one unexplained auth-refresh root-count failure, while its selected hosted CI passed. Earlier passing executions do not erase those historical limitations.Run 35739216555 on
fc2e52a54492efd1ccc3b8347ca774a973b073cepassed both previously failing Gateway shards and production types. Its sole test failure included cold memory-reader startup in a one-second fixture assertion. The current base contains the canonical correction from #155745 (5c9d100c72a08cbc0c3d1f09e5590ec27bd8d8e5): it queues a read barrier after both candidate lookups and verifies their public completion before releasing the held rebuild, with provider-entry and cancellation cleanup. On immutable canonical main, all three fixture cases passed; restoring the historical blockingawaitmade both startup variants fail the intended post-barrier assertion, with no timeout or unhandled error. The external proof driver's summary-count check misread Vitest's grouped trace; both named failures were independently qualified from the retained output without rerunning. The alternative warm-reader PR #155778 was closed as superseded. This proves repair independence, not a one-second cold-start guarantee or a product startup speedup.A separate clock-test coverage weakness was fixed on main by #155748 (
092cc29d5e0a9da56c507e567a6a5edaedf3be4d). A timer-aligned control proved that the old scheduler could pass through natural timer expiration 11.816 seconds after release; moving held enqueue after readiness made that same old scheduler fail the original queue assertion, while the current scheduler passed both delayed and normal flows. All four controls, selected checks, and independent review passed. This concerns the integration test's mutation coverage, independently of the MCP boundary regressions, and does not establish the cause of the historical started-but-unsettled failure.