Repository navigation
fix(mcp): restore channel media, event delivery, and lifecycle cleanup - #126592
Conversation
Restore persisted channel media, cancellation cleanup, retryable permission delivery, bounded-event gap recovery, complete shutdown, and actionable Gateway startup diagnostics.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
Land-ready proofReviewed head: Root-cause ownership is repaired across canonical persisted media projection, MCP request cancellation/waiter settlement, retryable owner-permission notification delivery, bounded queue eviction/cursor-gap recovery, complete bridge-plus-server shutdown, and actionable Gateway startup diagnostics. Existing attachment/event result fields are preserved; Exact local proof: Exact-head hosted CI: CI run 32346981395, conclusion Native review artifacts passed Production LOC: ClawSweeper: the latest comment currently reports an in-progress review; no substantive review or Known proof gap: the passing Docker verdict is packaged/mock-Gateway end-to-end evidence, not a live authenticated external-channel run. |
|
Merged via squash.
|
Restore persisted channel media, cancellation cleanup, retryable permission delivery, bounded-event gap recovery, complete shutdown, and actionable Gateway startup diagnostics.
Additional instructions
MUST: Keep Allow edits from maintainers enabled for this PR so maintainers
can help update the branch when needed.
What Problem This Solves
Fixes an issue where users connecting an MCP client to OpenClaw channels could lose persisted media attachments, leave cancelled long-poll requests running, permanently consume an undelivered permission response, silently miss evicted events, overlook shutdown failures, or receive an unrelated diagnostic when the Gateway could not start the MCP bridge.
Why This Change Was Made
The MCP bridge now repairs each lifecycle at its actual owner boundary: canonical persisted
__openclaw.mediais projected alongside existing content attachments as distinguishableopenclaw_mediaentries; the MCP SDK request abort signal settles the bridge waiter, timer, and listener exactly once; permission requests remain pending until their notification is actually delivered; bounded queue eviction reports an additive cursor gap, promptly wakes filtered waits, and provides filtered polls the first recoverable cursor; bridge and MCP server shutdown both run and aggregate multiple failures without leaking unhandled rejections; and startup failures direct operators toopenclaw gateway status --deep --require-rpc.Existing MCP attachment items, event fields, and cursor behavior remain compatible; the media item variant and optional
gapfields are additive, with no protocol or schema version change. The packaged fixture and client exercise the canonical persisted representation instead of a synthetic content block. AI-assisted; reviewed with no accepted or actionable findings.User Impact
Channel-connected MCP clients can retrieve real persisted inbound media, cancel waits without stranding server resources, retry owner permission delivery after a transport failure, detect and recover from live-event queue eviction, and reliably observe shutdown/startup failures with an actionable Gateway health command. Owner/non-owner permission boundaries remain unchanged.
Evidence
node scripts/run-vitest.mjs run src/mcp/channel-bridge.test.ts src/mcp/channel-server.test.ts src/mcp/channel-server.shutdown-unhandled-rejection.test.ts test/scripts/docker-e2e-seeds.test.ts(38 tests passing).node scripts/run-vitest.mjs run src/cli/mcp-cli.test.ts -t 'points serve startup failures at the deep Gateway health diagnostic'.node scripts/check-changed.mjs -- docs/cli/mcp.md scripts/e2e/mcp-channels-seed.ts src/cli/mcp-cli.test.ts src/cli/mcp-cli.ts src/mcp/channel-bridge.test.ts src/mcp/channel-bridge.ts src/mcp/channel-server-runtime.ts src/mcp/channel-server.shutdown-unhandled-rejection.test.ts src/mcp/channel-server.test.ts src/mcp/channel-server.ts src/mcp/channel-shared.ts src/mcp/channel-tools.ts test/e2e/qa-lab/runtime/mcp-channels-docker-client.ts test/scripts/docker-e2e-seeds.test.ts.pnpm docs:check-mdx,pnpm build, andgit diff --check.pnpm test:docker:mcp-channelspassed with{ "ok": true, "canonicalMediaAttachmentFound": true, "nonOwnerReplyForwarded": true, "nonOwnerPermissionBlocked": true, "ownerPermissionAllowed": true }; this is packaged/mock-Gateway end-to-end proof, not a live authenticated external-channel run.dist/esm/shared/protocol.js:169-175,314-320,670-685anddist/esm/shared/protocol.d.ts:170-177establish cancellation-to-request-signal ownership; the sibling Codex sourcecodex-rs/rmcp-client/src/rmcp_client.rs:756-812,codex-rs/rmcp-client/src/event_notification_transport.rs:121-145, andcodex-rs/mcp-server/src/message_processor.rs:533-575verify MCP tool-result and cancellation lifecycle contracts. Canonical persisted media ownership issrc/media/media-facts.ts:69-81.+139/-54(net+85); tests/proof:+262/-15; docs:+7/-3. The production growth is required by additive media/gap result contracts, single-owner cancellation settlement, retryable delivery ownership, and complete multi-owner shutdown across six independently reproduced defects; no compatibility shim, dependency, version, protocol bump, or changelog change is introduced.