Skip to content

Detailed Windows stdio MCP teardown report with ready patch branch #16144

Open

Description

@leonsong09

What version of Codex CLI is running?

codex-cli 0.117.0

What subscription do you have?

Using an API-key-backed custom provider. Subscription tier does not seem relevant to the reproduction.

Which model were you using?

gpt-5.4

What platform is your computer?

Windows

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

Windows Terminal + PowerShell 7

What issue are you seeing?

On Windows, stdio MCP processes can remain alive after the corresponding MCP client lifecycle should already have ended.

More specifically:

  • dropping a stdio MCP client may leave the launched Windows stdio process tree alive
  • refreshing/replacing MCP servers may also leave the previous stdio MCP launcher tree alive
  • over time, this can accumulate stale launcher / child / grandchild processes

I want to keep the scope narrow:

  • this is not arguing that all active subagents should share one MCP instance
  • this is not proposing MCP pooling / sharing changes
  • this is specifically about Windows stdio MCP lifecycle teardown

What steps can reproduce the bug?

A minimal reproduction shape is:

  1. Configure one or more stdio MCP servers
  2. Start a Codex session that initializes those MCP servers
  3. Trigger a lifecycle path that drops or replaces the MCP client
    • for example MCP refresh / reconnect / replacement / teardown-related paths
  4. Inspect the Windows process tree afterward
  5. Observe that old stdio MCP launcher trees can remain alive

What is the expected behavior?

Once a stdio MCP client is dropped or replaced, the previously launched Windows stdio MCP process tree should be torn down promptly and deterministically.

Repeated refresh / replacement cycles should converge back to a bounded baseline instead of leaving stale Windows stdio MCP stacks behind.

Additional information

Related existing reports:

  • #12976
  • #14233

I already prepared a narrow patch branch focused only on teardown behavior:

  • compare link:
    https://github.com/openai/codex/compare/main...leonsong09:fix/windows-stdio-mcp-teardown?expand=1

The patch direction is intentionally small:

  • implement best-effort Windows process-tree termination for stdio MCP teardown
  • keep a real Windows process guard for stdio RMCP clients
  • tear down the old Windows stdio tree on drop / refresh
  • add regression coverage at:
    • the rmcp-client layer
    • the core MCP refresh / replacement layer

I validated that narrow patch locally with:

  • cargo +stable-x86_64-pc-windows-msvc fmt --all --check
  • cargo +stable-x86_64-pc-windows-msvc check -p codex-utils-pty -p codex-rmcp-client --tests --locked
  • cargo +stable-x86_64-pc-windows-msvc check -p codex-core --tests --locked
  • cargo +stable-x86_64-pc-windows-msvc test -p codex-rmcp-client --test windows_stdio_teardown -- --nocapture
  • cargo +stable-x86_64-pc-windows-msvc test -p codex-rmcp-client --test resources -- --nocapture
  • cargo +stable-x86_64-pc-windows-msvc test -p codex-core refresh_mcp_servers_is_deferred_until_next_turn -- --nocapture
  • cargo +stable-x86_64-pc-windows-msvc test -p codex-core refresh_mcp_servers_reaps_previous_stdio_launcher_tree -- --nocapture

I could not open an upstream PR directly because the repository currently appears to restrict PR creation to collaborators, but the compare branch above is ready if maintainers want to review or cherry-pick from it.

Activity

  1. added
    bugSomething isn't working
    CLIIssues related to the Codex CLI
    windows-osIssues related to Codex on Windows systems
    mcpIssues related to the use of model context protocol (MCP) servers
    on Mar 29, 2026
  2. github-actions commented on Mar 29, 2026

    @github-actions
    Contributor
  3. leonsong09 commented on Mar 29, 2026

    @leonsong09
    Author

    Maintainer follow-up:

    I already have a narrow patch branch ready for this behavior:

    If the direction looks reasonable, a collaborator can open the upstream PR from that compare page directly, or cherry-pick commit:

    • b341247f27307cc51fc6c360e006eae2ae359b91
  4. leonsong09 commented on Mar 29, 2026

    @leonsong09
    Author

    Thanks — I reviewed those suggestions.

    My understanding is:

    • #14950 looks related at a broader stale-MCP-helper-tree symptom level, but it is app/macOS-focused and not specifically about Windows stdio MCP teardown during client drop / refresh.
    • #14773 looks more specific to app-owned Playwright / Chrome cleanup on macOS, so I do not think it is the same bug.

    I’m keeping this issue open for now because this report is intentionally narrow:

    • Windows
    • stdio MCP
    • teardown on drop / refresh
    • with a ready compare branch and regression coverage

    If maintainers would prefer consolidation into #14950 or another existing issue, I’m happy to close this and move the patch context there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmcpIssues related to the use of model context protocol (MCP) serverswindows-osIssues related to Codex on Windows systems

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions