openclaw - ✅(Solved) Fix sessions_spawn: MCP child processes not reaped after spawned run ends (cleanupBundleMcpOnRunEnd never set) [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#68827Fetched 2026-04-19 15:06:57
View on GitHub
Comments
0
Participants
1
Timeline
2
Reactions
0
Participants
Timeline (top)
cross-referenced ×1referenced ×1

MCP server processes (npx-based) accumulate in memory after cron-triggered spawned agent sessions complete. Each process holds ~96-100MB RSS. After several cron cycles, this results in 100+ zombie MCP processes consuming 2-3GB of container RAM.

Root Cause

Root Cause (traced from source)

In src/agents/pi-embedded-runner/run.ts (lines 2062-2070), disposeSessionMcpRuntime() is gated behind cleanupBundleMcpOnRunEnd === true. This flag is never set on the sessions_spawn path.

Fix Action

Fixed

PR fix notes

PR #68846: fix: reap MCP child processes when spawned session run ends

Description (problem / solution / changelog)

Fixes #68827

Problem

MCP server processes (npx-based) accumulate in memory after cron-triggered spawned agent sessions complete. Each process holds ~96-100MB RSS. After several cron cycles, this results in 100+ zombie MCP processes consuming 2-3GB of container RAM.

Root Cause

In src/agents/pi-embedded-runner/run.ts, disposeSessionMcpRuntime() is gated behind cleanupBundleMcpOnRunEnd === true. This flag was only set for local one-shot CLI runs (agent-via-gateway.ts), never for spawned sessions via sessions_spawn.

Fix

In src/agents/command/attempt-execution.ts, set cleanupBundleMcpOnRunEnd: true when spawnedBy is present:

cleanupBundleMcpOnRunEnd: params.opts.cleanupBundleMcpOnRunEnd || params.spawnedBy != null,

Tests

2 new tests verifying the flag is correctly set based on spawnedBy presence.

Changed files

  • src/agents/command/attempt-execution.cli.test.ts (modified, +118/-1)
  • src/agents/command/attempt-execution.ts (modified, +1/-1)
RAW_BUFFERClick to expand / collapse

Summary

MCP server processes (npx-based) accumulate in memory after cron-triggered spawned agent sessions complete. Each process holds ~96-100MB RSS. After several cron cycles, this results in 100+ zombie MCP processes consuming 2-3GB of container RAM.

Root Cause (traced from source)

In src/agents/pi-embedded-runner/run.ts (lines 2062-2070), disposeSessionMcpRuntime() is gated behind cleanupBundleMcpOnRunEnd === true. This flag is never set on the sessions_spawn path.

The only place cleanupBundleMcpOnRunEnd: true is explicitly wired is src/commands/agent-via-gateway.ts for local one-shot runs (opts.local === true). There is no equivalent hookup for spawned runs.

cleanup: "delete" on sessions_spawn does not imply cleanupBundleMcpOnRunEnd: true — confirmed by source trace and Krill.

Environment

  • Version: v2026.4.15
  • Setup: hub-and-spoke agents, cron-triggered, maxSpawnDepth:2
  • MCP servers: filesystem, context7, sqlite (all npx-based)

Expected Behavior

When a spawned run ends (regardless of cleanup mode), bundle MCP child processes should be reaped.

Suggested Fix

Wire cleanupBundleMcpOnRunEnd: true into the sessions_spawn run path, mirroring the existing pattern in agent-via-gateway.ts.

extent analysis

TL;DR

Wire cleanupBundleMcpOnRunEnd: true into the sessions_spawn run path to ensure bundle MCP child processes are reaped after a spawned run ends.

Guidance

  • Review the src/agents/pi-embedded-runner/run.ts file, specifically lines 2062-2070, to understand the current implementation of disposeSessionMcpRuntime().
  • Verify that setting cleanupBundleMcpOnRunEnd: true in src/commands/agent-via-gateway.ts for local one-shot runs correctly reaps bundle MCP child processes.
  • Update the sessions_spawn path to include cleanupBundleMcpOnRunEnd: true, mirroring the pattern in agent-via-gateway.ts, to ensure consistent behavior for spawned runs.
  • Test the updated implementation to confirm that bundle MCP child processes are properly reaped after a spawned run ends, regardless of cleanup mode.

Example

No code snippet is provided as the issue already suggests a specific fix and the code changes are implied.

Notes

The suggested fix assumes that the cleanupBundleMcpOnRunEnd flag is the primary mechanism for controlling the reaping of bundle MCP child processes. If other factors are at play, additional investigation may be necessary.

Recommendation

Apply the workaround by wiring cleanupBundleMcpOnRunEnd: true into the sessions_spawn run path, as this directly addresses the identified root cause and is expected to resolve the issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix sessions_spawn: MCP child processes not reaped after spawned run ends (cleanupBundleMcpOnRunEnd never set) [1 pull requests, 1 participants]