Skip to content

fix: dispose bundled MCP servers after every embedded run end#21

Open
EronFan wants to merge 1539 commits into
mainfrom
fix/69465-mcp-stdio-cleanup
Open

fix: dispose bundled MCP servers after every embedded run end#21
EronFan wants to merge 1539 commits into
mainfrom
fix/69465-mcp-stdio-cleanup

Conversation

@EronFan

@EronFan EronFan commented Apr 20, 2026

Copy link
Copy Markdown
Owner

Root cause

MCP stdio servers spawned per session via npx were never cleaned up when sessions end because cleanupBundleMcpOnRunEnd was 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 conditional cleanupBundleMcpOnRunEnd flag. This makes session cleanup unconditional for all embedded runs.

Changes

  • 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 propagation
  • e2e.test.ts / agent.test.ts: remove test references to the flag

Test coverage

Existing tests updated to remove the now-unnecessary cleanupBundleMcpOnRunEnd param; all other tests remain unchanged (cleanup is now unconditional, tests still pass).

Fixes openclaw#69465

steipete added 30 commits April 20, 2026 16:58
steipete and others added 30 commits April 20, 2026 21:33
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: MCP stdio server processes orphaned on session end — 2.4GB RAM leak from context7-mcp