openclaw - 💡(How to fix) Fix MCP进程泄漏:gateway session结束时未清理vibe-trading-mcp子进程 [2 comments, 3 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#74798Fetched 2026-05-01 05:41:18
View on GitHub
Comments
2
Participants
3
Timeline
3
Reactions
2
Author
Timeline (top)
commented ×2closed ×1
RAW_BUFFERClick to expand / collapse

问题描述

每次通过飞书等channel调用Vibe-Trading MCP工具时,openclaw-gateway会spawn一个 `vibe-trading-mcp` 子进程。但当session结束时,这些子进程未被回收,持续累积直至变成僵尸进程。

现象:宿主机上 `ps -ef|grep mcp` 可以看到大量残留进程,父进程均为 `openclaw-gateway`,创建时间从某天开始每天新增一个。

根本原因

问题出在 OpenClaw Gateway 的 MCP 生命周期管理:

  1. 泄漏链路:gateway 路由的 session 通过 `getOrCreateSessionMcpRuntime()` 创建 MCP runtime,每次调用 vibe-trading 工具时 spawn `vibe-trading-mcp` 子进程(MCP SDK 的 `StdioClientTransport`)

  2. 缺失清理:当 session 结束时,gateway 侧没有调用 `disposeSessionMcpRuntime()`。`session-reset-service.ts` 的 `emitGatewaySessionEndPluginHook` 只触发了 `session_end` 插件钩子,但没有清理 MCP runtime

  3. 关键代码位置

    • `src/agents/pi-bundle-mcp-runtime.ts`:`disposeSession()` 负责清理 transport/client,应该能杀死子进程
    • `src/gateway/session-reset-service.ts`:session end 路径缺少 `disposeSessionMcpRuntime` 调用
    • `src/commands/agent-via-gateway.ts`:`cleanupBundleMcpOnRunEnd: opts.local === true` 只对本地 embedded runner 生效,gateway 侧远程 session 触不到

环境信息

  • OpenClaw 2026.4.9
  • Gateway 长期运行(不重启),每日处理多轮飞书消息
  • MCP server:vibe-trading(通过 stdio transport)
  • 残留进程示例: ``` saw 685956 527343 0 11:19 ? vibe-trading-mcp (父:openclaw-gateway PID 527343) ```

期望行为

当 gateway session 结束时,应自动清理该 session 创建的 MCP runtime 和子进程,避免进程泄漏和资源浪费。

extent analysis

TL;DR

Calling disposeSessionMcpRuntime() when a session ends is likely to fix the issue of accumulating zombie processes.

Guidance

  • Review the session-reset-service.ts file to ensure that disposeSessionMcpRuntime() is called when a session ends, specifically in the emitGatewaySessionEndPluginHook function.
  • Verify that the disposeSession() function in pi-bundle-mcp-runtime.ts correctly cleans up the transport/client and kills the child process.
  • Check the agent-via-gateway.ts file to see if the cleanupBundleMcpOnRunEnd option can be modified to work with remote sessions.
  • Test the changes by running the gateway and verifying that the child processes are properly cleaned up after a session ends.

Example

// In session-reset-service.ts
emitGatewaySessionEndPluginHook(session) {
  // ...
  disposeSessionMcpRuntime(session);
}

Notes

The fix may require modifications to the OpenClaw Gateway code, specifically in the session-reset-service.ts and pi-bundle-mcp-runtime.ts files. It's essential to test the changes thoroughly to ensure that the child processes are properly cleaned up.

Recommendation

Apply the workaround by calling disposeSessionMcpRuntime() when a session ends, as this is the most direct solution to the problem. This should prevent the accumulation of zombie processes and reduce resource waste.

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 - 💡(How to fix) Fix MCP进程泄漏:gateway session结束时未清理vibe-trading-mcp子进程 [2 comments, 3 participants]