Skip to content

fix(mcp): restore channel media, event delivery, and lifecycle cleanup - #126592

Merged
steipete merged 1 commit into
mainfrom
steipete/admiring-nash-78dd08
Aug 20, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/admiring-nash-78dd08

Conversation

@steipete

Copy link
Copy Markdown
Contributor
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.media is projected alongside existing content attachments as distinguishable openclaw_media entries; 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 to openclaw gateway status --deep --require-rpc.

Existing MCP attachment items, event fields, and cursor behavior remain compatible; the media item variant and optional gap fields 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

  • Focused bridge/server/shutdown/Docker-seed regression suite: 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).
  • Targeted CLI diagnostic regression: node scripts/run-vitest.mjs run src/cli/mcp-cli.test.ts -t 'points serve startup failures at the deep Gateway health diagnostic'.
  • Changed-surface validation: 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.
  • Documentation/build/patch checks: pnpm docs:check-mdx, pnpm build, and git diff --check.
  • Exact-current packaged Docker proof: pnpm test:docker:mcp-channels passed 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.
  • Direct upstream contract inspection: the installed MCP SDK dist/esm/shared/protocol.js:169-175,314-320,670-685 and dist/esm/shared/protocol.d.ts:170-177 establish cancellation-to-request-signal ownership; the sibling Codex source codex-rs/rmcp-client/src/rmcp_client.rs:756-812, codex-rs/rmcp-client/src/event_notification_transport.rs:121-145, and codex-rs/mcp-server/src/message_processor.rs:533-575 verify MCP tool-result and cancellation lifecycle contracts. Canonical persisted media ownership is src/media/media-facts.ts:69-81.
  • Production LOC: +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.

Restore persisted channel media, cancellation cleanup, retryable permission delivery, bounded-event gap recovery, complete shutdown, and actionable Gateway startup diagnostics.
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes scripts Repository scripts size: M maintainer Maintainer-authored PR labels Aug 20, 2026
@clawsweeper

clawsweeper Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 20, 2026 08:04
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready proof

Reviewed head: 314b537c7cc6a26cf8fd57c622eeb7a360b08714.

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; openclaw_media items and optional gap metadata are additive, with no protocol/schema/version/dependency change.

Exact local proof:

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
# PASS: 4 files, 38 tests, 3 Vitest shards

node scripts/run-vitest.mjs run src/cli/mcp-cli.test.ts -t 'points serve startup failures at the deep Gateway health diagnostic'
# PASS: 1 focused CLI diagnostic regression

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
# PASS

pnpm docs:check-mdx
# PASS: 777 files

pnpm build
# PASS

git diff --check
# PASS

pnpm test:docker:mcp-channels
# PASS: { "ok": true, "canonicalMediaAttachmentFound": true, "nonOwnerReplyForwarded": true, "nonOwnerPermissionBlocked": true, "ownerPermissionAllowed": true }

node scripts/watch-pr-ci.mjs 126592 314b537c7cc6a26cf8fd57c622eeb7a360b08714
# STATUS state=SUCCESS pending=0 superseded=64
# GREEN

Exact-head hosted CI: CI run 32346981395, conclusion success; final openclaw/ci-gate, Windows shard 1, Windows shard 2, channel contracts A, and channel contracts B all passed.

Native review artifacts passed scripts/pr review-validate-artifacts 126592 with READY FOR /prepare-pr, valid PR-body issue evidence, behavioral sweep pass, no silent-drop risk, and zero findings. Fresh mandatory autoreview had no accepted/actionable findings.

Production LOC: +139/-54 (net +85); tests/proof: +262/-15; docs: +7/-3. Production growth is justified by additive media/gap result contracts and canonical settlement, delivery, and cleanup ownership across six confirmed defects.

ClawSweeper: the latest comment currently reports an in-progress review; no substantive review or Rank-up moves: list has been published, so there are no actionable moves to apply or skip. No re-review is required for this unchanged exact head.

Known proof gap: the passing Docker verdict is packaged/mock-Gateway end-to-end evidence, not a live authenticated external-channel run.

@steipete
steipete merged commit 10e7074 into main Aug 20, 2026
228 checks passed
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@steipete
steipete deleted the steipete/admiring-nash-78dd08 branch August 20, 2026 08:14
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 21, 2026
Restore persisted channel media, cancellation cleanup, retryable permission delivery, bounded-event gap recovery, complete shutdown, and actionable Gateway startup diagnostics.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes docs Improvements or additions to documentation maintainer Maintainer-authored PR scripts Repository scripts size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant