Repository navigation
Description
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
- On Windows, open T3 Code Desktop in a workspace whose project MCP config declares multiple stdio MCP servers.
- Work normally across a handful of Codex threads for 30–60 minutes, switching between threads and running turns.
- Count live MCP server sets owned by T3 Code's
codex.exe app-serverprocess, 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, NameThe 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.exelaunching a project stdio MCP server (StudioMCP.exe)python.exerunning a project coordination stdio MCP servernode.exe- Two
node_repl.exeprocesses (Codex's bundledcua_nodefromopenai-bundled) - Associated
conhost.exeprocesses
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 acmd.exewrapper) accumulated 69+ leaked pairs (138 total) alongside the custom servers. - Direct (non-wrapper) processes and
cmd.exewrappers both stayed alive: The Python coordination server is launched directly viapython.exe(nocmd.exeshim), uses a plainfor raw in sys.stdin.buffer:loop with no background threads or child processes, and exits cleanly on stdin EOF. Likewise, thecmd.exewrappers forStudioMCP.exestayed alive too (87 total), so this is not merely acmd.exewrapper being killed while leaving its child orphaned—codex.exe app-servernever 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 to0within 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 version0.1.10) - Codex: npm
@openai/codex0.171.0(codex-win32-x64binary) - 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
- 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 Codexapp-serverleaves 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. - Windows
.CMD/cmd.exewrapper orphaning: Check whether stdio servers launched throughcmd.exe/.CMDshims leave grandchild server processes running when only the shell process is terminated. - Windows Job Object safety net: Consider placing the spawned
codex app-serverin a Windows Job Object withJOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSEso 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
juliusmarminge commentedon Nov 21, 2026
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 againstcodex 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, thent3 thread start ... --provider codex --model gpt-6-luna --waitwith 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.
redpriest commentedon Nov 21, 2026
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:
releaseFinishedDelegateSessionsskips Codex (Orchestrator.ts:14951)During the 11:45–12:30 window in the report, a parent thread was fanning out short
delegate_taskjobs to Codex (~20 every 10 minutes). Checking~/.codex/state_5.sqlitefor that exact window matches the live MCP set counts bucket-for-bucket:state_5.sqlite)Every one of those 80 archived threads was unloaded/archived ~30 minutes after completion (
archived_atwas 32–39 min after creation — matching T3'sDEFAULT_IDLE_TIMEOUT_MS = 30 * 60 * 1000inProviderSessionManager.ts:81).The reason this happens specifically on Codex (and not on Claude or Antigravity/Neon) is
releaseFinishedDelegateSessionsinapps/server/src/orchestration-v2/Orchestrator.ts:14928-14963(verified onmain @ da57ea2bf9):packages/provider-acp/src/server/adapter.ts:815) and Claude (ClaudeAdapterV2.ts:554) havesupportsMultipleProviderThreadsPerSession: false, soreleaseFinishedDelegateSessionsimmediately detaches each finisheddelegate_taskchild and tears down its MCP server set right away.CodexAdapterV2.ts:269) hassupportsMultipleProviderThreadsPerSession: true, so line14951skips detaching finished delegated Codex children under the comment "Shared processes unload their threads themselves; only a per-thread process lingers."codex app-serverdoes 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-minuteDEFAULT_IDLE_TIMEOUT_MSfires (ProviderSessionManager.ts:2107). At ~20 delegations per 10 minutes, ~60–71 already-completed delegated Codex threads pile up simultaneously (~400 processes / ~8 GB RAM).provider-session.detachinProviderSessionManager.ts:3545-3565already supportssupportsMultipleProviderThreads: trueby callingunloadThread(thread/unsubscribe, orthread/archiveonce delivered) for just that child thread without affecting other active Codex threads — which with-c thread_unload_delay_secs=0closes the child's MCP servers within seconds.Deterministic fast repro (no 30-minute wait needed)
CODEX_HOME.delegate_taskcalls targeting Codex (e.g. a one-turn read/summary task) and wait for all of them to complete and deliver their results.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 nativespawn_agentsubagents when any other thread keeps the sharedcodex app-serveralive.Could this issue be reopened to:
delegate_taskchild threads on shared-session providers like Codex (not skip them inreleaseFinishedDelegateSessionsatOrchestrator.ts:14951), andfactory/repro-40582)?