Repository navigation
fix(mcp): stop retaining empty session runtimes - #150901
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:42 PM ET / 16:42 UTC (Revision 5). ClawSweeper reviewWhat this changesRemove empty MCP session runtime records after cleanup while preserving active handles and requester sign-in capabilities, and update lifecycle regression fixtures. Merge readiness✅ Ready for maintainer review This remains a useful, distinct runtime cleanup fix. The earlier retention concern is addressed, and no blocking correctness defect was found. The merged memory cleanup does not replace this manager-level repair. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw’s MCP runtime manager connects agent sessions to external tool servers and owns their cached runtimes and cleanup. Agent acquisition, configuration reload, and handle release determine which connections and session bindings remain available. flowchart TD
A[Agent session and server configuration] --> B[MCP runtime manager]
B --> C[Tool servers and retained handles]
C --> D[Handle release or configuration reload]
D --> E[Join cleanup and check current ownership]
E --> F{Servers, handles, or sign-in capabilities remain?}
F -->|Yes| G[Keep runtime registered]
F -->|No| H[Remove empty runtime and unused binding]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +26, Tests +444. Total +470 across 18 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep empty-record reclamation in the MCP lifecycle owner while preserving useful server connections, active handles, and revocable requester sign-in capabilities. Do we have a high-confidence way to reproduce the issue? Yes, source establishes the empty-record retention path, and the acquisition regression checks it before teardown. Historical before-and-after runs are supplied; this read-only review did not execute a current-main reproduction. Is this the best way to solve the issue? Yes. The repair extends the existing cleanup owner and protects live handles, replacement identity, and requester capabilities without adding a parallel cleanup mechanism. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a1cc9b38c1c8. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
cf5467c to
a95974e
Compare
Fix an intermittent Gateway restart benchmark test failure when a busy runner delays the healthy fixture response beyond the real probe deadline. Supply one healthy observation through the existing requestProbeStatus export and derive readiness from that observation. Preserve the real waitForRestartProbe flow, existing timing and downtime assertions, and separate HTTP deadline and recovery tests. Restore the spy in finally and assert no error or further polling. No user-visible or runtime change. Production/tooling: +0/-0; tests: +15/-18. Related: #150901. Validation: exact-head CI run 35244901923 passed; recorded proof includes 33/33 macOS tests, 1,284 Linux shard tests, and 660 tests across 20 Linux pressure runs. Independent review was scoped-clean and ClawSweeper found no actionable defects.
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.
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.
a95974e to
196ca3a
Compare
…#150985) Fix an intermittent Gateway restart benchmark test failure when a busy runner delays the healthy fixture response beyond the real probe deadline. Supply one healthy observation through the existing requestProbeStatus export and derive readiness from that observation. Preserve the real waitForRestartProbe flow, existing timing and downtime assertions, and separate HTTP deadline and recovery tests. Restore the spy in finally and assert no error or further polling. No user-visible or runtime change. Production/tooling: +0/-0; tests: +15/-18. Related: openclaw#150901. Validation: exact-head CI run 35244901923 passed; recorded proof includes 33/33 macOS tests, 1,284 Linux shard tests, and 660 tests across 20 Linux pressure runs. Independent review was scoped-clean and ClawSweeper found no actionable defects.
* 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: #150364. Observed in #150819 / run 35212277809 and #150244 / run 35217608611.
What Problem This Solves
Fixes empty MCP runtime records accumulating after serverless agent runs, which made a later session's cleanup assertion fail when the memory-transcript and requester-lifecycle tests shared a worker.
User Impact
Serverless and hidden memory sessions no longer leave empty MCP runtime records behind. Prepared tools, active server ownership, and requester sign-in capabilities retain their existing lifetimes. No configuration, dependency, schema, migration, or timeout changes are required.
Why This Change Was Made
The manager released connection capacity without removing empty runtime entries, and skipped cleanup entirely for entries that never consumed capacity. It now joins cleanup, rechecks the current owner, removes empty entries and connection metadata only after their retained handles release, and clears session-key bindings after admission drains. Sign-in-only requester runtimes remain tracked so configuration changes can revoke their capabilities.
This retention predates #150364; that PR added the assertion which exposed it. The four leftovers belonged to the earlier memory test: three
internal-session-effects-*entries andprivate-memory-source. The requester test's own HTTP sessions had already closed successfully.The regression preserves the original file order in one worker without a consumer reset. Existing lifetime and TTL tests now use configured server fixtures; their assertions remain. Idle-policy tests moved into a smaller file, reducing the large runtime test by 61 lines.
Evidence
The original campaign evidence below is for
185afaf795157f79dbc3a750c5879f3c83070096; the follow-up boundary proof is recorded separately below.The order was memory-transcript first, requester-lifecycle second, using the unit-fast configuration with isolation disabled and one worker. Linux also passed 20 repetitions of the requester file with CI's two-worker settings. Both platforms passed the original-order probe with eight CPU-burner processes active.
431 unit tests across 29 files have passing results, covering CLI-runner bundle MCP, MCP runtime/acquisition/reload, memory transcripts, and session-reset cleanup/concurrency. The initial broad run exposed 14 stale empty-fixture assertions; the repaired runtime/idle suites passed all 128 tests, and the remaining CLI partitions passed all 60 tests.
node scripts/check-changed.mjspassed on the final change. Fresh Codex autoreview with--mode branch --base origin/main --max-priority P1is scoped-clean at commit185afaf795157f79dbc3a750c5879f3c83070096.Linux Testbox run: command proofs completed with exit 0. A portal metadata sync timed out after the final successful command; the lease was stopped.
Reproduction command and representative leftovers
The original repeated command was:
OPENCLAW_VITEST_FS_MODULE_CACHE_PATH="$PWD/.artifacts/l588/vitest-cache" \ node scripts/run-vitest.mjs run \ --config .artifacts/l588/original-order.config.ts --reporter=verbose \ src/auto-reply/reply/agent-runner-memory.private-transcript.test.ts \ src/agents/cli-runner/bundle-mcp.requester-lifecycle.test.tsThat temporary config extends unit-fast and forces the stated file order,
maxWorkers: 1, andisolate: false. The tracked equivalent is exercised by:Representative pre-fix keys:
Production LOC: +28/-9. Tests and support: +224/-97, including the idle-policy test move. Changelog remains release-owned.
Follow-up lifecycle boundary proof
Review requested three forced-order checks against the original PR head. They exercise real HTTP MCP transports and the registered native CLI preflight, without replacing manager ownership decisions with mocks.
retains an empty runtime until its live materialized handle releasespreserves a newer session binding while old empty cleanup drainspreserves the runtime admitted by an in-flight static native preflightThe retained-handle check found a real gap: transport cleanup freed capacity and removed the facade despite its active lease. The manager now retains that binding until the final handle releases, then reaps empty unleased partitions through the existing release-completion path. It does not arm whole-session retirement or remove live siblings. Configuration removal still revokes removed tools; the retained facade remains readable.
The rebinding test admits a new session with the same session key and server name while the old DELETE is held. The preflight test holds the real
tools/listrequest open across cleanup and verifies the admitted runtime remains registered and callable after preparation. All 194 tests in the eight-file follow-up regression/sibling selection passed, including the original cross-file memory/requester regression.At
d8e2d6650eb7eee5a41baa729845e341b5e0a19e, changed-file checks passed and fresh Codex autoreview (--mode branch --base origin/main --max-priority P1) is scoped-clean.CI fixture repairs
Run 35227538461 at
d8e2d6650eb7eee5a41baa729845e341b5e0a19efailed the unused-file guard and seven shards. Each failed job log was inspected. All seven contain assertion failures caused by fixtures relying on retained empty runtimes; none is a worker timeout, unhandled rejection, class #66, or shared infrastructure failure.expected undefined to be { sessionId: 'rotated-session' ... }mcp-connection-resolver.test.ts:268—expected undefined to be definedpeekSessionobserves. Inspect the actual requester runtime key; retain the real authenticated requester calls and revocation assertions.owns MCP predecessor cleanup after rotation/unchanged/cancel-after-commit—expected undefined to be { ... }expected [] to include 'session:subagent:mcp-retire'retires only run-owned IDs when cleanup is false/true—expected undefined to be { ... }expected undefined to be { sessionId: 'idle-mcp' ... }expected [] to include 'stale-runtime-session'The existing manager test-support module now shares the unopened-server configuration across these suites. No additional production change was needed. The one-use
agent-bundle-mcp-retention.test-support.tsis deleted; its sole consumer creates the same ordered Vitest configuration in its existing tracked temporary directory. The original memory-before-requester worker boundary, isolation settings, and assertions remain.Local proof for this fixture repair: 454 tests across ten files passed, including all seven failed CI suites, the original shared-worker order regression, and all three lifecycle boundary checks. After the final requester-key and session-fixture edits, both affected files passed again (240 tests); the authenticated plugin-revocation case completed in 620 ms.
pnpm deadcode:fullpassed on the final diff, and the exact CI unused-file guard passed both production and full-tree scans with zero entries. Follow-up LOC: production +0/-0; tests/support +79/-63.At
cf5467c9446dc639c391c1b4e9b5d3b8a1a0dcc5,node scripts/check-changed.mjspassed in full. Fresh Codex autoreview (--mode branch --base origin/main --max-priority P1) is scoped-clean on the committed branch. The local pre-commit P1 review was also scoped-clean. Hosted CI on this head is the final platform check; the lane stops at its first terminal state without rerunning jobs.Hosted follow-up: remaining fixture assumptions
Run 35231526382 used CI merge
8f854c40a7588fc1bc06ed3ebaf69dd2c9c8004d(PR headcf5467c9446dc639c391c1b4e9b5d3b8a1a0dcc5merged into base9bea925e27aa632f37e99a7d2698e5f912f71d94). All three failed job logs were read.cli-runner.before-agent-reply-cron.test.ts:985, “does not retire a newer MCP runtime after its stable session key is rebound”:expected undefined to be { …(27) }servers: {}. The successor-by-ID assertion failed before the key assertion. The test now uses the shared unopened-server configuration and also asserts the rebound key before old-run cleanup.agent-runner-memory.private-transcript.test.ts:289, “keeps completed optional memory inference out of the next human turn” and “keeps interrupted optional memory inference out of the next human turn”:expected false to be trueagent-bundle-mcp-retention.test.ts:65, “does not retain memory-session MCP runtimes across shared-worker files”:expected 1 to be +0; its child reports the same two memory cases andexpected false to be trueThe branch is rebased onto main commit
077604ff7dc60b504d023b18b28beeb716f70848, bringing in #150899's memory lifetime assertions. No additional manager change was needed: binding removal already checks the currently mapped session ID, and CLI settlement retires the immutable original session ID. All existing assertions remain.Memory preparation materializes MCP catalogs before inference, so a bare unresponsive subprocess would introduce a connection timeout. Its existing synthetic HTTP fixture now serves a valid stateless MCP endpoint with an empty tool catalog. The runtime therefore owns a real server while the model request keeps the same tool inventory.
Hosted CI is the runtime proof of record for this follow-up, per maintainer direction. No local suites were run: the preceding head and merge-base attempts both stopped before assertions at the 120-second no-output watchdog under host overload. This follow-up changes tests only (+41/-2 LOC).
At
a95974e7ed6d4bef767b48109b39de66c2c0a90d,pnpm check:changedpassed in full. Fresh Codex autoreview (--mode branch --base origin/main --max-priority P1) is scoped-clean on the committed branch; the local P1 review is also scoped-clean. The next hosted pull-request run supplies the runtime proof. The lane stops at the native watcher's first terminal state without rerunning jobs or landing.