codex - 💡(How to fix) Fix MCP servers started for Codex subagents remain running after the subagent completes and close_agent succeeds [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

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
openai/codex#19092Fetched 2026-04-24 06:01:08
View on GitHub
Comments
1
Participants
2
Timeline
7
Reactions
0
Timeline (top)
labeled ×4closed ×1commented ×1cross-referenced ×1
RAW_BUFFERClick to expand / collapse

What version of Codex CLI is running?

codex --v0.122.0

What subscription do you have?

pro

Which model were you using?

No response

What platform is your computer?

macOS

What terminal emulator and version are you using (if applicable)?

No response

What issue are you seeing?

In Codex multi-agent mode, MCP server processes started for a subagent appear to remain alive after the subagent has completed and close_agent has successfully returned.

Observed behavior: A subagent is spawned and initializes configured MCP servers, such as chrome-devtools-mcp, @playwright/mcp, tavily-mcp, etc. The subagent finishes its task. close_agent is called and returns a completed status. The MCP server processes started around the subagent launch time are still running in the background. These processes remain children of the parent Codex process rather than being cleaned up with the closed subagent. This causes MCP processes to accumulate when multiple subagents are spawned concurrently. Over time, this can lead to unnecessary memory and process usage, browser/tooling contention, and confusing background state until the parent Codex process exits or the MCP processes are manually terminated.

What steps can reproduce the bug?

After a subagent is closed, its associated MCP servers and related configured resources should not remain as background residual processes.

What is the expected behavior?

When a subagent completes and is closed, any MCP servers or related resources that were started specifically for that subagent should be terminated or released, unless they are still actively shared by another live thread.

Additional information

No response

extent analysis

TL;DR

The issue can be mitigated by ensuring proper cleanup of MCP server processes after a subagent is closed, potentially by modifying the close_agent function or adding an additional cleanup step.

Guidance

  • Investigate the close_agent function to verify it properly terminates or releases MCP server processes associated with the subagent.
  • Check for any shared resources or threads that might be preventing MCP servers from being terminated after a subagent is closed.
  • Consider adding a cleanup step after close_agent returns to explicitly terminate any remaining MCP server processes.
  • Review the Codex multi-agent mode documentation to ensure correct usage and configuration of MCP servers and subagents.

Example

No code snippet can be provided without more context about the close_agent function or the Codex API.

Notes

The exact solution depends on the implementation details of the close_agent function and the Codex API, which are not provided in the issue description.

Recommendation

Apply workaround: Modify the close_agent function or add an additional cleanup step to ensure proper termination of MCP server processes after a subagent is closed, as the root cause of the issue seems to be related to resource cleanup rather than a version-specific bug.

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