fix: dispose bundled MCP servers after every embedded run end#21
Open
EronFan wants to merge 1539 commits into
Open
fix: dispose bundled MCP servers after every embedded run end#21EronFan wants to merge 1539 commits into
EronFan wants to merge 1539 commits into
Conversation
Root cause: cleanupBundleMcpOnRunEnd was gated behind a flag, causing MCP stdio servers spawned per session to accumulate unboundedly when the flag was false or unset. Every session created orphaned MCP processes consuming RAM (reported 2.4GB from a single context7-mcp instance). Fix: always call disposeSessionMcpRuntime() in the run finally block, removing the conditional cleanupBundleMcpOnRunEnd flag and making session cleanup unconditional. Also removes the now-unnecessary flag from RunEmbeddedPiAgentParams and cleans up all test references. Affected files: - run.ts: remove flag guard, always call disposeSessionMcpRuntime - params.ts: remove cleanupBundleMcpOnRunEnd from RunEmbeddedPiAgentParams - attempt-execution.ts / types.ts / agent-via-gateway.ts: remove flag - e2e.test.ts / agent.test.ts: remove test references to the flag Fixes openclaw#69465
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause
MCP stdio servers spawned per session via npx were never cleaned up when sessions end because
cleanupBundleMcpOnRunEndwas gated behind a flag that defaulted to false/unset. Orphaned processes accumulated unboundedly (reported 2.4GB RAM from a single context7-mcp instance, gateway OOM kill over time).Fix
Always call
disposeSessionMcpRuntime()in the run finally block, removing the conditionalcleanupBundleMcpOnRunEndflag. This makes session cleanup unconditional for all embedded runs.Changes
run.ts: remove flag guard, always calldisposeSessionMcpRuntimeparams.ts: removecleanupBundleMcpOnRunEndfromRunEmbeddedPiAgentParamsattempt-execution.ts/types.ts/agent-via-gateway.ts: remove flag propagatione2e.test.ts/agent.test.ts: remove test references to the flagTest coverage
Existing tests updated to remove the now-unnecessary
cleanupBundleMcpOnRunEndparam; all other tests remain unchanged (cleanup is now unconditional, tests still pass).Fixes openclaw#69465