codex icon indicating copy to clipboard operation
codex copied to clipboard

MCP server processes leak: per-thread processes never cleaned up (9+ GB RSS)

Open kkkayye opened this issue 5 months ago • 73 comments

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

  1. Configure global MCP servers in ~/.codex/config.toml (e.g. playwright, davinci-resolve, node_repl)
  2. Open Codex Desktop, create ~25 threads over a session
  3. Close/archive threads as normal
  4. 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 shared or reuse mode so all threads share a single MCP process instance
  • Consider an idle_timeout option to auto-kill MCP processes after N minutes of no use

kkkayye avatar Jun 28 '26 03:06 kkkayye

Potential duplicates detected. Please review them and close your issue if it is a duplicate.

  • #29057
  • #29079

Powered by Codex Action

github-actions[bot] avatar Jun 28 '26 03:06 github-actions[bot]

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-server process 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 (via tsx) ×5, plus the uv-based servers (arxiv-mcp-server, semantic-scholar-mcp, reddit-*) at similar multiplicity. System-wide that was 128 node + 24 uv 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:

  1. npm exec doubling — each stdio server launched via npm exec <pkg> is two processes (the npm wrapper + the actual node), so N configured servers × M threads produces ~2·N·M processes.
  2. Config size is a multiplier — with 24 servers configured, each leaked thread cycle adds ~48+ processes. Overlapping/rarely-used servers make it much worse (I had 6 web-search servers configured, most unused).

The cost isn't only RAM — it's disk exhaustion and system-wide failure, which I think deserves emphasis alongside the RSS number:

  • Memory pressure from the leaked fleet grows swap — vm.swapusage was at ~2.5 GB used with multiple /System/Volumes/VM/swapfile* present.
  • The orphaned processes hold deleted files open — lsof +L1 shows unlinked-but-open inodes pinned by the stale node processes, so that space is never reclaimed by the OS.
  • Net effect on a 460 GB APFS volume: free space silently collapses toward 0 with no corresponding visible files, eventually reaching the state described in #26869 / #25744 where the desktop looks normal but launching executables/actions fails until reboot. A reboot only "fixes" it because it kills the whole tree.

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:

  • a shared/reuse mode so all threads share one MCP instance (biggest win — collapses the ×M entirely), and/or
  • per-thread ownership tracking + reap on thread close/archive, and
  • an idle_timeout to auto-kill idle MCP processes.

Happy to provide sanitized ps / lsof captures through a private channel if useful.

ZenAlexa avatar Jul 02 '26 10:07 ZenAlexa

I can reproduce a similar leak on macOS with the current Codex Desktop app.

Environment:

  • Codex Desktop: 26.623.101652
  • Bundle build: 4674
  • macOS: 26.5.1 (25F80)
  • Architecture: Apple Silicon arm64
  • App server: /Applications/Codex.app/Contents/Resources/codex app-server --analytics-default-enabled

Observed on July 6, 2026 JST under the live app-server PID:

Codex app-server PID: 82560
Codex app-server RSS: 740896 KB
node_repl count: 66, aggregate RSS: 592608 KB
delimit-mem-proxy count: 70, aggregate RSS: 63680 KB

The node_repl and 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:

  • per-thread or per-tool child processes should be cleaned up when the tool call/thread ends, or reused through a bounded pool.

Actual behavior:

  • node_repl and 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-memory daemon 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_repl and MCP proxies).

ryofukutani avatar Jul 05 '26 19:07 ryofukutani

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:

  • macOS, Apple Silicon
  • Codex Desktop app
  • ulimit -n: 256
  • launchctl limit maxfiles: observed as 65536 unlimited, but Codex-spawned shell still inherited ulimit -n = 256

Observed app-server processes:

PID 4815
PPID 4709
elapsed: 01-21:44
command: /Applications/Codex.app/Contents/Resources/codex app-server --analytics-default-enabled
lsof line count: fd=334
PID 30519
PPID 30513
elapsed: 04-03:29
command: codex app-server --listen unix://
lsof line count: fd=175

There was also an orphaned launcher shell:

PID 30513
PPID 1
command: /bin/sh -c ... nohup codex app-server --listen unix:// ...

The GUI app-server had duplicated MCP children:

parent PID 4815:
  chrome-devtools-mcp: 9
  playwright-mcp: 10
  lightpanda mcp: 11
  node_repl: 9
  SkyComputerUseClient mcp: 11
  node ./mcp/server.bundle.mjs: 11
  node ./mcp/server.cjs --stdio: 9
  node ./mcp/server.mjs: 10
  node ./mcp/server.mjs --stdio: 10

The Unix-socket app-server also had duplicated MCP children:

parent PID 30519:
  chrome-devtools-mcp: 4
  playwright-mcp: 5
  lightpanda mcp: 5
  node_repl: 5
  SkyComputerUseClient mcp: 3
  node ./mcp/server.bundle.mjs: 5
  node ./mcp/server.cjs --stdio: 5
  node ./mcp/server.mjs: 4
  node ./mcp/server.mjs --stdio: 4

The generic ./mcp/server.* processes mapped back by cwd to plugin-bundled MCPs:

node ./mcp/server.mjs
  cwd: ~/.codex/plugins/cache/openai-curated-remote/openai-developers/1.2.3

node ./mcp/server.mjs --stdio
  cwd: ~/.codex/plugins/cache/openai-curated-remote/codex-security/0.1.10

node ./mcp/server.cjs --stdio
  cwd: ~/.codex/plugins/cache/openai-curated-remote/data-analytics/...

node ./mcp/server.bundle.mjs
  cwd: ~/.codex/plugins/cache/openai-curated-remote/creative-production/0.1.23

This eventually reproduced inside Codex as:

CreateProcess failed:
Too many open files (os error 24)

So this is not only memory/process accumulation; with a low inherited RLIMIT_NOFILE, the app-server can become unable to spawn new commands.

mochafreddo avatar Jul 06 '26 04:07 mochafreddo

Independent severe reproduction on macOS, adding Jetsam-level evidence to this MCP lifecycle leak. The system became unresponsive and required a manual restart.

Environment

  • Desktop bundle: ChatGPT/Codex 26.707.31123 (bundle build 5042)
  • Bundled app-server: codex-cli 0.144.0-alpha.4
  • macOS 26.5.1 (25F80)
  • Mac mini, Apple M4, 16 GB RAM

macOS Jetsam evidence

macOS wrote two JetsamEvent reports 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 node processes node in 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:

  • node count increased by 83
  • Codex-coalition process count increased by 82
  • all-node resident memory increased by 1.77 GiB
  • Codex-coalition resident memory increased by 2.13 GiB

At 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 node diagnostic report identifies the ownership chain as:

responsibleProc = ChatGPT
coalitionName   = com.openai.codex
parentProc      = node

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:

npm exec @playwright/mcp@latest
npm exec chrome-devtools-mcp@latest
npm exec xcodebuildmcp@latest mcp
node ./scripts/start-mcp.mjs
node ./mcp/server.mjs
.../cua_node/bin/node_repl

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.

qingye-lab avatar Jul 09 '26 22:07 qingye-lab

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

  • Ubuntu Linux, x86_64, long-running Codex app-server
  • App-server command: codex app-server --listen unix://
  • App-server launched by a managed systemd --user service
  • Inherited RLIMIT_NOFILE: soft 1024, hard 524288
  • Three global stdio MCP servers, each configured as: docker 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:

Failed to create unified exec process: No file descriptors available (os error 24)

The PTY path failed independently:

failed to openpty ... os error 24

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 /proc evidence before mitigation

The app-server process was captured at 1012 open FDs with a soft limit of 1024 (FDSize=1024, highest occupied FD 1023):

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 docker clients:

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:

/proc/sys/fs/file-nr: 29211  0  9223372036854775807
cgroup pids.current / pids.max: 2162 / 18153

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:

prlimit --pid <app-server-pid> --nofile=8192:524288

After that change, two non-PTY and two PTY executions of /bin/bash -c true, launched concurrently through unified exec, all exited 0. 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 docker child / 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

DongwonTTuna avatar Jul 11 '26 12:07 DongwonTTuna

Corroborating from a different surface: this also happens with codex-cli on Linux, so it is not Desktop- or macOS-specific.

Environment

  • codex-cli 0.144.3 (terminal CLI, --dangerously-bypass-approvals-and-sandbox)
  • Debian Linux x86_64, 32 GB RAM
  • stdio MCP servers from ~/.codex/config.toml: ferrex (Rust memory server, loads ~2 GB of embedding models at initialize) and a python RAG server via uv run

Observation (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:

    PID    PPID     ELAPSED  VmSwap  CMD
3510714 3510112    05:22:28  1997MB  ferrex
3934474 3510112    03:36:37  1997MB  ferrex
3935803 3510112    03:36:29  1997MB  ferrex
4064556 3510112    03:05:07  1997MB  ferrex
(+4 matching uv/python MCP children with the same spawn times)

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.

Lenvanderhof avatar Jul 13 '26 08:07 Lenvanderhof

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:

  • Windows 11 Home, x64, build 26200
  • Codex Desktop package 26.707.12708.0
  • 32 GB RAM
  • Several long-running local tasks across multiple repositories
  • A mix of global, project-scoped, and plugin-provided stdio MCP servers

I 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:

  • About 8 minutes after restart, 7 matching runtime bundles were live.
  • About 15 minutes after restart, 12 bundles were live.
  • During one 10-second readback window, the bundle count increased from 10 to 12 while the older bundles remained alive.

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 = false before 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-only child 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:

  • A task that becomes notLoaded, is archived, or is evicted should release its stdio transports and terminate the complete process tree after a bounded grace period.
  • Plugin MCP entries with enabled = false should not be started for newly loaded task runtimes.
  • The number of runtime bundles should stay bounded instead of increasing with long-running multi-task use.

I have a sanitized PID and lifecycle matrix and can provide it without local paths, project names, session content, or credentials.

rwang23 avatar Jul 16 '26 18:07 rwang23

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 the codex.exe bridge 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.exe hosts, 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:39Z to 14 each at 21:57Z without 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-only flag 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:

  • Expose a stable task or runtime owner ID in process diagnostics.
  • Close the stdio transport and the complete Windows process tree when that owner is archived, evicted, or unloaded.
  • Start global and plugin MCP servers on first use, then apply an idle eviction policy.
  • Honor enabled = false before 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.

rwang23 avatar Jul 16 '26 22:07 rwang23

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

  • Codex Desktop: 26.715.21425
  • Bundled CLI: codex-cli 0.145.0-alpha.18
  • macOS 26.5.2 (25F84), Apple Silicon (arm64)
  • 128 GB RAM, 20 logical CPUs
  • Relevant global stdio MCP definitions:
    • npx -y chrome-devtools-mcp@latest
    • uvx --from git+https://github.com/oraios/serena serena start-mcp-server --project-from-cwd --context codex
    • headroom mcp serve

Observed failure

After a long-running desktop session with many threads/background agents, the host became nearly unusable. A process snapshot showed:

  • Load average around 191 / 512 / 636 at capture time (earlier samples were approximately 520-686)
  • 373 live chrome-devtools-mcp processes, consuming about 898% aggregate CPU
  • 362 uv launcher processes plus 362 Python Serena server processes (about 724 Serena-related process entries)
  • 386 headroom mcp serve processes
  • 1,291 Node processes in total
  • About 2,877 zombie children below the bundled Codex app-server process (2,884 zombies 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: 1
  • Serena server: 1
  • Headroom server: 1
  • Aggregate CPU for those three: 0% at the verification sample
  • System memory free: 94%

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.

sleepfrontofmtv avatar Jul 17 '26 09:07 sleepfrontofmtv

Additional reproduction on the current unified ChatGPT/Codex macOS app, with a strong per-tool-execution lifecycle correlation.

Environment

  • ChatGPT/Codex app build: 26.715.21425
  • Codex Framework: 150.0.7871.124
  • Bundled Codex CLI: 0.145.0-alpha.18
  • macOS: 26.5.1 (25F80)
  • Apple M5, 16 GB RAM

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 mcp root 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:

  • xcodebuildmcp
  • a local SEO MCP
  • a local site/CLI MCP
  • plugin-provided Node MCP servers
  • Computer Use event stream
  • Node REPL

This 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:

  • 954 total processes / 8,032 threads
  • 381 direct children under one codex app-server
  • 297 node processes
  • about 41–42 copies of several MCP roots
  • load averages around 28–36
  • system CPU around 64%
  • 23.8–24.4 GB swap used on a 16 GB Mac
  • roughly 740–790 MB/s disk reads during the paging storm
  • no thermal warning and more than 120 GB free storage

The app-server itself sampled around 83–148% CPU.

Terminating only the duplicated MCP trees removed 472 processes:

  • total processes fell from about 951 to 465
  • node processes fell from 307 to 17
  • swap began unwinding immediately, falling from about 24.4 GB to 13.3 GB within seconds

Relative cost seen locally

Among three specialized globally configured servers, summed RSS per retained tree was approximately:

  • xcodebuildmcp: 90–300 MB
  • SEO MCP: about 110 MB across four processes
  • local site/CLI MCP: about 36 MB

RSS 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.toml files 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.

andheller avatar Jul 17 '26 13:07 andheller

Additional Windows reproduction on a newer Codex Desktop build, showing partial cleanup but rapid recreation of complete MCP process pools.

Environment:

  • Codex Desktop 26.715.2305.0
  • Windows 11 Pro 25H2, build 26200.8037, x64
  • Main app-server: codex.exe, parent ChatGPT.exe

Observed:

  • 755 total processes at capture time, including 258 node.exe and 239 cmd.exe.
  • The main app-server tree reached 522 descendants, 3,921 threads, 106,740 handles, and 17.69 GB private memory.
  • A typical complete runtime pool contained eight MCP servers, node_repl, two plugin server.mjs processes, and their cmd/npx/node children: 31 processes and approximately 1.07–1.24 GB private memory.
  • Some pools remained alive for more than five hours.
  • At least 19 matching GitHub-MCP/node_repl pools were alive, while native list_threads returned only 10 recent tasks: 3 active, 2 idle, and 5 notLoaded.
  • Cleanup was not strictly absent: over 66.7 seconds, the classified pool count changed from 14 to 13 while 45 PIDs appeared and 107 disappeared. However, a new complete pool was created during that interval.
  • Additional agent/tool executions correlated with new complete pools at 17:14:07, 17:14:16, 17:14:25, 17:14:32, and 17:14:37.

Performance impact:

  • During a clean 10.76-second sample, the app-server tree consumed 9.81% of total capacity across 16 logical CPUs.
  • System context switches averaged 175,583/s and peaked at 214,986/s; processor queue peaked at 7.
  • DPC, interrupts, disk queue, and available RAM did not indicate hardware, storage, or memory exhaustion.
  • The user observed visible Desktop freezes and mouse stutter.

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.

aidawilliam41-ops avatar Jul 17 '26 14:07 aidawilliam41-ops

Independent reproduction on the current macOS Desktop build, with a concrete pooling proposal.

Environment

  • Codex Desktop 26.715.21425 (build 5488)
  • Bundled CLI 0.145.0-alpha.18
  • Darwin 24.6.0 arm64
  • 48 GiB RAM

Observation

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 890 to 913, then to 945, without restarting the app-server.

At the final snapshot:

  • 945 MCP-related Node processes
  • about 19.2 GiB aggregate MCP RSS (RSS includes shared mappings, so this is not unique physical memory)
  • 789 Node processes were direct children of the Desktop app-server
  • those direct children accounted for about 16.5 GiB aggregate RSS
  • the app-server itself was using about 1.8 GiB RSS

The 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:

  1. Pool shareable upstreams by a canonical configuration fingerprint: transport, command/URL, arguments, cwd, plugin version, and names of forwarded environment variables. Secret values must not appear in diagnostics or pool keys.
  2. Give threads and subagents lightweight leases on pooled upstreams. Release leases on completion, interruption, archive, unsubscribe, or eviction.
  3. Start stdio upstreams lazily on first tool use and stop them after a bounded idle TTL when the reference count reaches zero.
  4. Add an explicit scope for servers that cannot be shared safely: global, project, or session. Stateful browser/computer-control servers should not be silently pooled across unrelated tasks.
  5. Connect native Streamable HTTP upstreams directly instead of creating a local stdio bridge per session.
  6. Enforce a global app-server budget for MCP process count, RSS, file descriptors, and startup rate. Surface the owning server, scope, lease count, last tool call, and idle deadline in Desktop diagnostics.
  7. Add a “Restart MCP runtime” action that restarts only the broker/upstreams, without terminating active Codex 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.

iddictive avatar Jul 18 '26 07:07 iddictive

Correction and narrowed scope for this Fedora datapoint.

This reproduction used the official managed standalone Codex CLI 0.144.6 in app-server mode, 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:

  • the client does send thread/unsubscribe
  • app-server returns status: unsubscribed
  • the local Linux integration does not patch the thread/unsubscribe / thread/closed lifecycle

I also ran an isolated 0.144.6 app-server probe with a disposable, well-behaved stdio MCP server:

  • thread/unsubscribe left the MCP alive, which matches the documented 30-minute unloaded-thread residency
  • thread/archive transitioned the thread to notLoaded and the corresponding MCP process exited
  • stopping app-server also removed the remaining probe process

Therefore 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.6 app-server report should correlate a specific MCP PID with thread/closed or an explicit archive/unload boundary and show that it survives that boundary.

kkkzbh avatar Jul 19 '26 09:07 kkkzbh

Independent reproduction on a newer macOS Codex Desktop build.

Environment

  • Codex/ChatGPT Desktop: 26.715.72028 (build 5706)
  • Bundled Codex Framework: 150.0.7871.124
  • macOS: 26.4 (build 25E246)
  • Architecture: Apple Silicon / arm64
  • Physical memory: 24 GiB
  • Desktop uptime when captured: about 43h 46m

Observed process retention

A process snapshot reported:

  • 63 Codex/ChatGPT-related processes
  • 72 MCP / Computer Use helper processes
  • 3 zombie processes
  • 3 detached cua_node ... kernel.js processes with PPID=1

The persistent Desktop app-server had repeated direct-child groups with this shape:

.../Contents/Resources/cua_node/bin/node_repl
node ./mcp/server.cjs --stdio
node ./mcp/server.mjs

The oldest retained group had been alive for about 1 day 17h 55m. Several other groups were older than one day, two hours, or tens of minutes while sleeping at 0% CPU.

During the controlled investigation, sequential tool calls created three additional complete node_repl + server.cjs + server.mjs groups within about five minutes. Completed calls did not remove the earlier groups; every group remained a direct child of the same long-lived app-server.

Controlled cleanup result

I sent SIGTERM only to:

  • helper groups idle for more than 10 minutes,
  • the three confirmed PPID=1 orphan kernels, and
  • descendants of one stale tool-host sandbox.

The active Desktop/app-server processes, current tool helpers, and unrelated application processes were explicitly preserved.

Result: 48 stale helper processes exited successfully, while Codex Desktop and the active task continued running. This confirms that these were retained helper trees rather than required Chromium virtual-memory mappings.

Performance correlation

At capture time:

  • system disk throughput was 50–123 MiB/s,
  • ~/.codex/logs_2.sqlite was about 348 MiB,
  • its WAL was about 65 MiB,
  • multiple Codex app-server processes had the same database and WAL open.

There was no pageout or swapout increase during the capture. The apparent 1.87 TiB VSZ was verified as sparse Chromium/V8 address space (physical footprint about 519 MiB), so it is not the cause being reported here.

Expected behavior

Tool-scoped MCP/Node REPL processes should be terminated when a tool call or owning task runtime completes, or reused through a bounded pool with idle eviction. Detached PPID=1 kernels should also be reaped.

Additional evidence

A timestamped local diagnostic bundle contains the process tree, elapsed times, memory pressure, SQLite sizes, disk I/O samples, and a main-process stack sample. I have not attached the raw bundle because it includes local project paths and command arguments, but I can provide a sanitized version if maintainers need it.

LeiGitHub1024 avatar Jul 24 '26 05:07 LeiGitHub1024

Additional Windows reproduction on a newer Desktop build, with Goal-mode correlation

I am seeing the same unbounded per-thread/per-runtime STDIO MCP process retention on Windows in a newer build:

  • Codex Desktop package: OpenAI.Codex_26.721.3996.0_x64
  • Platform: Windows x64
  • One long-lived codex.exe app-server
  • Snapshot: 118 descendant processes
  • A slightly earlier aggregate of 116 descendants used approximately 3.87 GB working set / 3.55 GB private memory

The MCP descendants formed 11 near-identical creation-time batches under the same app-server. Each batch contained one instance of several independently implemented STDIO servers (node_repl, Node-based filesystem tools, a Python MCP, and a native MCP). One npm-based Gmail MCP contributed a three-process launcher chain per batch.

Observed totals for the recognizable MCP roles:

Role Processes
Gmail MCP launcher/server chain 33
Python MCP 12
Node REPL MCP 11
Native MCP 11
Filesystem MCP A 11
Filesystem MCP B 11

The batches were created in synchronized bursts. Several bursts created two complete MCP sets in the same minute. The processes remained alive after the work that created them had finished.

Most of these bursts occurred while a persisted Goal was active and auto-continuing. This suggests Goal continuation/resume may enter the same MCP-manager initialization path, and possibly combines with #32793 (concurrent Goal auto-continuations across app-server processes). I have not yet proven a strict one-to-one mapping from every Goal transcript turn to every process batch, but the creation-time clustering is strong and the complete MCP fleet is repeated each time.

This also matches the Windows/subagent evidence in #34658, but the workload here was centered on Goal auto-continuation rather than intentionally spawning many subagents.

Additional observations:

  • The MCP tools did not need to be deliberately invoked; complete configured fleets appeared during runtime/thread initialization.
  • Setting every raw MCP entry to enabled = false did not affect the already-running app-server immediately; it retained its startup configuration and another child appeared afterward.
  • A full Codex Desktop restart is therefore required to clear the retained trees and load the disabled settings.
  • The practical impact was severe Codex input/rendering latency plus noticeable machine-wide sluggishness.

Expected behavior would be bounded ownership: reuse/share an MCP client where safe, start servers lazily, or terminate the complete STDIO process tree when the owning thread/runtime/Goal continuation finishes.

onmokoworks avatar Jul 24 '26 17:07 onmokoworks

Reproduced on Codex 0.145.0 with Neon MCP 0.6.5. Codex spawned 13+ local workers despite remote OAuth configuration; one reached ~4.2 GiB RSS and 438% CPU in under a minute. Eight workers later totaled ~26.3 GiB, causing system-wide input/audio failure and a reboot. Related: #18881, #17832.

brannn avatar Jul 26 '26 00:07 brannn

I found a distinct trigger for this multiplication: Codex’s hidden internal tasks.

During one visible task, Codex started four Serena processes for the same project within 23 seconds; each launched its own rust-analyzer. One startup was directly tied to the visible task. Two others coincided with app-server’s ambient_suggestions and thread_title tasks, and the fourth with an unlabeled thread/start. The latter mappings are timestamp-based because Serena logs lack Codex thread IDs.

Existing reports cover user-created threads, subagents, Goals, and process retention. This suggests non-user-visible internal tasks also inherit and eagerly initialize the user’s MCP configuration.

TyceHerrman avatar Jul 28 '26 17:07 TyceHerrman

Follow-up: displaying a completed automation thread reproducibly starts a thread-correlated MCP/helper process bundle

This is a current-build follow-up to #30408, not a claim that every part of the original report still behaves the same way.

Executive summary

On the tested macOS Codex App build and helper configuration:

  • unarchiving a completed automation thread without displaying it did not change the measured MCP/helper process count;
  • navigating to and displaying that completed thread changed the count by exactly +10 in each of two reversible A-B-A replications;
  • explicitly rearchiving the thread and returning away from it changed the count by exactly -10, back to the prior baseline;
  • a third completed thread reproduced the distinction between “unarchive only” and “display/load”;
  • no MCP tool was invoked during the display step.

The narrow conclusion is that navigating to/displaying the tested completed automation threads was the observed eager-start trigger for a thread-correlated MCP/helper process bundle in this build. The experiment does not distinguish rendering from other task-activation work performed by the app, does not establish the internal code-level cause, and does not show that every thread type, platform, or MCP configuration behaves this way.

For quick triage, the shortest path through this comment is:

  1. Actual behavior in this build
  2. Test environment
  3. Minimal reproduction
  4. Primary results
  5. Evidence-supported conclusions and limits

The investigation chronology, reporting decision, template-alignment notes, and attachment decision are included later in collapsible sections.

Actual behavior in this build

Displaying the history of a completed local scheduled-automation thread started a repeated set of local MCP/helper processes even though no MCP tool was invoked. The added processes remained present across the three short samples collected during each displayed phase. Explicitly rearchiving the tested thread and returning away from it restored the matching process count to the previous baseline.

This differs from the exact cleanup behavior described in the original #30408 report: the combined rearchive-and-return step restored baseline in this reproduction, while display/load still eagerly started a thread-correlated helper set. Because rearchiving and returning away were performed together, this experiment does not establish which part of that combined step performed the cleanup. It is also not proof that archive cleanup is fixed globally.

Test environment

  • Codex App: 26.721.81911 (CFBundleVersion 5973)
    • Values were read from the active signed app bundle used during the test.
  • Bundled CLI/app-server: codex-cli 0.146.0-alpha.3.1
  • Platform, exact uname -mprs output: Darwin 27.0.0 arm64 arm
  • macOS: 27.0 (26A5378n)
  • Hardware: Apple M2, 16 GB RAM
  • Node.js: v24.15.0
  • Thread type tested: completed local scheduled-automation run threads
  • Enabled local helpers included:
    • xcodebuildmcp
    • Playwright MCP
    • Context7 MCP
    • Chrome DevTools MCP
    • bundled node_repl
    • Computer Use
    • uv-launched helpers

Subscription plan, session/thread IDs, token-limit usage, and context-window usage are intentionally omitted; the reasons are documented in the collapsed “Template alignment and intentional deviations” section below.

Minimal reproduction

  1. Configure multiple local MCP/helper integrations in Codex App.
  2. Choose two completed scheduled-automation threads and place both in the archived state.
  3. Collect three short baseline samples of the fixed MCP/helper matcher count (A0).
  4. Unarchive and display thread 1 without invoking an MCP tool; collect three samples (B1). Rearchive it, return away, and collect three samples (A1).
  5. Unarchive and display thread 2 without invoking an MCP tool; collect three samples (B2). Rearchive it, return away, and collect three samples (A2).
  6. With a third archived completed thread, collect three samples in each of four phases: archived baseline, unarchive-only without display, navigate to/display, then rearchive-and-return.

The primary metric was a system-wide count of unique PIDs matching the same OR-expression in every phase:

npm exec .*mcp
node_repl
SkyComputerUseClient
xcodebuildmcp
context7-mcp
playwright/mcp
chrome-devtools-mcp

An equivalent read-only counter is:

LC_ALL=C ps -axo pid=,command= |
awk '
  /[n]pm exec .*mcp|[n]ode_repl|[S]kyComputerUseClient|[x]codebuildmcp|[c]ontext7-mcp|[p]laywright\/mcp|[c]hrome-devtools-mcp/ {
    if (!seen[$1]++) {
      count++
    }
  }
  END {
    print count + 0
  }
'

The character-class spelling, such as [n]ode_repl, prevents the counter command from matching its own command line. Exact process names will vary with the configured helpers.

Measurement design

Before changing thread state for the controlled crossover, I designated:

  • Primary outcome: the identically defined MCP/helper matcher count, sampled three times in every phase.
  • Mechanism check: direct-child counts under the live Codex app-server for node_repl, npm, Computer Use, and uv.
  • Secondary outcomes: total process count, summed RSS of matching processes, swap, load average, and an unrelated persistent high-CPU process as a negative control.

The experiment used:

  • two completed automation threads for a reversible A-B-A crossover; and
  • a third completed automation thread to separate the unarchive metadata change from navigating to/displaying the thread.

No process was manually signaled or killed. No application, container, build, download, or VM was stopped. All three test threads were returned to their original archived state.

Primary results

Two-thread reversible crossover

Phase Operation MCP/helper process count
A0 Rearchived baseline 131, 131, 131
B1 Unarchive and display completed thread 1 141, 141, 141
A1 Rearchive thread 1 and return 131, 131, 131
B2 Unarchive and display completed thread 2 141, 141, 141
A2 Rearchive thread 2 and return 131, 131, 131

Observed effect for this matcher and these two threads:

display/load:  +10
rearchive:     -10

Trigger separation with a third thread

Operation MCP/helper count Direct-child tuple
Rearchived baseline 131, 131, 131 14/53/14/13
Unarchive only; do not display 131, 131, 131 14/53/14/13
Navigate to/display the thread 141, 141, 141 15/57/15/14
Rearchive and return 131, 131, 131 14/53/14/13

Direct-child tuple order:

node_repl / npm / Computer Use / uv

This identifies navigating to/displaying the task as the observed trigger in this reproduction. It does not distinguish the visual rendering action from broader task activation, restoration, or app-server initialization performed at the same time.

Direct-child mechanism evidence

In the clean second crossover replicate (A1 -> B2 -> A2), direct children of the live Codex app-server changed reversibly:

node_repl / npm / Computer Use / uv
14 / 53 / 14 / 13
15 / 57 / 15 / 14  # one completed thread displayed
14 / 53 / 14 / 13  # thread rearchived

Under this configuration, displaying one tested completed thread coincided with:

  • four additional direct npm children;
  • one additional direct node_repl;
  • one additional direct Computer Use client;
  • one additional direct uv; and
  • descendants bringing the fixed MCP/helper matcher increase to exactly ten.

Because the matcher includes Computer Use, node_repl, and uv-launched helpers, this report uses “MCP/helper process bundle” rather than describing all ten processes as MCP servers.

Expected behavior

Merely displaying the history of a completed or idle automation thread should not eagerly start a full configured MCP/helper set when no MCP tool is invoked during the display step.

If eager initialization is required by design, I would expect the ownership and cleanup behavior to be bounded and observable—for example, cleanup after leaving the thread or after an idle/completion period.

Resource impact

In the clean second crossover replicate, summed RSS for the matching MCP/helper processes changed as follows:

Phase Summed matcher RSS
Rearchived baseline approximately 1,852 MiB
Thread displayed approximately 2,449 MiB
Thread rearchived approximately 1,903 MiB

The displayed phase was therefore approximately 546–597 MiB (0.53–0.58 GiB) above the adjacent archived measurements in that replicate. This is not presented as an exact per-thread physical-memory cost:

  • summed RSS may count shared pages more than once;
  • startup and cache state may affect RSS;
  • only one clean RSS replicate is being cited; and
  • the exact reversible +10/-10 process-count result is the stronger finding.

Total-process medians moved in the same direction but drifted in the background:

A0 731
B1 764
A1 742
B2 758
A2 748

Those totals support direction only; they do not establish an exact total-process cost per displayed thread.

Swap moved from approximately 7,113.94 MiB before the first load to 7,244.81 MiB after it and ended at 7,228.81 MiB. Because swap is hysteretic and did not promptly reverse, it is excluded from the causal claim.

Evidence-supported conclusions and limits

Classification Statement
Directly observed Unarchive-only produced no matcher-count change for the third tested thread.
Directly observed Displaying each of two tested completed threads produced the same +10 matcher count in all three short samples.
Directly observed Rearchiving each tested thread and returning away restored the prior matcher count.
Directly observed The app-server direct-child tuple changed and reversed with the displayed/rearchived state.
Supported inference The added processes form a thread-correlated MCP/helper set under this configuration.
Not established Whether rendering, task activation, state restoration, or another simultaneous app-server action is the internal trigger.
Not established Whether all Codex thread types, platforms, app versions, or helper configurations behave the same way.
Not established An exact unique physical-memory cost per thread.
Not established That the earlier system-wide swap, load-average, or disk-space improvement was caused solely by archiving.
Not established That the original archive-cleanup problem in #30408 is fixed globally.

Current safe workaround

For the three tested automation threads on this build, explicitly archiving a completed thread and returning away from it restored the matcher count to baseline. This is a reversible workaround, not a general fix or a guarantee for other thread types/configurations.

Possible engineering directions

These are non-prescriptive possibilities, not claims about the current implementation:

  • initialize local MCP/helper processes lazily on first tool use;
  • pool or share compatible stateless helper connections;
  • tear down thread-correlated helper sets after a bounded idle/completion period;
  • expose process ownership and lifecycle state in diagnostics.

The automation-history UX is related but distinct from the process-lifecycle bug; see #30515. Eager per-session MCP startup is also tracked in #21984.

Sources and evidence provenance

Sources were verified on 2026-07-30 JST. Official repository documents are linked to fixed commits to avoid later main-branch drift. No secondary articles or third-party documentation were used.

Official OpenAI repository guidance

  1. Codex contributing guide, commit d53e68954acee2eb50303970498ffebddff393ed
    • Governs the reporting-path decision.
    • It asks users to verify whether an existing bug report covers the issue and encourages reproduction details, analysis, root-cause hypotheses, and high-level fix ideas directly in the issue thread.
  2. Codex App bug-report template, commit 12f69b893f10393ef48fa8a3ac460a8b6f4438f7
    • Defines the environment, actual behavior, reproduction, expected behavior, and additional-information fields used to structure this comment.

Prior primary reports in the official repository

These are primary reports from repository users, not authoritative product specifications:

  1. #30408: MCP server processes leak: per-thread processes never cleaned up
    • Primary target because it covers Codex App/app-server MCP process lifecycle and memory impact.
  2. #21984: MCP servers eagerly start per session
    • Related eager-start behavior.
  3. #30515: Codex App automations clutter the main thread list
    • Related automation-history lifecycle and UX context.

Direct local evidence

All numerical results in this comment are direct observations from the tested Mac on 2026-07-30 JST. They were collected with short, bounded, read-only process/system commands, except for the explicitly authorized reversible thread archive/unarchive/display operations used in the crossover. No prompt contents, user paths, account identifiers, or session/thread IDs are included.

Investigation chronology and decision trail

1. Initial health check

A bounded Mac health check found both:

  • an unrelated, persistent File Provider CPU problem; and
  • a large number of repeated Codex MCP/helper processes.

At the degraded observation point:

  • total processes: 1,156;
  • fixed MCP/helper matcher count: 349;
  • summed matcher RSS: approximately 1,804 MiB;
  • swap used: approximately 17,011.44 MiB of 18,432 MiB; and
  • memory-pressure output reported 32% free.

The File Provider problem was kept separate from the Codex/MCP investigation because it remained active after the Codex-thread action.

2. First reversible remediation

Twenty-five completed, inactive runs of the same monitoring automation were archived. Active work and unrelated active tasks were preserved.

Immediately afterward:

Measurement Before After
Total processes 1,156 760
MCP/helper matcher count 349 119
Summed matcher RSS approximately 1,804 MiB approximately 929 MiB
Swap used approximately 17,011.44 MiB approximately 7,193.94 MiB
Memory-pressure free percentage 32% 45%
Load average 6.82 / 6.59 / 6.85 4.10 / 3.55 / 4.46

These were observational before/after measurements. They motivated the controlled test but were not treated as sufficient proof that archiving alone caused every system-wide improvement.

In particular:

  • the unrelated File Provider process remained at approximately 92–94% CPU;
  • swap and load average can lag or vary for unrelated reasons; and
  • APFS free-space changes were excluded from causal attribution.

3. Decision to require a controlled test

The initial process-count reduction was large and consistent with completed threads releasing repeated helper sets, but spontaneous idle cleanup and macOS memory/swap housekeeping could not be excluded.

A strict unarchive/display/rearchive test was initially deferred because it would deliberately reintroduce load. It was performed only after explicit permission for that reversible test.

4. Controlled crossover

Two completed threads were tested with the same primary outcome and three samples per phase:

A0 baseline
-> B1 display thread 1
-> A1 rearchive
-> B2 display thread 2
-> A2 rearchive

The exact 131 -> 141 -> 131 -> 141 -> 131 pattern was reproduced, with each phase stable across all three short samples.

5. Trigger-separation control

A third completed thread separated:

rearchived baseline
-> unarchive without display
-> navigate to/display
-> rearchive and return

Unarchive-only remained at baseline. The +10 change appeared only after navigating to/displaying the thread and reversed after rearchiving.

6. Reporting-path decision

The finding was classified as a reproducible Codex App/app-server process-lifecycle bug or behavioral defect, not a setup-help question.

The official contributing guide favors adding analysis and reproduction evidence to the relevant issue thread. #30408 was selected as the primary target because it already covers Codex App MCP process lifecycle and memory impact. #21984 and #30515 are linked as related but distinct issues.

Template alignment and intentional deviations

This is a detailed comment on an existing issue, not a new issue submission. The current Codex App bug-report template was nevertheless used as the structural baseline.

Template expectation Status Treatment and rationale
Search for an existing issue Complied #30408 was identified as the closest existing Codex App/app-server/MCP lifecycle report.
Prefer a reaction over a duplicate comment Intentional exception This is not a bare duplicate or “me too” report. It adds materially new current-build evidence: the combined rearchive-and-return step restored baseline, display/load was separated from unarchive-only, and the +10/-10 lifecycle result was replicated. The contributing guide explicitly invites reproduction details and analysis in the issue thread.
Codex App version Complied with equivalent source Exact version/build values are included. They were read from the active signed app bundle rather than manually transcribed from the About dialog.
Subscription plan Intentionally omitted This is an existing-issue comment, and subscription tier is not part of the tested local process-lifecycle mechanism. It can be supplied if a maintainer identifies a diagnostic need.
Platform Complied Exact uname -mprs output, macOS version/build, architecture, chip, and memory are included.
Actual issue Complied An explicit “Actual behavior” section appears near the top.
Reproduction steps Complied Numbered steps, the fixed matcher definition, an executable read-only counter, repeated phase measurements, and the third-thread control are included.
Session/thread ID Intentionally omitted as not applicable The result was reproduced across three completed threads and does not depend on one session-specific trace. Publishing identifiers is unnecessary for the initial report. One representative ID can be supplied if a maintainer requests trace correlation.
Token-limit and context-window usage Intentionally omitted as not applicable No token-limit or context-window boundary was involved in the display-triggered process change.
Expected behavior Complied Included explicitly and phrased as an expectation rather than an implementation assertion.
Additional information Complied Resource impact, limitations, workaround, possible directions, related issues, provenance, and safety controls are included.
PII redaction and text-first evidence Complied The document contains text and tables, not screenshots; prompt contents, private user paths, account identifiers, and thread IDs are excluded.
Why no CSV or diagnostic archive is attached

A CSV is not required by the Codex App bug template. For this experiment, the complete primary dataset is only five crossover phases with three identical count samples per phase, plus a four-phase trigger-separation control. The full values are therefore easier to review in the Markdown tables above.

No original timestamped CSV was captured during the experiment. Reconstructing a CSV afterward from summary notes could imply sample-level timestamp precision or provenance that does not exist, so no synthetic CSV is being attached.

If maintainers request a new run, a timestamped machine-readable capture can be collected prospectively with fields such as:

timestamp
build
phase
thread_state
thread_displayed
sample_index
matcher_count
node_repl_children
npm_children
computer_use_children
uv_children
matcher_rss_kib
total_process_count

No broad diagnostic archive is attached because it may contain unrelated paths, commands, or session metadata. A narrowly scoped, redacted capture can be supplied if a maintainer identifies the exact fields needed.

Anionix avatar Jul 30 '26 15:07 Anionix

Still present on 0.146.0-alpha.9.2, and the accumulation is linear with app-server uptime, not load

Another macOS reproduction, with a controlled restart that pins down the mechanism and a same-machine control from a different agent host.

Environment

  • Bundled CLI: codex-cli 0.146.0-alpha.9.2 (/Applications/ChatGPT.app/Contents/Resources/codex ... app-server) — newer than any build cited above in this thread
  • macOS 26.4.1, arm64, 128 GB
  • 34 [mcp_servers.*] blocks in ~/.codex/config.toml

1. A fresh app-server is correct; it degrades purely as a function of uptime

I tore the previous app-server down cleanly and re-measured the replacement twice:

app-server uptime direct MCP children
~10 min 19 — one clean fleet
82 min 116
11 h 16 m (prior instance) 464 → 541 over a 30-min observation window

≈1.4 children/min, roughly one new fleet every ~12 minutes, with no correlation to how much I was actually using it. A newly started app-server spawns exactly one fleet and is behaving correctly. This rules out a per-server leak or a runaway individual server, and is consistent with the per-conversation-fleet-never-reaped mechanism in the original report.

2. The uniform count is the tell

At the 11 h mark the prior instance held exactly 24 copies of every configured server — identical count across xcodebuildmcp, node_repl, n8n-mcp, cua-driver and four others, no outliers. Subtree: 890 total descendants, 32.3 GB RSS.

Uniformity across heterogeneous servers (Node, Python, Rust, native) means whole fleets are being duplicated, not that any one server is failing to exit.

3. Same-machine control: a session-owned parent does not accumulate

Measured at the same moment on the same machine, with a comparable MCP config: 11 live Claude Code sessions, each holding a steady 21–22 children, zero accumulation. There the session process is the MCP parent, so a fleet dies with its owner.

The difference is architectural rather than a bug in any individual server: the Codex app-server is a long-lived singleton host, so per-conversation fleets have no owner whose exit terminates them. That also explains why fleet count tracks app-server uptime rather than thread count or activity.

4. Hazard worth flagging for anyone applying a manual workaround

Killing the app-server PID first makes things strictly worse. All ~890 descendants get reparented to launchd, converting them into genuine orphans and freeing nothing — you lose the one handle that could still reach them. Teardown has to go children-first (deepest-first), then the parent.

Second caveat: on this machine live xcodebuild test runs are also children of the same app-server, so a blind subtree kill will silently take out in-flight builds. Any teardown — manual, or an eventual idle-reaper implementation — needs to check for in-flight work rather than killing the subtree wholesale.

5. Impact and recovery

Before teardown the machine was at 418 MB unused / 55 GB compressor / load average 155. After a children-first teardown of 630 descendants, ~70 minutes later: 39 GB unused / 9.7 GB compressor / load 10.7.

So the teardown is an effective mitigation — but it has to be repeated as uptime accrues, which makes it a chore rather than a fix.

Asks (unchanged from the original report, restated with this evidence behind them)

  1. Terminate a conversation's MCP fleet when the conversation closes.
  2. Failing that, expose an idle-reap or max-fleet knob — startup_timeout_sec and tool_timeout_sec are the only lifetime-adjacent knobs available today and neither bounds process lifetime.
  3. On app-server shutdown, reap the fleet children rather than orphaning them to launchd.

lightcloud00 avatar Jul 31 '26 21:07 lightcloud00