Repository navigation
fix(gateway): recover MCP loopback after unexpected close - #183352
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. What this changesThis PR retires a closed MCP listener’s cached endpoint and grants so the next CLI run starts a replacement. Example: The MCP listener closes while the Gateway remains alive, then Claude CLI requests an OpenClaw write.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR repairs a current-main listener lifecycle defect with a focused change and no actionable findings; exact-head CI remains pending. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe Gateway-owned loopback HTTP listener exposes scoped OpenClaw tools to CLI subprocesses; run grants authorize incoming MCP requests, and CLI preparation consumes the published listener endpoint. flowchart TD
A[CLI run preparation] --> B[Active runtime]
B --> C[Loopback HTTP listener]
C --> D[Run grant validation]
D --> E[Scoped tool execution]
C --> F[Listener close cleanup]
F --> B
F --> G[Grant retirement and work drain]
Technical reviewBest possible solution: Retain this owner-level cleanup repair and land it once the required checks pass. Do we have a high-confidence way to reproduce the issue? Source establishes stale endpoint reuse after actual listener closure, and the supplied process run exercises that condition; this review ran no target code, and the original spontaneous closure cause remains unknown. Is this the best way to solve the issue? Yes: sharing cleanup between managed shutdown and actual listener closure repairs the existing owner while preserving grant isolation, successor ownership, and accepted-work draining. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 929abf856df0. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +21, Tests +147, Docs +2. Total +170 across 3 files. Added test files: 1. View PR surface stats
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (7 earlier review cycles)
Reviewed October 26, 2026, 3:23 PM ET / 19:23 UTC (Revision 8). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Integrate current main and retire the closed listener runtime and grants so the next CLI run starts a replacement. Co-authored-by: songc <[email protected]>
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…83352) Retire the MCP loopback runtime, grants, and cached endpoint when its listener closes unexpectedly, so the next CLI run starts a working listener. Share idempotent cleanup with managed shutdown and preserve successor ownership. Validated with the actual-listener recovery regression and async-scope tests (12 passed), retained isolated Windows Gateway/CLI proof, and exact-head CI 40385723704. Closes openclaw#139340 Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: Nice De Cc <[email protected]> Co-authored-by: songc <[email protected]>
Retire the MCP loopback runtime, grants, and cached endpoint when its listener closes unexpectedly, so the next CLI run starts a working listener. Share idempotent cleanup with managed shutdown and preserve successor ownership. Validated with the actual-listener recovery regression and async-scope tests (12 passed), retained isolated Windows Gateway/CLI proof, and exact-head CI 40385723704. Closes #139340 Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: Nice De Cc <[email protected]> Co-authored-by: songc <[email protected]> (cherry picked from commit 7058d9e) Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit caea1bbd76548daf42b08686683e3e91dd44cfee)
Retire the MCP loopback runtime, grants, and cached endpoint when its listener closes unexpectedly, so the next CLI run starts a working listener. Share idempotent cleanup with managed shutdown and preserve successor ownership. Validated with the actual-listener recovery regression and async-scope tests (12 passed), retained isolated Windows Gateway/CLI proof, and exact-head CI 40385723704. Closes #139340 Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: Nice De Cc <[email protected]> Co-authored-by: songc <[email protected]> Beta.5 baseline adaptation: Retain the native beta.5 owners, fixtures and public contracts; add focused regression controls and bounded fixture extraction; apply checkout formatting. (cherry picked from commit 7058d9e) (cherry picked from commit fe15736) Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 441f64154d8d95980b882baef840e5b4a17faaff)
Preserve the deployed requester-bound mail recovery checkpoint repair while integrating the reviewed backend recovery, question, model, and delivery fixes. Upstream OpenClaw backports and adaptations: - MCP listener recovery, openclaw#183352 / 7058d9e: Nice De Cc, songc, and Peter Steinberger. - Process lineage sharing, 7dc3350: Dallin Romney. - Model publication supersession, openclaw#179144 / 5a97c90: Peter Steinberger; adapted to this fork's successful skipped-candidate batches. - Authoritative delivery settlement, openclaw#169650 / c2fe11f: Peter Steinberger. - Blocking question routing, openclaw#170039 / e163d81: Peter Steinberger. - fast-uri security backport, openclaw#187285 / 9f492b6: Dallin Romney; upstream parser fixes by Vincent Le Goff and Ulises Gascon. - Nodemailer sender parsing, openclaw#187301 / 0692808: Dallin Romney; upstream parser fixes by Andris Reinman. Keep existing local question-answer custody and synchronous native Codex steering; preserve both published SDK module/ingress ownership repairs.
Closes #139340
What Problem This Solves
Fixes: CLI-backed runs keep receiving a dead MCP endpoint after its listener closes while the Gateway remains alive.
User Impact
The next CLI run starts a replacement listener and regains tool access. Grants from the retired listener stop authorizing calls. The Gateway log records unexpected closure.
Why This Change Was Made
The listener owner shares idempotent cleanup between managed shutdown and the actual close event. Cleanup retires only its own runtime, grants, and tool cache, preserves a successor listener, and drains accepted work.
Thanks to @SC-10749 for the fix and process-level recovery proof. Contributor commits are preserved.
Co-authored-by: songc [email protected]
Evidence
0cbd02a455a08bb329fb6f695dc5ce30708338c9: closing the actual listener leaves the cached runtime present. The repaired owner passes; authorized writes succeed before closure and through the replacement, while a captured old grant is revoked and cannot write.Contributor process-level proof on
da197ede4f8f6f67e43c88448529dd647a0419a8: a real Windows Gateway launched Claude Code CLI 2.1.98 against an isolated local model mock. An MCP write succeeded, Node Inspector closed the Gateway's actual MCP HTTP listener, and the next CLI run bound a replacement listener and wrote successfully. The Gateway and WebSocket listener remained alive throughout. This proof was retained rather than repeated with an additional Inspector/model harness; the spontaneous real-world cause of listener closure remains unverified. No external model credentials or operator state were used.Current integration includes main commit
a8af441b0efa, which repairs the unrelated reply-preparation test type error seen in the earlier CI run. Final integrated-head focused checks and CI are recorded below.Final head
1061587b199ccf1066dffe4d1f3e131b0358de98passes all 12 focused tests after integration (215.00 seconds outer wall, 189.36 seconds Vitest; real HTTP recovery 22.479 seconds under shared-host load). Targeted core oxlint, oxfmt, and whitespace checks pass. Exact-head CI run 40385723704 and the aggregate CI gate passed. Final-head ClawSweeper completed with zero findings.