Skip to content

fix(node-host): recover MCP catalogs and sessions - #125092

Merged
steipete merged 3 commits into
mainfrom
steipete/node-mcp-architecture-cleanup-20260816
Aug 17, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/node-mcp-architecture-cleanup-20260816

Conversation

@steipete

@steipete steipete commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Node-hosted MCP reused the same configuration and low-level transport/filter primitives as Gateway/session MCP, but independently reimplemented client lifecycle and result projection. That drift left node tool catalogs stale after tools/list_changed, left expired stateful Streamable HTTP sessions broken until restart, abandoned server-side HTTP sessions during shutdown, and converted MCP application errors into failed node RPCs.

Closes #125044.

Why This Change Was Made

Keeps the two correct architectural owners—session/requester lifetime in the Gateway and process lifetime on the node—while moving placement-neutral behavior into shared MCP primitives.

The shared client-lifecycle owner now handles initialize deadlines, parent aborts, bounded teardown, forced stdio cleanup, Streamable HTTP termination, and exact stateful-session expiry classification. The node owner now serializes per-server refresh/recovery, globally rebuilds the bounded descriptor catalog, republishes only effective changes, and reconnects with bounded backoff. The current published descriptor array remains the sole call authority.

The result projector now preserves the MCP contract: CallToolResult.isError is delivered as a model-visible failed tool result with structured and non-text content, while unavailable servers, unpublished tools, timeouts, and transport/protocol failures remain failed node.invoke RPCs.

AI-assisted: yes. The implementation received independent architecture, proof-coverage, dependency-contract, result-semantics, recovery, simplification, and structured autoreview passes. No agent transcript is attached.

User Impact

Node-hosted MCP tools now update live when the server changes its catalog. Closed stdio/SSE/HTTP transports and expired stateful Streamable HTTP sessions withdraw stale tools and recover without restarting the node host. The call that discovers an expired session still fails once and is never replayed; later calls use the replacement connection after republishing.

Gateway/session MCP behavior is unchanged except for sharing the same lifecycle and result-projection owners. Node MCP application errors now retain useful structured content so the model can correct its request.

Evidence

  • Focused node MCP lifecycle/invoke suite: 33 passed.
  • Session MCP materialization: 19 passed.
  • Session timeout/retry regression: passed after removing a fire-and-forget log-order assertion that flaked under loaded process teardown.
  • Real isolated Gateway + real openclaw node run E2E: passed.
    • real stdio, legacy SSE, and Streamable HTTP servers in both placements;
    • two-stage device/node pairing;
    • include/exclude filter parity;
    • real node.pluginTools.update publication and node.invoke calls;
    • MCP application-error payload preservation;
    • live tool rename/schema replacement through tools/list_changed;
    • stateful Streamable HTTP 404 withdrawal and later recovery without replay;
    • stdio process withdrawal and proactive reconnect;
    • tools.effective node inventory and disconnect cleanup.
  • Complete private-QA build: passed locally.
  • Blacksmith Testbox exact changed gate: passed on tbx_01m072smmrmhprtjfzbanbw8jz (run); format, ratchets, dead exports, core/core-test/root typechecks, core/scripts lint, import cycles, and architecture guards all passed.
  • Post-rebase CI inventory repair: 23 focused tests passed, Knip reported zero unused files, and formatting/diff checks passed.
  • Exact-head GitHub CI: green for 2a4005519d52d396d926ff2d3970559a4d9f67b4 (run).
  • Pinned dependency contract: directly inspected installed @modelcontextprotocol/sdk 1.30.0 source for status-preserving StreamableHTTPError, session-ID handling, DELETE termination, abort propagation, and close-on-initialize-failure.
  • Sibling Codex contract: directly inspected commit 92cbfb4d2431 for stateful-404-only expiry classification, single-flight session reinitialization, DELETE termination, and owned stdio shutdown.
  • Fresh final Codex P1 autoreview after the startup-cancellation repair: clean, with no accepted/actionable findings.
  • Authenticated OpenAI proof gap: both approved Molty OpenAI keys currently return HTTP 401. The lane reached the real OpenAI Responses endpoint and is kept as a gated live test, but this PR does not claim a successful external-model call.

Production LOC: +571/-349 (net +222) | Tests/support: +2005/-42 | Docs/ratchets/tooling: +10/-2. The production growth is the process-lifetime node recovery/catalog owner plus shared bounded lifecycle handling; duplicate per-placement projectors and teardown paths were removed.

Share placement-neutral MCP lifecycle and result projection while keeping Gateway session ownership and node process ownership separate. Refresh node catalogs live, recover closed or expired transports without replay, and preserve MCP application errors across node.invoke.\n\nFixes #125044
@clawsweeper

clawsweeper Bot commented Aug 17, 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 17, 2026 05:57
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling plugin: file-transfer size: XL maintainer Maintainer-authored PR labels Aug 17, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 17, 2026
@clawsweeper

clawsweeper Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 17, 2026, 2:38 AM ET / 06:38 UTC.

ClawSweeper review

What this changes

The PR centralizes MCP client lifecycle and result projection, then makes node-hosted MCP catalogs refresh and recover live after transport closure or stateful HTTP-session expiry.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open for protected maintainer handling. Current main still has the reported one-shot catalog behavior, and the PR provides a coherent node-lifecycle owner with focused and real-process coverage; no concrete patch defect was found in this review.

Priority: P1
Reviewed head: 2a4005519d52d396d926ff2d3970559a4d9f67b4
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Strong real-process proof and focused coverage support a coherent repair, with protected owner approval and local dependency-inspection limits remaining.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body reports an after-fix isolated Gateway plus real node-process E2E across all three supported MCP transports, including recovery and cleanup behavior.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body reports an after-fix isolated Gateway plus real node-process E2E across all three supported MCP transports, including recovery and cleanup behavior.
Evidence reviewed 6 items Current-main defect: Current main lists node MCP tools only during startup; its close callback removes descriptors but does not reconnect or refresh the catalog.
Canonical repair boundary: The PR makes the node process own serialized catalog refresh, descriptor replacement, teardown, and bounded reconnect while reusing placement-neutral lifecycle primitives.
Real-process coverage: The added E2E starts an isolated Gateway and real node process, exercises stdio, SSE, and Streamable HTTP, then verifies catalog replacement, expiry recovery without replay, and process cleanup.
Findings None None.
Security None None.

How this fits together

Node-hosted MCP connects external tool servers to a paired OpenClaw node, which publishes tool descriptors through the Gateway for agents. This change governs connection recovery, descriptor publication, and the resulting tool-call payloads.

flowchart LR
  A[MCP servers] --> B[Node-host MCP client]
  B --> C[Catalog and recovery manager]
  C --> D[Paired Gateway]
  D --> E[Agent tool catalog]
  E --> F[Tool call]
  F --> B
  B --> G[Model-visible result]
Loading

Decision needed

Question Recommendation
Does the node-host/MCP owner approve this +222-line recovery state machine as the canonical process-lifetime owner before merge? Approve the canonical recovery owner: Accept the shared lifecycle primitive plus node-local catalog manager, supported by the real Gateway/node E2E and focused recovery tests.

Why: The protected maintainer label and cross-owner lifecycle refactor require explicit human architectural acceptance despite no concrete patch defect.

Before merge

  • Resolve merge risk (P1) - The new process-lifetime recovery manager adds net +222 production lines; a lifecycle mistake could temporarily withdraw or mispublish node MCP tools across reconnects.
  • Resolve merge risk (P1) - This read-only checkout lacks node_modules and could not resolve GitHub, so the MCP SDK source and claimed test runs were not independently rerun locally.
Agent review details

Security

None.

PR surface

Source +222, Tests +1963, Docs +6, Other +2. Total +2193 across 20 files.

View PR surface stats
Area Files Added Removed Net
Source 7 571 349 +222
Tests 10 2005 42 +1963
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 2 4 2 +2
Total 20 2586 393 +2193

Review metrics

Metric Value Why it matters
Production versus test delta production +571/-349 (net +222); tests/support +2005/-42; docs/tooling +10/-2 The production growth is concentrated in the node recovery/catalog owner and shared lifecycle extraction, so it needs explicit owner acceptance.

Stored data model

Persistent data-model change detected: serialized state: src/agents/agent-bundle-mcp-materialize.ts, serialized state: src/agents/mcp-content.ts, serialized state: src/agents/node-plugin-tools.ts, serialized state: test/e2e/qa-lab/runtime/gateway-node-mcp.fixture.mjs. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #125044
Summary: This PR is the linked candidate repair for the current node-host MCP catalog and session recovery bug.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Accept the reviewed recovery boundary (recommended)
    Merge with owner approval, accepting the bounded reconnect and catalog-republication behavior validated by the PR's real-process proof.
  2. Pause for lifecycle simplification
    Keep this PR open if maintainers want a smaller canonical recovery owner before changing node MCP availability behavior.

Technical review

Best possible solution:

Keep one shared lifecycle/result-projection path and one node-local catalog recovery owner, then land after protected maintainer approval.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: current main performs initial listing and only withdraws descriptors on close, leaving no live refresh or reconnect path. This review did not execute it because node_modules are absent.

Is this the best way to solve the issue?

Yes, as far as source establishes: session/requester ownership stays separate while shared lifecycle work is extracted once and node process recovery remains local. Direct MCP SDK inspection is the remaining reviewer-side limitation.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against ac5c8be00196.

Labels

Label justifications:

  • P1: The current node-host MCP path leaves dynamic catalogs stale and expired sessions unusable until an operator restart.
  • merge-risk: 🚨 session-state: The PR changes stateful Streamable HTTP expiry classification, client retirement, and subsequent session replacement.
  • merge-risk: 🚨 availability: The PR changes node-host connection teardown, retries, and catalog withdrawal/republication after transport failure.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body reports an after-fix isolated Gateway plus real node-process E2E across all three supported MCP transports, including recovery and cleanup behavior.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body reports an after-fix isolated Gateway plus real node-process E2E across all three supported MCP transports, including recovery and cleanup behavior.

Evidence

What I checked:

  • Current-main defect: Current main lists node MCP tools only during startup; its close callback removes descriptors but does not reconnect or refresh the catalog. (src/node-host/mcp.ts:321, ac5c8be00196)
  • Canonical repair boundary: The PR makes the node process own serialized catalog refresh, descriptor replacement, teardown, and bounded reconnect while reusing placement-neutral lifecycle primitives. (src/node-host/mcp.ts:301, 2a4005519d52)
  • Real-process coverage: The added E2E starts an isolated Gateway and real node process, exercises stdio, SSE, and Streamable HTTP, then verifies catalog replacement, expiry recovery without replay, and process cleanup. (test/e2e/qa-lab/runtime/gateway-node-mcp.e2e.test.ts:171, 2a4005519d52)
  • Feature provenance: Blame attributes the current one-shot node-host MCP implementation to the original feature commit, whose close path withdraws descriptors without recovery. (src/node-host/mcp.ts:321, 9e4ba15f4c37)
  • Release scope: Neither the original node-host implementation nor this PR head is contained in the latest supplied release v2026.7.1-2; the defect and repair are main/PR-only. (2a4005519d52)
  • Dependency signal and local limitation: The branch directly imports the MCP SDK for HTTP session classification and lifecycle control. This checkout has no node_modules and network DNS failed, so its installed SDK source and tests could not be independently rerun. (src/agents/mcp-client-lifecycle.ts:1, 2a4005519d52)

Likely related people:

  • Patrick Erichsen: Git blame attributes the current node-host MCP manager and its one-shot close behavior to the original feature commit. (role: introduced node-host MCP behavior; confidence: high; commits: 9e4ba15f4c37; files: src/node-host/mcp.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-17T06:28:55.388Z sha 2a40055 :: needs maintainer review before merge. :: none

@steipete

Copy link
Copy Markdown
Contributor Author

Maintainer merge review is complete for exact head 2a4005519d52d396d926ff2d3970559a4d9f67b4.

Evidence:

Dependency contract confirmation for the ClawSweeper rank-up move:

  • The installed package is @modelcontextprotocol/sdk 1.30.0. Its Streamable HTTP transport preserves HTTP status in StreamableHTTPError, exposes the active session ID, sends Mcp-Session-Id on stateful requests, and implements explicit DELETE termination while accepting HTTP 405. Its protocol request path observes AbortSignal, emits request-timeout errors, owns transport startup, and closes when initialize fails.
  • I also directly inspected sibling Codex commit 92cbfb4d2431: its HTTP adapter classifies 404 as session expiry only when a session ID was sent, implements DELETE termination, and its client serializes session reinitialization and shuts down owned stdio processes. Codex retries an operation after recovery; OpenClaw intentionally does not replay the call that discovers expiry, because a tool call may have side effects. Only later calls use the republished replacement session.

The +222 net production lines are accepted as the smallest coherent owner boundary after the simplification passes: shared lifecycle/result projection replaces duplicate placement code, while the node-local state machine adds the missing process-lifetime catalog refresh, stale-session fencing, bounded retry, and reconnect ownership. ClawSweeper reported no code findings; its dependency-contract, positive-LOC, maintainer-review, and exact-head-CI items are now resolved.

Authenticated external-model proof remains explicitly limited: both approved OpenAI keys reached the real Responses endpoint but returned HTTP 401, so this PR does not claim a successful external-model call.

@steipete
steipete merged commit ee86b24 into main Aug 17, 2026
231 checks passed
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@steipete
steipete deleted the steipete/node-mcp-architecture-cleanup-20260816 branch August 17, 2026 08:39
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 18, 2026
* fix(node-host): recover MCP catalogs and sessions

Share placement-neutral MCP lifecycle and result projection while keeping Gateway session ownership and node process ownership separate. Refresh node catalogs live, recover closed or expired transports without replay, and preserve MCP application errors across node.invoke.\n\nFixes openclaw#125044

* test: register node MCP CI inventory

* fix(node-host): stop MCP recovery after abort
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. plugin: file-transfer proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Node-hosted MCP catalogs and HTTP sessions do not recover live

1 participant