Skip to content

Codex app appears to start duplicate MCP server processes across conversations #22992

Open

Description

@Deniskoyyy

Component

Codex desktop app / MCP server lifecycle

What happened?

I noticed that the Codex app appears to start separate MCP server instances for different conversations, even when they are the same MCP servers with the same configuration.

Over time, these processes accumulate and duplicate each other.

On my home PC, I recently saw 14 instances each of four MCP servers, around 56 processes total.

I also checked my MacBook and saw a similar pattern:

  • multiple serena MCP server processes;
  • multiple context7 wrapper/server processes;
  • multiple node_repl processes;
  • multiple codex app-server --listen stdio:// processes.

The processes appeared to accumulate in batches as I worked with different sessions/conversations.

Expected behavior

If several conversations use the same MCP servers with the same configuration, Codex should ideally reuse a shared MCP runtime/server instance, or clean up inactive instances when the conversation that owns them is no longer active.

At minimum, old inactive MCP server processes should not accumulate indefinitely during long-running app usage.

Actual behavior

Repeated MCP server instances can remain running at the same time.

This creates extra memory/process overhead. It is not always immediately critical, but after long-running work it can become significant.

Why this matters

Many Codex users configure multiple MCP servers. If every active or previously opened conversation starts its own duplicate set, the number of background processes can grow quickly.

For example, 14 copies of 4 MCP servers becomes 56 processes. Even if each process is modest, the combined memory/process overhead adds up and can make the app feel heavier over time.

Possible direction

Potential approaches:

  • shared MCP runtime across conversations when the server command/configuration is identical;
  • reference-counted MCP process lifecycle;
  • more aggressive cleanup of MCP servers attached to inactive/closed conversations;
  • diagnostics in the app showing which MCP processes are running and which conversation owns them.

Related issues / discussion

Related broader discussion:
#22987

Related large-session performance issue:
#22991

Environment

Observed on:

  • Windows home PC, where I saw around 56 MCP-related processes in one case;
  • macOS MacBook, where I saw repeated serena, context7, node_repl, and codex app-server --listen stdio:// processes.

I can provide exact OS/app versions and process-list snippets if helpful.

Activity

  1. added
    bug
    app
    mcp
    app-server
    on May 16, 2026
  2. github-actions commented on May 16, 2026

    @github-actions
    Contributor

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

    Powered by Codex Action

  3. Deniskoyyy commented on May 16, 2026

    @Deniskoyyy
    Author

    Adding a small Windows tray screenshot related to the MCP duplication symptom.

    Related Community thread:
    https://community.openai.com/t/feedback-from-a-remote-codex-helper-prototype-long-session-performance-durable-queue-and-mcp-process-reuse/1381062

    In this screenshot, several Serena instances are visible at the same time. This matches the duplicated MCP/server process accumulation pattern I described above.

    This screenshot is only a visual symptom, not a full process-list proof. I can follow up with Task Manager / Activity Monitor or process-list output if useful.

    Image
  4. TyceHerrman commented on Oct 19, 2026

    @TyceHerrman

    Additional macOS evidence from Desktop 26.1013.40934, bundled CLI 0.163.0-alpha.10.2.

    During a slowdown on October 19, a process capture showed 128 Node-related tool workers under the main Codex backend: 50 Node REPL workers, 38 server.mjs workers, 20 CUA REPL launchers, and 20 Codex Security MCP workers.

    Their summed physical footprint was approximately 3.6 GiB, although summed RSS was only about 206 MiB. Physical footprint was measured with proc_pid_rusage; these totals are not system-wide unique resident RAM.

    This supports the repeated tool-runtime accumulation described here, but I have not established that every worker belonged to an inactive chat or should already have exited.

    this may be be related to #26773's orphaned nested Codex backends but unclear if they have the same cause

  5. biuro-ctrl commented on Nov 19, 2026

    @biuro-ctrl

    Additional Linux Desktop observation, Codex App 0.170.0 (read-only, no cleanup attempted)

    This matches the process duplication pattern described here, but I cannot yet prove orphaned or terminally settled MCP owners. Sharing bounded evidence for app-server lifecycle maintainers:

    • Ubuntu Linux desktop, long-running Codex App GUI app-server, managed daemon 0.170.0 on the same user account. The GUI app-server has 190 direct child processes: 22 copies of each of seven distinct Python stdio MCP helpers (154), 24 Node server helpers, 11 Node REPLs, and one other direct child.
    • End-of-window proportional memory (/proc/<pid>/smaps_rollup PSS, rather than inflated sum of RSS) of all 190 GUI child processes was about 1.99 GiB; Python MCP sets themselves were about 1.55 GiB PSS. The biggest Electron renderer had ~1.8 GiB PSS.
    • Two distinct passive sampling windows (~8 seconds each) observed 190→190 GUI children with no births/deaths inside the respective windows. Other historical audits had higher and lower totals; no monotonic leak or staleness was established. The 22-copy groups correlate with four distinct working-directory cohorts but not with authoritative thread_id → writer/claims/pending effects → PID.
    • A separate managed daemon responds to native WebSocket thread/loaded/list with 0 loaded threads. This is not the GUI app-server that owns the 190 children, so the zero cannot be used as authorization to reap any GUI MCP.
    • Current Ubuntu has ~31 GiB available RAM and near-zero memory pressure; GUI sluggishness may also have an independent software graphics cause (GNOME Shell ~54% of one core with Mesa llvmpipe render threads). This is not proof that MCP causes input lag.

    Request: please provide a supported, non-destructive per-GUI-app-server diagnostic for MCP client residency/ownership and pending work, and documented graceful disposal only after the owning thread is definitively terminal and settled, or safe shared MCP reuse/reference-counting. Please do not recommend blind pkill by parent PID/name/age: active threads may still depend on these children. The objective is to distinguish expected per-live-thread copies from a leak without breaking resumable agent sessions.

    No session IDs, private thread titles/messages, command secrets, file contents or user locations were disclosed. No Codex process was killed, restarted or reconfigured for this audit.

    Exact API inspection: thread-scoped status exists, but not an owner→PID lifecycle receipt

    The installed Codex app-server 0.170.0 generated protocol (ClientRequest.json, 109 methods) exposes mcpServerStatus/list, with optional threadId, serverName, detail and bounded pagination. Its status result exposes runtimeStatus (e.g. notStarted, starting, connected, failed) and tool/server metadata, but does not expose child PID, process start identity, writer/lease ownership or pending-effect settlement. thread/loaded/list returns loaded thread IDs only for the App Server instance receiving the call. Thus the managed daemon's empty list cannot establish whether MCP children owned by a separate desktop stdio App Server are safe to dispose.

    Reviewing public upstream codex-rs/app-server/src/request_processors/mcp_processor.rs, list_mcp_server_status with threadId calls load_thread(thread_id), then can perform config/snapshot discovery. I did not invoke it on the active GUI/session because it may change runtime residency and would still not return a PID→claim/fence receipt. See implementation: https://github.com/openai/codex/blob/main/codex-rs/app-server/src/request_processors/mcp_processor.rs .

    Refined maintainer request: provide a genuinely passive (appServerId,threadId,turnId,helperName,PID+startTime,resourceRefCount,writerPendingEffects,settledState) map for the exact GUI App Server, plus a supported gracefulDispose(CLOSED_SETTLED) operation with idempotent receipt/readback. Do not suggest polling mcpServerStatus/list on live dormant threads as a process-owner diagnostic without confirming it is side-effect free. No live processes or sessions were touched.

    R23 follow-up: 266/266 MCP stdio pipes remain connected; count grew with additional worker activity

    New passive Linux /proc readback on the same running GUI App Server observed 330 direct child processes, up from 190 at earlier samplings, including 266 Python stdio MCP helpers = 7 distinct helper types ×38 copies. A single 8-second sample window was stable at 330. Aggregate PSS of all 330 child processes ~6.73 GiB; this is not proof of a memory leak, as new workflow/worker cohorts were present and no long-term trend was established.

    For each of the 266/266 Python helpers, I matched its current standard input, output and error pipe:[inode] to an open file descriptor in the GUI App Server with the opposite read/write mode, and cross-checked the child PID, /proc/stat process-start ticks and PPID. All three pipe-peer checks passed for 266/266 at the snapshot. Thus these are connected IPC subprocesses, not simply detached orphan processes; still not proof of active session ownership or CLOSED_SETTLED.

    Grouping each parent/cwd's seven helper types by nth observed process start gave 38 possible sets, but only 37 sets were temporally plausible within a 3-second window; one grouping was ambiguous and explicitly excluded from the plausible count. This is a heuristic, not a threadId map. A new optional read-only WFOS diagnostic PR #298 records only aggregate pipe-peer checks and plausible/ambiguous cohort counts, without storing FD inode IDs, thread IDs, private content or env values. Local exact tests 8/8 PASS; its CI/merge status is separate from Codex App.

    Requested vendor-safe next step unchanged: expose per-GUI-App-Server threadId→MCP child PID+birth identity→shared refcount→claims/pending effects→CLOSED_SETTLED, with a native idempotent graceful-dispose receipt and before/after resource readback. No process was stopped or restarted.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    appapp-serverbugmcpperformance

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions