MCP server processes leak: per-thread processes never cleaned up (9+ GB RSS)
Bug description
Codex app-server spawns a full set of global MCP server processes for each new thread/conversation, but never kills them when threads are archived or closed. Over time, orphaned MCP processes accumulate unboundedly.
Environment
- Codex Desktop: 0.142.3 (macOS, Apple Silicon)
- OS: macOS 15.x, 64 GB RAM
Steps to reproduce
- Configure global MCP servers in
~/.codex/config.toml(e.g.playwright,davinci-resolve,node_repl) - Open Codex Desktop, create ~25 threads over a session
- Close/archive threads as normal
- Check process list
Expected behavior
MCP server processes should be cleaned up when the owning thread is closed or archived. At most one set of MCP processes should exist per actively-used server.
Actual behavior
After 25 threads, observed 133 orphaned MCP processes consuming ~9.3 GB RSS:
| MCP Server | Orphaned Processes | RSS |
|---|---|---|
| playwright (npm + node) | 52 | 2.9 GB |
| davinci-resolve (python) | 26 | 3.5 GB |
| node_repl | 26 | 266 MB |
| npm exec wrappers | 29 | 2.6 GB |
All processes had PPID = app-server PID. The app-server holds them indefinitely.
Root cause
The app-server does not track which MCP processes belong to which thread, and has no lifecycle management to kill MCP processes when threads end. There is also no idle_timeout, reuse, or shared config option for MCP servers.
Workaround
- Manually kill orphaned processes:
pkill -P <app-server-pid> -f "playwright-mcp|davinci-resolve" - Remove rarely-used MCP servers from global config and add them per-project instead
Suggested fix
- Track MCP process ownership per-thread
- Kill MCP processes when the owning thread is closed/archived
- Alternatively, add a
sharedorreusemode so all threads share a single MCP process instance - Consider an
idle_timeoutoption to auto-kill MCP processes after N minutes of no use
14 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
Independent reproduction on macOS at a different config scale — confirming this isn't size-specific.
Environment: Codex Desktop (macOS, Apple Silicon), macOS 26.x; 24 global MCP servers configured in
~/.codex/config.toml.Observed: a single live
codex app-serverprocess held 101 direct child processes (ppid == app-server) — roughly **5 copies of every configured server:@modelcontextprotocol/server-github×5,server-memory×5,server-sequential-thinking×5,@playwright/mcp×5,chrome-devtools-mcp×5,gemsuite-mcp(viatsx) ×5, plus the uv-based servers (arxiv-mcp-server,semantic-scholar-mcp,reddit-*) at similar multiplicity. System-wide that was 128node+ 24uv** processes. This matches the root cause described here exactly: the app-server spawns the full MCP fleet per thread and never reaps the prior sets.Two amplifiers worth noting:
npm execdoubling — each stdio server launched vianpm exec <pkg>is two processes (the npm wrapper + the actual node), so N configured servers × M threads produces ~2·N·M processes.The cost isn't only RAM — it's disk exhaustion and system-wide failure, which I think deserves emphasis alongside the RSS number:
vm.swapusagewas at ~2.5 GB used with multiple/System/Volumes/VM/swapfile*present.lsof +L1shows unlinked-but-open inodes pinned by the stalenodeprocesses, so that space is never reclaimed by the OS.So the leak has three compounding costs: RAM → swap → APFS free space, plus held-open deleted-file space.
+1 on the suggested fixes, in priority order for the disk angle:
shared/reusemode so all threads share one MCP instance (biggest win — collapses the ×M entirely), and/oridle_timeoutto auto-kill idle MCP processes.Happy to provide sanitized
ps/lsofcaptures through a private channel if useful.I can reproduce a similar leak on macOS with the current Codex Desktop app.
Environment:
26.623.101652467426.5.1(25F80)arm64/Applications/Codex.app/Contents/Resources/codex app-server --analytics-default-enabledObserved on July 6, 2026 JST under the live app-server PID:
The
node_repland MCP proxy processes are children of the Codex app-server. Their start times are spread across the session, with many alive for 1-3 hours, so they do not look like short-lived tool-call processes being cleaned up normally. They are mostly sleeping with near-zero CPU, but they keep accumulating.This happened during a session that included repeated Browser / in-app browser recovery attempts and MCP/tool usage. I cannot prove the browser path is the only trigger, but the timestamps line up with repeated browser-control attempts.
Expected behavior:
Actual behavior:
node_repland MCP proxy processes remain under app-server and accumulate across the session.Additional note: the high-RSS Python process in my snapshot is a local
delimit-memorydaemon backed by mem0, not the old Delimit product itself. The leaking symptom I am reporting here is the app-server-owned child process accumulation (node_repland MCP proxies).I am seeing what appears to be the same MCP lifecycle leak, with an additional failure mode: app-server FD exhaustion leading to
Too many open files (os error 24)on macOS.Environment:
ulimit -n:256launchctl limit maxfiles: observed as65536 unlimited, but Codex-spawned shell still inheritedulimit -n = 256Observed app-server processes:
There was also an orphaned launcher shell:
The GUI app-server had duplicated MCP children:
The Unix-socket app-server also had duplicated MCP children:
The generic
./mcp/server.*processes mapped back by cwd to plugin-bundled MCPs:This eventually reproduced inside Codex as:
So this is not only memory/process accumulation; with a low inherited
RLIMIT_NOFILE, the app-server can become unable to spawn new commands.Independent severe reproduction on macOS, adding Jetsam-level evidence to this MCP lifecycle leak. The system became unresponsive and required a manual restart.
Environment
26.707.31123(bundle build5042)codex-cli 0.144.0-alpha.426.5.1(25F80)macOS Jetsam evidence
macOS wrote two
JetsamEventreports 5m56s apart. The reports use a 16,384-byte page size. The values below are direct calculations from the reports (GiB = pages × 16,384 / 2^30):| Snapshot | All
nodeprocesses |nodein Codex coalition | All-node resident pages | Codex coalition processes | Codex coalition resident pages | Free memory ||---|---:|---:|---:|---:|---:|---:|
| 06:20:05 | 760 | 755 | 1,662,363 = 25.37 GiB | 799 | 1,895,040 = 28.92 GiB | 5,445 pages = 85.1 MiB |
| 06:26:01 | 843 | 842 | 1,778,409 = 27.14 GiB | 881 | 2,034,698 = 31.05 GiB | 2,246 pages = 35.1 MiB |
In 5m56s:
nodecount increased by 83At the second snapshot, the system compressor occupied 9.40 GiB and represented 50.99 GiB of uncompressed, system-wide pages. This is not all attributable to Codex, but it shows the severity of the resulting system pressure.
A separate
nodediagnostic report identifies the ownership chain as:No kernel-panic report was present. The machine was manually restarted at 06:32 after the UI became unusable.
Post-restart reproduction
After restart, read-only process inspection again showed repeated app-server-owned batches containing:
Their start times appeared in repeated batches during tool-enabled thread activity, and earlier batches remained alive. This observation supports the lifecycle leak reported here, but it does not distinguish whether each new batch is keyed to a thread, subagent, tool-host lifecycle, or another app-server boundary.
Impact
On a 16 GB Mac this progressed from an application leak to a system-wide outage. Quitting/restarting the app-server is currently the only reliable way I found to release the accumulated process tree.
I have intentionally omitted project names, usernames, local paths, and raw session logs. I can provide sanitized excerpts or the aggregation queries through a private channel if useful.
Adding an independent Ubuntu/Linux reproduction. This issue is still reproducible with
codex-cli 0.144.1, and in this run it progressed to complete unified-exec/PTY failure.Environment
codex app-server --listen unix://systemd --userserviceRLIMIT_NOFILE: soft1024, hard524288docker exec -i -w <workspace> mcp-suite mcp-suite-stdio <lsp|codegraph|agbrowse>The incident followed a large collaboration/subagent tree containing many completed or interrupted agents.
User-visible failure
Eventually even a trivial process could not be created:
The PTY path failed independently:
One attempt also reported
dup of fd 992 failed. The same failure occurred from the original Goal thread, collaboration subagents, and a new same-directory child thread, which ruled out one stale unified-exec session registry as the primary cause.Live
/procevidence before mitigationThe app-server process was captured at 1012 open FDs with a soft limit of 1024 (
FDSize=1024, highest occupied FD1023):| FD class | Count |
|---|---:|
| pipe | 662 |
| pidfd | 221 |
| regular/session/state files | 111 |
| socket | 6 |
| other anon-inode FDs | 12 |
Of the 111 file FDs, 82 pointed into the Codex session store.
The same app-server had 221 direct children. 219 were live, sleeping
dockerclients:| MCP stdio child | Count |
|---|---:|
|
mcp-suite-stdio lsp| 74 ||
mcp-suite-stdio codegraph| 73 ||
mcp-suite-stdio agbrowse| 72 |The Docker MCP clients alone accounted for 657 broker-side pipe FDs + 219 pidfds = 876 FDs. This is approximately 73 retained copies of the three-server MCP set, or roughly 12 broker FDs per agent/context.
An important Linux-specific detail: these were not zombie/dead children. Every one of the 219 pidfds still targeted a live Docker process, and all 657 associated pipe inodes still had a live peer. There were no PTY FDs in the service cgroup. This snapshot therefore looks like retention of live per-agent stdio transports, rather than only failure to reap already-dead children.
Host-wide exhaustion was ruled out:
Controlled mitigation and toggle evidence
I did not kill/restart the app-server or any MCP process. I only raised the running app-server's soft limit, leaving the hard limit unchanged:
After that change, two non-PTY and two PTY executions of
/bin/bash -c true, launched concurrently through unified exec, all exited0. The retained MCP processes and FDs remained; only the headroom changed. A later snapshot still showed 216 Docker MCP children and 994 app-server FDs, confirming that this was a recovery workaround rather than cleanup.The service definition still has
LimitNOFILESoft=1024, so the next app-server restart would inherit the low limit again unless the unit is hardened.Why this appears to be the same upstream issue
The direct parent of every Docker MCP client was the Codex app-server. The Docker command came from the normal global
[mcp_servers.*]config; it was not launched by a still-running LazyCodex wrapper process. The issue therefore reproduces as app-server MCP lifecycle behavior with an ordinary stdio MCP command.As a local workaround, I can replace these stdio entries with the already-running loopback Streamable HTTP endpoints. That should remove the
dockerchild / pipe / pidfd multiplier, but it does not address per-thread/agent MCP client ownership, sharing, or idle teardown in Codex itself.This Linux data point suggests a useful regression test: after completing, interrupting, or archiving a large collaboration-agent tree, app-server child-process and FD counts should return close to baseline. It would also be valuable to cover a low inherited
RLIMIT_NOFILE, because the lifecycle retention otherwise surfaces as total loss of shell and PTY execution.Related: #26984.
---
This issue or PR was generated by LazyCodex.
Tag: lazycodex-generated
Corroborating from a different surface: this also happens with codex-cli on Linux, so it is not Desktop- or macOS-specific.
Environment
--dangerously-bypass-approvals-and-sandbox)~/.codex/config.toml:ferrex(Rust memory server, loads ~2 GB of embedding models at initialize) and a python RAG server viauv runObservation (2026-07-12/13)
One long-lived codex CLI process (PID 3510112, ~5.5 h old) had accumulated 4 concurrent instances of the same ferrex stdio server and 4 instances of the python server, all still direct children, none ever reaped:
Spawn timestamps cluster in bursts (03:27, 05:13, 05:14, 05:44 local), consistent with a fresh MCP set per thread/turn burst while earlier sets stay alive but idle. With ~2 GB of model weights per instance this pushed the 32 GB machine deep into swap (observed 61 GB swap used across sessions exhibiting this pattern).
Repro sensitivity note
Our MCP server initialized slowly under memory pressure (30–90 s model load). If the respawn path triggers on initialize/tool-call timeouts, slow-initializing stdio servers make the leak far more likely — that may explain why some setups see it constantly and others rarely.
I can reproduce this on the current Codex Desktop build for Windows. Since #19753 was merged in April, this looks like a lifecycle path that is still missing in Desktop, or a regression after that fix.
Environment:
26.707.12708.0I recorded the app-server PID, each direct MCP root PID, process creation time, working directory, and private memory before and after a full Codex restart. I did not terminate any process during the capture.
The full restart did clean up the old app-server tree. The app-server PID changed, and all 57 previously tracked direct-child process instances were gone. The problem returned quickly under the new app-server:
At the end of that window, the new app-server owned:
| Process group | Root count | Aggregate private memory |
| --- | ---: | ---: |
| CodeGraph MCP | 12 | 970.0 MB |
| Project-scoped MCP | 2 | 225.5 MB |
| Data Analytics Widgets | 12 | 301.0 MB |
| OpenAI API key local confirmation | 12 | 263.6 MB |
| Sites Design Picker | 0 | 0 MB |
| Built-in
node_repl| 12 | 32.2 MB |The managed stdio and built-in tool trees used about 1.79 GB of private memory. The app-server itself used about 2.16 GB at that point.
There is also a configuration inconsistency that amplifies the leak. These three plugin MCP servers were all set to
enabled = falsebefore the new processes were created:sites-design-picker: the setting was honored, with zero processes after restart.dataAnalyticsWidgets: the setting was not honored, with 12 processes.openai-api-key-local-confirmation: the setting was not honored, with 12 processes.The two project-scoped MCP roots matched two active tasks in that repository, so project scoping itself appears to work. The duplicate global and plugin bundles are the part that keeps growing.
One CodeGraph
--liftoff-onlychild also remained alive across the full app restart after its launcher parent had exited. That may be specific to the third-party launcher, but a Windows Job Object around the task-owned process tree would prevent detached descendants from surviving the owning runtime.What I expected:
notLoaded, is archived, or is evicted should release its stdio transports and terminate the complete process tree after a bounded grace period.enabled = falseshould not be started for newly loaded task runtimes.I have a sanitized PID and lifecycle matrix and can provide it without local paths, project names, session content, or credentials.
Follow-up from the same Windows host after extending the read-only process snapshot.
The environment is unchanged: Windows 11 x64, 32 GB RAM, Codex Desktop package
26.707.12708.0, and several long-running tasks. The newer classifier separates the one top-level Desktop app-server from thecodex.exebridge processes launched under built-in Node REPL hosts.At
2026-07-16T21:57:38Z, the top-level app-server had 104 descendants and 56 managed service roots:| Process group | Root count | Process count | Private memory |
| --- | ---: | ---: | ---: |
| CodeGraph | 14 | 43 | 1,494.1 MB |
| Built-in Node REPL | 14 | 20 | 2,440.8 MB |
| Plugin MCP CJS entrypoint | 14 | 14 | 352.9 MB |
| Plugin MCP MJS entrypoint | 14 | 14 | 305.0 MB |
Those service trees used about 4.59 GB of private memory. The app-server itself used another 1.24 GB.
The Node REPL number needs some unpacking. There were 14 lightweight
node_repl.exehosts, but only three had an active Node kernel and Codex bridge. One persistent kernel alone was using 2,217 MB of private memory and had accumulated 2,960 CPU seconds. The same kernel had dropped to about 408 MB in an earlier sample, then grown again. This looks like a persistent per-task execution state with large allocation and GC swings, not 14 equally heavy REPL processes.I also saw partial cleanup on this build. The four root groups fell from 19 each at
21:39Zto 14 each at21:57Zwithout any manual process termination. So "never cleaned up" is too strong for this Windows host. The behavior is still delayed or incomplete: all four groups move together, and every retained task runtime keeps the full bundle even when most Node REPL hosts have no active kernel.A separate 30-second multi-session sample recorded 237.7 MB of app-server reads, 36.5 MB of writes, 41,433 read operations, 5,703 write operations, and 5.36 CPU seconds. These are Windows process counters and include files, pipes, and network traffic, so I am not treating them as pure disk I/O.
I found one third-party multiplier as well. CodeGraph 1.4.1 relaunches its Node adapter with V8's
--liftoff-onlyflag when that flag is missing from the original Node command line. Supplying the flag directly should remove one wrapper process per CodeGraph root after the next Desktop restart. That reduces the cost of this particular MCP, but it does not explain why Codex retains one complete adapter bundle per loaded task.The upstream behavior would be much easier to diagnose and contain if Desktop did the following:
enabled = falsebefore constructing a new task runtime.I can provide another sanitized PID and start-time matrix if a maintainer needs it. No project paths, session content, command lines, daemon tokens, or credentials were captured in the snapshot output.
I reproduced the same issue on a newer Codex Desktop build, at substantially larger scale. There was also an unreaped-zombie component similar to #12491.
Environment
26.715.21425codex-cli 0.145.0-alpha.1826.5.2(25F84), Apple Silicon (arm64)npx -y chrome-devtools-mcp@latestuvx --from git+https://github.com/oraios/serena serena start-mcp-server --project-from-cwd --context codexheadroom mcp serveObserved failure
After a long-running desktop session with many threads/background agents, the host became nearly unusable. A process snapshot showed:
191 / 512 / 636at capture time (earlier samples were approximately520-686)373livechrome-devtools-mcpprocesses, consuming about898%aggregate CPU362uvlauncher processes plus362Python Serena server processes (about724Serena-related process entries)386headroom mcp serveprocesses1,291Node processes in total2,877zombie children below the bundled Codex app-server process (2,884zombies system-wide)Nearly every sampled Chrome DevTools MCP parent chain led back to the same bundled Codex app-server process. The affected app-server had been running for roughly seven hours.
This was not primarily RAM exhaustion. The machine still had substantial free memory; the freeze was caused by run-queue/process-table pressure from thousands of live and zombie processes.
Recovery result
After restarting the Codex/ChatGPT application stack, counts returned to:
chrome-devtools-mcp:1110%at the verification sample94%The three remaining system zombies were traced to LM Studio and two SSH sessions, not Codex/MCP.
I do not yet have a deterministic minimal reproduction beyond sustained multi-thread/background-agent use with multiple global stdio MCP servers. However, the parent-process evidence and the immediate return to one instance per MCP after restarting Codex strongly support the per-thread lifecycle leak described here.
In addition to terminating MCP children when their owning thread ends, the app-server should reap exited children and ideally provide a shared/singleton MCP mode or a hard per-server instance limit. A process-count or zombie-growth guard would also prevent the desktop from taking down the host while the underlying lifecycle bug is being addressed.
Additional reproduction on the current unified ChatGPT/Codex macOS app, with a strong per-tool-execution lifecycle correlation.
Environment
26.715.21425150.0.7871.1240.145.0-alpha.1826.5.1 (25F80)Reproduction and lifecycle evidence
After a fresh reboot/app launch, there were 5 copies of each configured local stdio MCP root. During four read-only diagnostic/tool-execution cells in a single existing task, the
npm exec xcodebuildmcp@latest mcproot count rose from 5 to 9. The elapsed start times of the four new MCP sets aligned with the four tool cells. No new user task was opened during that sequence.Each retained set included local servers/helpers such as:
xcodebuildmcpThis appears to be more granular than only “one set per visible conversation”: completed tool/code-mode execution cells can initialize another full MCP set that remains parented by the persistent
codex app-server.Impact observed before reboot
After extended use:
codex app-servernodeprocessesThe app-server itself sampled around 83–148% CPU.
Terminating only the duplicated MCP trees removed 472 processes:
nodeprocesses fell from 307 to 17Relative cost seen locally
Among three specialized globally configured servers, summed RSS per retained tree was approximately:
xcodebuildmcp: 90–300 MBRSS includes shared pages, so these figures are directional rather than perfectly additive.
Workaround
Moving specialized stdio MCPs out of global config and into trusted project-level
.codex/config.tomlfiles substantially reduces the fan-out, but it does not address teardown of already-started sets. Fully quitting the app remains the reliable way to reap the persistent app-server tree.No raw logs or session files are attached because they may contain private prompts and project metadata.
Additional Windows reproduction on a newer Codex Desktop build, showing partial cleanup but rapid recreation of complete MCP process pools.
Environment:
Observed:
Performance impact:
Expected:
MCP runtimes should be reused or terminated after their owning task/tool execution becomes idle, unloaded, superseded, or complete. Pool count should remain bounded by actually loaded work.
Workaround:
A full Codex Desktop restart clears the accumulated tree temporarily. No permanent safe workaround is confirmed.
Independent reproduction on the current macOS Desktop build, with a concrete pooling proposal.
Environment
26.715.21425(build5488)0.145.0-alpha.18Darwin 24.6.0 arm64Observation
The long-lived Desktop app-server had been running for about 24 hours. During a read-only diagnostic window, the number of Node processes attributable to configured/plugin MCP servers increased from
890to913, then to945, without restarting the app-server.At the final snapshot:
945MCP-related Node processes19.2 GiBaggregate MCP RSS (RSS includes shared mappings, so this is not unique physical memory)789Node processes were direct children of the Desktop app-server16.5 GiBaggregate RSS1.8 GiBRSSThe process tree consisted of repeated, session-shaped batches of the same enabled stdio MCP commands and package-runner wrappers. The affected MCPs were mostly idle at capture time. A full Desktop restart is currently the only reliable way to return the process tree to baseline, but that interrupts every active task.
Suggested manager contract
The app-server should own a singleton MCP broker instead of attaching an eagerly spawned stdio stack to every loaded thread or subagent:
global,project, orsession. Stateful browser/computer-control servers should not be silently pooled across unrelated tasks.The important separation is logical thread residency versus MCP runtime residency. Keeping a completed thread available for resume should not require keeping its entire stdio process stack alive.
All project names, local paths, credentials, account identifiers, and command arguments have been omitted. I can provide sanitized aggregation commands if useful.
Correction and narrowed scope for this Fedora datapoint.
This reproduction used the official managed standalone Codex CLI
0.144.6inapp-servermode, driven by a custom Linux app-server client. It should not be read as an official Linux client/support report.I checked the client boundary:
thread/unsubscribestatus: unsubscribedthread/unsubscribe/thread/closedlifecycleI also ran an isolated
0.144.6app-server probe with a disposable, well-behaved stdio MCP server:thread/unsubscribeleft the MCP alive, which matches the documented 30-minute unloaded-thread residencythread/archivetransitioned the thread tonotLoadedand the corresponding MCP process exitedTherefore the original 39-child snapshot is not sufficient to claim that every child was leaked by app-server. It conflated three possible contributors: expected 30-minute thread residency, missing EOF/signal shutdown in some custom MCP servers, and any genuine CLI-side runtime retention. I retract the stronger causal conclusion from the earlier wording.
The snapshot still establishes that the official CLI process owns the child roots and pipe endpoints. The independent long-running TUI reproduction in #26984 remains the stronger evidence that the broader MCP/pipe lifecycle problem can occur without any app-server GUI client. A conclusive
0.144.6app-server report should correlate a specific MCP PID withthread/closedor an explicit archive/unload boundary and show that it survives that boundary.