Skip to content

[Bug]: Codex app-server leaks ~20 sets of stdio MCP server processes every 10 minutes on Windows #40582

Closed as not planned

Description

@redpriest

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Summary

While running Codex threads in T3 Code Desktop on Windows, the shared codex.exe app-server process spawned by T3 Code repeatedly starts new sets of stdio MCP server processes (~20 sets every 10 minutes) and almost never shuts them down. Within 40 minutes, this accumulated 71 sets (~400 leaked processes and ~8 GB of private memory), causing severe system-wide lag.

Quitting T3 Code terminated every leaked process within a few minutes and restored system responsiveness immediately.

This appears to be a Windows follow-up to #33767 / #33769: T3 Code starts Codex with -c thread_unload_delay_secs=0 (apps/server/src/provider/codexLaunchArgs.ts), assuming codex app-server cleanly tears down a thread's MCP children on unload. The underlying reaping failure looks upstream in openai/codex (related open issues: openai/codex#30408, openai/codex#53285, openai/codex#56430, openai/codex#56937, openai/codex#25015), but T3 Code's thread_unload_delay_secs=0 setting likely amplifies the leak on Windows by unloading threads immediately and spawning fresh MCP sets on reload while prior sets stay alive.

Other agent hosts running against the exact same project MCP config on the same machine at the same time (Claude Code, Antigravity) maintained one MCP set per open session with no buildup.

Steps to reproduce

  1. On Windows, open T3 Code Desktop in a workspace whose project MCP config declares multiple stdio MCP servers.
  2. Work normally across a handful of Codex threads for 30–60 minutes, switching between threads and running turns.
  3. Count live MCP server sets owned by T3 Code's codex.exe app-server process, for example:
$all = Get-CimInstance Win32_Process; $byId = @{}; $all | % { $byId[[int]$_.ProcessId] = $_ }
$all | ? Name -eq 'node_repl.exe' | % { $p = $byId[[int]$_.ParentProcessId]; if ($p) { $byId[[int]$p.ParentProcessId] } } |
  ? Name -eq 'codex.exe' | Group-Object ProcessId | select Count, Name

The count continues climbing over time until T3 Code is quit.

Expected behavior

When a Codex thread unloads or finishes a turn and is no longer loaded, its stdio MCP server processes should be shut down and reaped. The number of running MCP server sets should stay close to the number of active/loaded threads.

Actual behavior

New sets of stdio MCP servers keep spawning (~20 sets per 10 minutes with only a few Codex threads in use) and almost never exit.

Process tree spawned by T3 Code:

electron.exe  <t3code>\apps\server\dist\bin.mjs --bootstrap...
  cmd.exe /d /s /c "%APPDATA%\npm\codex.CMD" app-server -c thread_unload_delay_secs=0
    node.exe  %APPDATA%\npm\node_modules\@openai\codex\bin\codex.js app-server -c thread_unload_delay_secs=0
      codex.exe app-server -c thread_unload_delay_secs=0

Under that single codex.exe, each leaked MCP set consisted of:

  • cmd.exe launching a project stdio MCP server (StudioMCP.exe)
  • python.exe running a project coordination stdio MCP server
  • node.exe
  • Two node_repl.exe processes (Codex's bundled cua_node from openai-bundled)
  • Associated conhost.exe processes

Observed growth over ~1 hour:

Local time MCP sets owned by codex.exe app-server Total system processes Free RAM Commit charge
11:47 app-server starts — — —
11:50–12:00 21 started (still alive at 12:26) — — —
12:00–12:10 12 started (still alive at 12:26) — — —
12:10–12:20 22 started (still alive at 12:26) — — —
12:20–12:26 17 started (still alive at 12:26) — — —
12:25 71 1,434 13.8 GB 81.6 / 95.6 GB
13:00 57 (only a few reaped) 1,241 — —
13:06 (after quitting T3 Code) 0 646 27.6 GB 67.4 / 95.6 GB

At peak (12:25), system-wide totals reached 84 StudioMCP.exe, 84 coordination-server python.exe, 138 node_repl.exe, 74 node.exe, 374 conhost.exe, and 87 cmd.exe (69+ of each belonging to the single codex.exe app-server), holding ~8 GB of private memory plus thousands of handles and threads.

Ruling out a misbehaving stdio MCP server

This is not caused by a custom MCP server ignoring shutdown or hanging on stdin EOF:

  • Codex's own bundled MCP servers leaked at the exact same rate: OpenAI's bundled node_repl.exe (cua_node, launched directly without a cmd.exe wrapper) accumulated 69+ leaked pairs (138 total) alongside the custom servers.
  • Direct (non-wrapper) processes and cmd.exe wrappers both stayed alive: The Python coordination server is launched directly via python.exe (no cmd.exe shim), uses a plain for raw in sys.stdin.buffer: loop with no background threads or child processes, and exits cleanly on stdin EOF. Likewise, the cmd.exe wrappers for StudioMCP.exe stayed alive too (87 total), so this is not merely a cmd.exe wrapper being killed while leaving its child orphaned—codex.exe app-server never closed the MCP transports at all.
  • Other hosts using the exact same MCP servers did not leak: Claude Code and Antigravity ran concurrently against the same project MCP config and kept one set per open session.
  • All servers exited cleanly once pipes closed: Quitting T3 Code brought every leaked server (node_repl.exe, python.exe, StudioMCP.exe, cmd.exe) down to 0 within minutes.

Impact

Major degradation or frequent failure

Version or commit

main @ 8e8ff9b243 (also verified apps/server/src/provider/codexLaunchArgs.ts and Codex unload handling are unchanged on main @ da57ea2bf9)

Environment

  • OS: Windows 11 Pro, Insider build 26300 (x64), 32 logical cores, 64 GB RAM
  • T3 Code: Desktop built from source, main @ 8e8ff9b243 (app version 0.1.10)
  • Codex: npm @openai/codex 0.171.0 (codex-win32-x64 binary)
  • Node: v24.13.0
  • Workspace: Large Git repository (~50,000 tracked files) with a project MCP config declaring multiple stdio servers

Suggested investigation / T3-side mitigations

  1. Interaction with thread_unload_delay_secs=0 (fix(server): settling a Codex thread stops its MCP servers right away #33767): Verify whether immediate thread unloading in Codex app-server leaves MCP child trees behind on Windows while triggering fresh MCP launches on each thread reload. If so, a longer default unload delay (at least on Windows) may significantly reduce accumulation until upstream fixes MCP server processes leak: per-thread processes never cleaned up (9+ GB RSS) openai/codex#30408 / [Windows 26.1007] One stdio MCP process set per thread; 13 sets / 353 processes / ~9.6 GiB under a single app-server, reclamation lags creation openai/codex#53285.
  2. Windows .CMD / cmd.exe wrapper orphaning: Check whether stdio servers launched through cmd.exe / .CMD shims leave grandchild server processes running when only the shell process is terminated.
  3. Windows Job Object safety net: Consider placing the spawned codex app-server in a Windows Job Object with JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE so provider restarts or unexpected T3 exits cannot strand the tree.

Workaround

Fully quitting and restarting T3 Code terminates the codex.exe app-server process tree and frees all leaked MCP processes and memory. Overriding thread_unload_delay_secs via Codex launch args / T3CODE_CODEX_LAUNCH_ARGS (e.g., -c thread_unload_delay_secs=1800) may also reduce reload churn.

Activity

  1. juliusmarminge commented on Nov 21, 2026

    @juliusmarminge
    Member

    I tried to reproduce this on the current build and could not.

    Commit: origin/main 828fe37 (T3 dev server, T3CODE_DEV_SEED=0, own --home-dir) on a Windows Server 2025 pool machine with npm @openai/codex 0.171.0 (codex.cmd shim, same cmd.exe -> node -> codex.exe app-server -c thread_unload_delay_secs=0 tree as the report). CODEX_HOME held three stub stdio MCP servers that log their pids: one launched directly, one via cmd.exe /c node stub.js, one via cmd.exe that keeps running after stdin closes. (1) Raw JSON-RPC driver against codex app-server -c thread_unload_delay_secs=0, no T3: thread/start then thread/unsubscribe, 3 cycles and again with MCP startup delayed 8 s. thread/closed came at once and every stub exited each time, including the sticky one behind cmd.exe, so neither the cmd wrapper nor the zero delay leaks on its own. (2) Same driver with a real model turn (gpt-6-luna through the hub) telling the agent to spawn_agent one subagent: two MCP sets started. thread/unsubscribe of the root gave thread/closed for the root only. thread/loaded/list still listed the child thread, and one MCP set stayed alive until the app-server was killed. Then sending thread/unsubscribe for the child closed it and its set exited within 3 s. (3) Real T3 server: t3 project add, then t3 thread start ... --provider codex --model gpt-6-luna --wait with the spawn_agent prompt left 2 live MCP sets (root + child). Settling the thread with Ctrl+Shift+S (Playwright) sent thread/unsubscribe for the child (id 9) and the root (id 10), and both sets exited. A second identical thread was left unsettled: at the 30-minute idle unload (23:04Z) T3 sent thread/unsubscribe for the root only (id 18), with no unsubscribe for its subagent child. In that run the app-server had no other thread attached, so T3 released the whole shared app-server and all stubs ended (0 alive at 23:06Z). The leftover child would outlive this only when other threads keep the shared app-server alive, as in the report. A second 30-minute run with a keep-alive thread did not fit the budget, so accumulating processes were not observed in the app itself. (4) Failing test on branch factory/repro-40582: CodexAdapterV2.test.ts 'unsubscribes native subagent threads when their root thread unloads' replays a root turn that spawns a native subagent, then calls runtime.unloadThread on the root. On main only the root's thread/unsubscribe is sent.

    Closing as not planned. If it still happens for you, reply with the exact steps and the version you are on and it will be looked at again.

  2. redpriest commented on Nov 21, 2026

    @redpriest
    Author

    Thanks for the thorough investigation — your test narrowed it right down, and checking ~/.codex/state_5.sqlite + the server code pinpointed the exact cause of the 71 live MCP sets (and why a single-thread repro didn't hit it).

    Exact cause: releaseFinishedDelegateSessions skips Codex (Orchestrator.ts:14951)

    During the 11:45–12:30 window in the report, a parent thread was fanning out short delegate_task jobs to Codex (~20 every 10 minutes). Checking ~/.codex/state_5.sqlite for that exact window matches the live MCP set counts bucket-for-bucket:

    Window (local) Delegated Codex threads created (state_5.sqlite) Live MCP sets reported at 12:26
    11:47–11:49 8 (archived 12:20–12:22, just before the 12:25 count) —
    11:50–12:00 20 21
    12:00–12:10 12 12
    12:10–12:20 22 22
    12:20–12:30 19 (17 by 12:26) 17

    Every one of those 80 archived threads was unloaded/archived ~30 minutes after completion (archived_at was 32–39 min after creation — matching T3's DEFAULT_IDLE_TIMEOUT_MS = 30 * 60 * 1000 in ProviderSessionManager.ts:81).

    The reason this happens specifically on Codex (and not on Claude or Antigravity/Neon) is releaseFinishedDelegateSessions in apps/server/src/orchestration-v2/Orchestrator.ts:14928-14963 (verified on main @ da57ea2bf9):

    for (const session of providerSessions) {
      // Shared processes unload their threads themselves; only a per-thread process lingers.
      if (
        session.status === "stopped" ||
        session.status === "error" ||
        session.capabilities.sessions.supportsMultipleProviderThreadsPerSession
      )
        continue;
      yield* dispatchWithReceiptEffect({
        type: "provider-session.detach",
        commandId: CommandId.make(
          `command:system:delegated-task-release:${resultRunId}:${session.id}`,
        ),
        threadId: childThreadId,
        providerSessionId: session.id,
        reason: "Delegated task finished.",
      });
    }
    • Antigravity (packages/provider-acp/src/server/adapter.ts:815) and Claude (ClaudeAdapterV2.ts:554) have supportsMultipleProviderThreadsPerSession: false, so releaseFinishedDelegateSessions immediately detaches each finished delegate_task child and tears down its MCP server set right away.
    • Codex (CodexAdapterV2.ts:269) has supportsMultipleProviderThreadsPerSession: true, so line 14951 skips detaching finished delegated Codex children under the comment "Shared processes unload their threads themselves; only a per-thread process lingers."
    • Because codex app-server does not unload a thread while T3 still holds a subscription to it, every finished delegated Codex child stays loaded — keeping its full per-thread stdio MCP set alive — until T3's 30-minute DEFAULT_IDLE_TIMEOUT_MS fires (ProviderSessionManager.ts:2107). At ~20 delegations per 10 minutes, ~60–71 already-completed delegated Codex threads pile up simultaneously (~400 processes / ~8 GB RAM).
    • Meanwhile, provider-session.detach in ProviderSessionManager.ts:3545-3565 already supports supportsMultipleProviderThreads: true by calling unloadThread (thread/unsubscribe, or thread/archive once delivered) for just that child thread without affecting other active Codex threads — which with -c thread_unload_delay_secs=0 closes the child's MCP servers within seconds.

    Deterministic fast repro (no 30-minute wait needed)

    1. Configure a stdio MCP server in CODEX_HOME.
    2. From a parent thread, fan out 5–10 short delegate_task calls targeting Codex (e.g. a one-turn read/summary task) and wait for all of them to complete and deliver their results.
    3. Check live MCP processes under codex.exe app-server: all 5–10 MCP sets remain alive after the delegated tasks have finished and delivered (for the next 30 minutes), whereas delegating the same 5–10 tasks to Claude or Antigravity tears down each child's MCP set immediately upon completion.

    Secondary bug also found in your triage

    Your test (3) / (4) (factory/repro-40582: CodexAdapterV2.test.ts 'unsubscribes native subagent threads when their root thread unloads') also caught a real leak for native spawn_agent subagents when any other thread keeps the shared codex app-server alive.

    Could this issue be reopened to:

    1. Release/unload finished delegate_task child threads on shared-session providers like Codex (not skip them in releaseFinishedDelegateSessions at Orchestrator.ts:14951), and
    2. Unsubscribe native Codex subagent threads when their root thread unloads (factory/repro-40582)?
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions