Repository navigation
fix(mcp): cleanup fails when a retired relay stalls - #150306
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 17, 2026, 12:47 AM ET / 04:47 UTC (Revision 10). ClawSweeper reviewWhat this changesRepairs stalled MCP subprocess shutdown, exposes confirmed forced-cleanup diagnostics, and isolates shell-test mocks so real-process cleanup tests retain native termination behavior. Merge readiness✅ Ready for maintainer review The repair remains necessary. The previous recursive-spy finding is addressed at its producer, and the recorded ordered replays support that correction. No remaining actionable patch defect was found. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw's MCP client exchanges requests with local server subprocesses. Its process supervisor uses an anchor and relay to shut down descendants and confirm cleanup before the client reports success. flowchart TD
A[MCP client shutdown] --> B[Process cleanup owner]
B --> C{Receipt and pipes closed}
C -->|Confirmed| D[Retire anchor through relay]
C -->|Missing facts| G[Cleanup error]
D --> E[Confirm relay exit and group absence]
E -->|Confirmed| F[Successful shutdown and diagnostics]
E -->|Deadline expires| G
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +248, Tests +302, Docs +10. Total +560 across 14 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep shutdown and escalation in the existing process owner, preserving confirmed extinction, permanent failure outcomes, and the original cleanup deadline. Do we have a high-confidence way to reproduce the issue? Yes, source and the recorded held-anchor/relay cases establish a concrete trigger: shutdown receives closure facts while a cleanup process remains alive. This read-only review did not execute a current-main reproduction. Is this the best way to solve the issue? Yes. The patch repairs the existing cleanup owner and preserves its completion checks; narrowing the shell mock addresses the demonstrated shared-worker contamination without weakening cleanup assertions. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 947a7eb9a35e. LabelsLabel 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)
|
8159c61 to
e9dac7f
Compare
ffe9922 to
a582ee5
Compare
a582ee5 to
b17d641
Compare
b17d641 to
08fed26
Compare
08fed26 to
6bf8e39
Compare
Admit forced retirement from closure facts instead of requiring prior group extinction. Retain force requests across later closure events and recheck routing within the existing cleanup deadline. Let the relay kill and reap its owned anchor, then retire the retained relay handle. Kernel-proven group absence still permits direct native termination of an unresponsive relay. Confirm actual exit and group disappearance before reporting cleanup complete; release IPC on terminal failure without reviving a timed-out outcome. Reproduce the missing-escalation failure with a real held anchor and keep the existing deadline, failed-delivery, late-exit, and fresh-client contracts. Related: #150306
Apply the repository formatter to the two test conditions left unformatted by openclaw#135276 (18dcf28), which broke check-docs formatting checks on unrelated PRs openclaw#150306 and openclaw#150312. This changes line wrapping only.
Honor existing force requests after a closing receipt only when control, output, lineage and kernel group-disappearance facts permit reclaiming the retained direct relay. Confirm actual exit within the original hard deadline and retain timing, signal-delivery errors and observed exit facts. Keep stop() compatible and expose the optional cleanup result without reviving a retired connection. Fresh driver executions remain available. Related: #150236
Admit forced retirement from closure facts instead of requiring prior group extinction. Retain force requests across later closure events and recheck routing within the existing cleanup deadline. Let the relay kill and reap its owned anchor, then retire the retained relay handle. Kernel-proven group absence still permits direct native termination of an unresponsive relay. Confirm actual exit and group disappearance before reporting cleanup complete; release IPC on terminal failure without reviving a timed-out outcome. Reproduce the missing-escalation failure with a real held anchor and keep the existing deadline, failed-delivery, late-exit, and fresh-client contracts. Related: #150306
Replace the whole child_process autospy with a native-backed spawnSync mock. The broad autospy mutated ChildProcess.prototype across files, so the cleanup fixture reconfigured its captured kill spy into a recursive call and later prevented teardown signals. Preserve the existing cleanup assertions and deadlines. Related: #150306
6bf8e39 to
6507e49
Compare
|
Merged via squash.
|
Keep child cleanup and eager supervised-process failures visible to callers without letting unobserved rejections crash the Gateway. Publish the retained cleanup promise at the sole spawnServiceChildRelay creation site, join authority finalization and admitted tree signaling, and preserve retained-handle escalation, forced-exit diagnostics, output drainage, and cleanup deadlines. Uncertain extinction remains a failure. Include redacted error stacks in Gateway stability bundles, bounded to 8,000 UTF-16 code units; older bundles without stacks remain readable. No configuration, CLI option, dependency, schema version, or installed update-driver behavior changes. The runtime repair takes effect when the candidate Gateway starts. Related: #144911, #144941. Preserve integration with #150306, #150392, and #150564. The earlier MCP field-crash path is separately contained by #144941; this change closes remaining unobserved-promise paths. Thanks to @itanyplus, @waynegault, @chachi-max, and @kip-claw for the reports and field evidence. Validation: exact-head CI run 35208176360 is green. Recorded focused proof: 395 tests passed and 6 skipped, followed by 64 passing spawn-broker tests; check:changed passed. Codex review is scoped-clean through P1 on a patch-identical revision, and ClawSweeper reports no findings on the landed head. Prior macOS Gateway probes predate final broker integration and do not claim a Linux/systemd field-crash reproduction.
Service-child cleanup could report an unavailable MCP driver when a retired relay or anchor remained alive after the closing receipt and pipe closure. Retain pending force requests in the existing cleanup owner, reap a live anchor through its relay, then retire the retained relay handle. Confirm actual exit and group disappearance within the original hard deadline, preserving signal-delivery errors and forced-cleanup diagnostics. Fresh driver executions can connect afterward. The CUA proxy cleanup-deadline flake on hosted runners was a symptom of this cleanup gap. The accompanying shell-test fix narrows whole-module child_process autospy to native-backed spawnSync, preventing shared-worker prototype contamination and recursive kill calls without relaxing cleanup assertions or deadlines. Exact-head CI passed without reruns: https://github.com/openclaw/openclaw/actions/runs/35182765072 Retained proof includes real-process stall, failed-delivery, late-exit, fresh-client and ordered shared-worker replay coverage. Codex review and the exact-head ClawSweeper review have no remaining actionable findings within their stated scope. Related: openclaw#150236
…150427) Keep child cleanup and eager supervised-process failures visible to callers without letting unobserved rejections crash the Gateway. Publish the retained cleanup promise at the sole spawnServiceChildRelay creation site, join authority finalization and admitted tree signaling, and preserve retained-handle escalation, forced-exit diagnostics, output drainage, and cleanup deadlines. Uncertain extinction remains a failure. Include redacted error stacks in Gateway stability bundles, bounded to 8,000 UTF-16 code units; older bundles without stacks remain readable. No configuration, CLI option, dependency, schema version, or installed update-driver behavior changes. The runtime repair takes effect when the candidate Gateway starts. Related: openclaw#144911, openclaw#144941. Preserve integration with openclaw#150306, openclaw#150392, and openclaw#150564. The earlier MCP field-crash path is separately contained by openclaw#144941; this change closes remaining unobserved-promise paths. Thanks to @itanyplus, @waynegault, @chachi-max, and @kip-claw for the reports and field evidence. Validation: exact-head CI run 35208176360 is green. Recorded focused proof: 395 tests passed and 6 skipped, followed by 64 passing spawn-broker tests; check:changed passed. Codex review is scoped-clean through P1 on a patch-identical revision, and ClawSweeper reports no findings on the landed head. Prior macOS Gateway probes predate final broker integration and do not claim a Linux/systemd field-crash reproduction.
Related: #150236
What Problem This Solves
Fixes CUA MCP cleanup reporting an unavailable driver when its anchor or relay remains alive after the closing receipt and pipe closure.
User Impact
Confirmed forced cleanup completes normally and preserves the observed exit and any signal-delivery errors. A fresh driver execution can connect afterward. Unconfirmed cleanup still fails with timings and missing closure facts. Runtime deadlines and configuration remain unchanged.
Why This Change Was Made
The original escalation gate required server-group disappearance before permitting escalation. The owner now retains pending force requests and admits them once the matching closing receipt and control/output/lineage closures are confirmed. A live anchor is killed and reaped through its relay before the host retires the retained relay handle. When the group is already absent, the host can terminate an unresponsive relay directly. Actual relay exit and group disappearance must still be confirmed within the original hard deadline.
The later shared-worker failure came from the shell-test fixture. Whole-module autospy of
node:child_processmutated nativeChildProcess.prototypemethods, and those autospies survivedrestoreAllMocks(). The cleanup fixture bound the inheritedkillspy, then replaced that same spy's implementation with a call to its bound self. Subsequent fault injection also changed the inherited method for later children, preventing teardown signals. The follow-up mocks onlyspawnSync, preserving its native implementation and call tracking without instrumenting native child prototypes. All cleanup assertions and deadlines remain unchanged.Evidence
Missing-escalation recurrence on a582ee541ab: all closing/pipe facts were confirmed, with relay exit and extinction outstanding at 5002.394261 ms and
escalationAfterMs: undefined. A real held-anchor regression reproduced this before the owner repair (5000.049541 ms, no escalation). The repaired persistent-group and closure-ordering cases subsequently passed 60/60 executions under CPU/IO load.Shared-worker recurrence on 6bf8e39091a: 4 failed / 1,925 passed, including two 180-second teardown timeouts. The reported-failure fixture recursively called its
killspy; cleanup expired at 5000.191654 ms, after escalation at 3995.210801 ms.Local standalone proof passed 6/6 before the fixture repair. Replaying the captured packed plan reproduced the shared-worker failure:
The stack alternated between the forwarding callback at
mcp-stdio-client.cleanup.real.test.ts:134and Vitest'sChildProcess.killspy. A separate probe of the installed Vitest implementation confirmed that the prototype spy survives restoration and reproduces this recursion.Proof at
12359e02849104b5bbbf81b0dddb22836e00a063(macOS, Node 24.21.0):shell-utils.node scripts/check-changed.mjs: passed, including formatting, core/test typechecking, lint, line-cap ratchets, all three dead-export scans, and repository guards.--mode branch --base origin/main --max-priority P1): scoped-clean, no accepted/actionable P0/P1 findings.A complete packed-job replay before the final rebase also passed 5,202 tests, two skipped. Interrupted capacity probes and repetitions that did not preserve the original order are excluded from the counts above; their artifacts were retained.
Publication head:
6507e49540f36222174d72f53a02f754dff3f1c2. The final rebase onto6be890529a957873878536b5edf2f70a2e1f3ae4kept all four patches identical (git range-diffreports=for each), and every PR file and review-context file remained byte-identical. Script files match that main anchor,pnpm install --frozen-lockfilepassed, and the ordered shell/cleanup boundary check on the publication head passed 42 tests, one skip.This follow-up changes production 0 lines; tests +5/-1 (net +4). The service-child cleanup owner is unchanged by the fixture repair.