Repository navigation
fix(mcp): stop unused servers from accumulating across sessions - #150364
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, 3:16 AM ET / 07:16 UTC (Revision 7). ClawSweeper reviewWhat this changesPrevents wholly denied MCP servers from connecting and retires unused discovery connections while preserving prepared tools and requester connections until session closure. Merge readiness✅ Ready for maintainer review This remains a useful repair beyond the related merged fixes. The prior requester-disposal concern is resolved, the supplied production-path proof supports the intended lifecycle, and no blocking introduced defect was found. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw’s MCP runtime connects configured external tool servers to agent sessions. Tool policy controls discovery, and the session lifecycle owns connection reuse and cleanup. flowchart TD
A[Server configuration] --> C[Policy-aware discovery]
B[Conversation tool policy] --> C
C --> D[Final prepared tool bundle]
D --> E[Retain selected connections]
D --> F[Retire unused unleased connections]
E --> G[Session closes]
G --> H[Release remaining connections]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +105, Tests +461, Docs +2. Total +568 across 25 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep connection selection and selective retirement within the existing session owner, preserving callable peers, credential revalidation, and final session cleanup. Do we have a high-confidence way to reproduce the issue? Yes, source inspection identifies the denied-server discovery and unused-connection paths, and the supplied before/after evidence exercises them through production preparation entrypoints. This read-only review did not independently execute them. Is this the best way to solve the issue? Yes. The patch extends the existing policy and lifecycle owners, preserves session reuse, and fixes the earlier requester-preflight regression without adding another cleanup mechanism. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 67ecde756632. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (6 earlier review cycles)
|
4ebedf4 to
8a18f59
Compare
d40a04d to
0500f0c
Compare
Retire native policy discovery runtimes after their leases release, and carry prepared server denials through connection setup and status without renaming surviving servers. Related: #142965. Thanks to @michaeljgood71 and @terrencehinds99 for the completed-session and denied-agent traces.
Keep final bundle members and their OAuth context live. Retire only unleased discovery exclusions after final projection, using exact runtime ownership and releasing empty capacity slots. Existing session-close paths retire the remaining servers. Preserve the unchanged native OAuth contracts and prove preparation, selective cleanup, and session closure with real child processes. Related: #142965.
0500f0c to
46791e8
Compare
|
Merged via squash.
|
Stabilize the MCP catalog recovery regression under busy CI workers. The fixture previously raced the final healthy HTTP call against a 50 ms wall-clock deadline and observed server response submission before client catalog publication. Synchronize six intentional timeouts with observed HTTP request arrival, retain the real 500 ms overlap window and single-flight assertion, and await the published catalog before successful tool execution. Extract the HTTP fixture so the oversized test file shrinks without a baseline change or suppression. Production behavior, timeout values, configuration, dependencies, and schemas are unchanged. This was a pre-existing fixture timing race exposed under load, not a regression from #150364. Production LOC: 0; tests and support: +186/-179. Validation: controlled 100 ms response stalls failed before and passed after on Linux and macOS; 99 session-reset tests and changed checks passed. The PR records 14 Linux and seven macOS original-shard passes; macOS attempt eight hit the separate untouched reload-marker failure, while this target passed. The separate marker test passed its single isolated check. Exact-head CI run 35221633216 is green with zero pending checks. The accepted Codex review is scoped-clean and ClawSweeper reported no actionable findings or before-merge items. Related: #150364 CI: https://github.com/openclaw/openclaw/actions/runs/35221633216
Remove serverless MCP facades after joined cleanup while preserving requester sign-in capabilities and current replacement ownership. Clear session-key bindings once admission drains, and avoid republishing metadata for a removed runtime. Fix pre-existing retention exposed by #150364. Preserve lifecycle and idle-policy assertions with configured server fixtures and track the original memory-to-requester test order without a consumer reset. Validation: 20 ordered before/after runs on macOS and Linux, Linux two-worker repetition, CPU-pressure proof on both platforms, 431 focused tests, changed checks, and clean P1 review.
* fix(mcp): stop retaining empty session runtimes Remove serverless MCP facades after joined cleanup while preserving requester sign-in capabilities and current replacement ownership. Clear session-key bindings once admission drains, and avoid republishing metadata for a removed runtime. Fix pre-existing retention exposed by #150364. Preserve lifecycle and idle-policy assertions with configured server fixtures and track the original memory-to-requester test order without a consumer reset. Validation: 20 ordered before/after runs on macOS and Linux, Linux two-worker repetition, CPU-pressure proof on both platforms, 431 focused tests, changed checks, and clean P1 review. * fix(mcp): retain empty runtimes until handles release Keep a drained facade registered while its retained lease is live. Reap empty unleased partitions through the existing handle-release completion path without arming whole-session retirement or retiring useful siblings. Add forced-order boundary coverage for retained handles, concurrent session-key rebinding, and static native preflight. The retained-handle case failed at 185afaf; rebinding and preflight passed. All three now pass, along with 194 regression/sibling tests and changed checks. * fix(mcp): align retirement fixtures with runtime ownership * fix(mcp): configure remaining runtime lifetime fixtures
…claw#150364) Prevent wholly denied MCP servers from starting and retire excluded, unleased discovery connections through the existing session lifecycle owner. Keep final prepared tools and their OAuth context callable until session cleanup, and preserve requester connections and their advertised catalog during static native preflight. Requester acquisition owns catalog reconciliation; omitting that partition from native preparation does not revoke it. Exact runtime ownership and active leases protect useful peers and replacements, while final session cleanup closes the remaining connections and owned stdio process trees. No configuration, TTL default, dependency, schema, or data migration changes. Related: openclaw#142965 Closes openclaw#147041 Thanks to @michaeljgood71 and @terrencehinds99 for the completed-session and denied-agent traces. Validation: 313 focused tests across 15 files and check-changed passed; repeated native/OAuth lifecycle proof preserved callable tools and returned every session to zero live children. The mixed HTTP regression verifies requester calls after native preflight. Nine existing lifecycle tests additionally cover openclaw#147041's stdio process-tree cleanup. Exact-head CI run 35193052654 is green, and native hosted CI/Testbox preparation passed at 46791e8.
Stabilize the MCP catalog recovery regression under busy CI workers. The fixture previously raced the final healthy HTTP call against a 50 ms wall-clock deadline and observed server response submission before client catalog publication. Synchronize six intentional timeouts with observed HTTP request arrival, retain the real 500 ms overlap window and single-flight assertion, and await the published catalog before successful tool execution. Extract the HTTP fixture so the oversized test file shrinks without a baseline change or suppression. Production behavior, timeout values, configuration, dependencies, and schemas are unchanged. This was a pre-existing fixture timing race exposed under load, not a regression from openclaw#150364. Production LOC: 0; tests and support: +186/-179. Validation: controlled 100 ms response stalls failed before and passed after on Linux and macOS; 99 session-reset tests and changed checks passed. The PR records 14 Linux and seven macOS original-shard passes; macOS attempt eight hit the separate untouched reload-marker failure, while this target passed. The separate marker test passed its single isolated check. Exact-head CI run 35221633216 is green with zero pending checks. The accepted Codex review is scoped-clean and ClawSweeper reported no actionable findings or before-merge items. Related: openclaw#150364 CI: https://github.com/openclaw/openclaw/actions/runs/35221633216
* fix(mcp): stop retaining empty session runtimes Remove serverless MCP facades after joined cleanup while preserving requester sign-in capabilities and current replacement ownership. Clear session-key bindings once admission drains, and avoid republishing metadata for a removed runtime. Fix pre-existing retention exposed by openclaw#150364. Preserve lifecycle and idle-policy assertions with configured server fixtures and track the original memory-to-requester test order without a consumer reset. Validation: 20 ordered before/after runs on macOS and Linux, Linux two-worker repetition, CPU-pressure proof on both platforms, 431 focused tests, changed checks, and clean P1 review. * fix(mcp): retain empty runtimes until handles release Keep a drained facade registered while its retained lease is live. Reap empty unleased partitions through the existing handle-release completion path without arming whole-session retirement or retiring useful siblings. Add forced-order boundary coverage for retained handles, concurrent session-key rebinding, and static native preflight. The retained-handle case failed at 185afaf; rebinding and preflight passed. All three now pass, along with 194 regression/sibling tests and changed checks. * fix(mcp): align retirement fixtures with runtime ownership * fix(mcp): configure remaining runtime lifetime fixtures
Related: #142965
Closes #147041
What Problem This Solves
Agents can start MCP servers that their tool policy wholly denies, and native discovery can leave excluded servers alive outside the final prepared bundle. Mixed static/requester setups also need their advertised requester tools to remain callable after static native preflight.
User Impact
Wholly denied servers never start. Prepared native MCP servers, including their OAuth context, remain connected for the session and retire when the session closes. Unleased discovery-only servers outside the final bundle can close earlier without interrupting useful peers. Static native preflight preserves the separate requester connections and advertised catalog.
Thanks to @michaeljgood71 and @terrencehinds99 for the completed-session and denied-agent traces.
Why This Change Was Made
Both native preparation paths compute retained membership after final policy and OAuth projection. Releasing the acquisition passes that membership to its exact runtime owner, which retires only excluded, unleased servers and releases an empty owner's capacity slot. Current-owner checks protect replacements; composite cleanup joins every acquired partition before reporting failure.
The acquisition owner no longer interprets an omitted requester partition as removal: native preflight deliberately supplies a static-only projection. Requester acquisition owns reconciliation of its advertised catalog. Existing config publication and credential revalidation retain actual removal/revocation authority, and the existing per-server retirement diagnostic records retirement at that owner.
The final bundle's servers remain under the existing session lifecycle owner. CLI/embedded run-end, reset, explicit Stop, and Gateway shutdown still perform session retirement independently of an unset idle TTL. Preparation failure releases its lease without asserting that the prepared bundle is empty. Whole-server denials gate connection setup using prepared policy facts and stable full-declaration names;
tools.effectiveconsumes the same facts.No configuration option, environment surface, TTL default, dependency, schema, or process reaper changed. The isolated-heartbeat leak is already fixed by #143433 (
109972b2aa0); #150306 covers stalled-relay escalation, and #150339 covers the shared incoming MCP HTTP listener. This candidate runtime repair needs no updater-driver marker or data migration.Evidence
Coverage for #147041: configured stdio servers (including
npxlaunchers) share the session lifecycle ownerdisposeMcpClient→closeOwnedStdioProcess; all 9 selected existing lifecycle tests passed once on46791e8eff8e, includingbundle-mcp.discovery-lifecycle.test.tsandmcp-stdio-transport.process.test.ts, confirming synthetic process-tree extinction after cleanup while preserving active and requester leases.The mixed-server regression runs the real requester harness materialization followed by the real native app-server preflight with the same session/sender. It uses a local HTTP MCP fixture and isolated state.
5830d95542c)bundle-mcp runtime disposed for session mixed-native-discoveryApplied the sole Rank-up move in ClawSweeper's review of
5830d95542c: removed projection-triggered requester disposal and added a mixed static/requester regression that executes the requester tool after native preparation. No rank-up moves skipped.The previous CI failures (
localToolsempty and OAuthread_docsmissing immediately after preparation) remain covered. Both unchanged OAuth contract tests passed 10/10 each. Both real-stdio native lifecycle cases (app-server and CLI) also passed 10/10 each:node scripts/run-vitest.mjs src/agents/cli-runner/bundle-mcp.user-config.test.ts \ src/agents/cli-runner/bundle-mcp.discovery-lifecycle.test.ts \ -t 'omits unavailable OAuth servers without blocking the CLI agent|keeps native OAuth refresh available while projecting the child bearer|keeps prepared servers usable until session end' \ --repeats 9Across those lifecycle repeats, 60 allowed sessions retained two callable servers after preparation, retired one excluded discovery server, and returned to zero live server/anchor/relay PIDs after every session. 20 wholly denied sessions started zero servers. Owner tests also cover active leases, stale acquisitions, unchanged transport reuse, true revocation, and 257 empty releases without capacity exhaustion.
node scripts/check-changed.mjspassed in full: production/test typechecks, lint, line-cap checks, and every selected guard. No extension-lint substitution was needed.--mode branch --base origin/main --max-priority P1) is scoped-clean at4ebedf45663cf0b894093739e7e2a1eee3e2ae99, with no actionable P0/P1 findings.The earlier isolated Gateway proof remains relevant to unchanged gating/session-end paths: denied starts fell from two to zero with the same 36 model-visible tools; three ordinary chat/reset cycles and three isolated heartbeats returned to zero relays/servers after closure. It used the built-in runtime and a local mock provider. No operator Gateway or live model service was used.
This follow-up: production +16/-19 (net -3); tests +173/-0. PR total: production +313/-208 (net +105), tests +467/-6 (net +461), docs +2. The remaining production growth belongs to prepared policy gating and selective cleanup through existing owners; this correction removes the extra disposal path. No suppression or baseline was added. Lazy imports and package boundaries are unchanged, so no full build was needed for this follow-up.
Sibling follow-up remains sandbox-browser provisioning at
src/agents/sandbox/context.ts:333: its explicit retained-container lifetime requires separate treatment. CUA/LSP execution cleanup, browser profile ownership, and host-exec command scopes were preserved.