Skip to content

Process leak: codex app-server --listen stdio:// not cleaned up when chat tab is closed #26773

Open

Description

@hrygo

Bug Description

When closing a chat tab in Codex Desktop, the codex app-server --listen stdio:// and its parent node_repl processes are not terminated, accumulating zombie processes over time.

Process Tree

Codex Desktop (Electron)
  └── node_repl
       └── codex app-server --listen stdio://

Each new chat tab spawns a fresh set of these processes. After closing tabs, they remain running indefinitely with 0% CPU and 0 children.

Steps to Reproduce

  1. Open Codex Desktop
  2. Open multiple chat tabs (e.g., 10)
  3. Close most of them, keeping only 1-2
  4. Check processes: ps aux | grep 'codex app-server'
  5. Observe that nearly all processes from closed tabs remain alive

Observed Behavior

$ ps aux | grep 'codex app-server' | grep -v grep | wc -l
       9

Only 1 of the 9 processes had active children (26 MCP sub-processes). The other 8 were idle zombies consuming memory.

Root Cause Analysis

The app-server in stdio mode exits only on stdin EOF (codex-rs/app-server-transport/src/transport/stdio.rs:68):

// codex-rs/app-server-transport/src/transport/stdio.rs:43-80
// stdin reader loop — blocks on lines.next_line().await
// EOF triggers ConnectionClosed event

And shutdown_when_no_connections is set based on stdio mode (codex-rs/app-server/src/lib.rs:662-663):

let single_client_mode = matches!(&transport, AppServerTransport::Stdio);
let shutdown_when_no_connections = single_client_mode;

The leak occurs because:

  1. When Desktop closes a tab, node_repl may be killed (SIGKILL) without gracefully closing the stdin pipe to codex app-server
  2. Or node_repl exits but the stdin fd is orphaned — the kernel doesn't always reclaim it immediately
  3. codex app-server blocks forever on lines.next_line().await, never receiving EOF
  4. There is no heartbeat/timeout mechanism to detect this zombie state
  5. Daemon uses setsid() (app-server-daemon/src/backend/pid.rs:171-176) creating independent process groups, so SIGTERM doesn't cascade to children

Suggested Fixes

Fix 1: Add heartbeat/timeout in stdio transport

Add a periodic check in stdio.rs — if no data received on stdin for N minutes, treat as EOF and shut down.

Fix 2: PID file tracking for stdio mode

Daemon mode already uses PID files (pid.rs) for process lifecycle management. Stdio mode should similarly track child PIDs so orphaned processes can be discovered and cleaned up.

Fix 3: Desktop-side fix (Electron)

Ensure that when a tab is closed, node_repl gracefully closes the stdin pipe to codex app-server before terminating, giving it a chance to shut down cleanly.

Environment

  • macOS Darwin 25.5.0
  • Codex Desktop 26.602.40724
  • Codex app-server started via --listen stdio://

Workaround

Manually kill zombie processes:

# Find idle app-server processes (0 children, 0% CPU)
ps aux | grep 'codex app-server' | grep -v grep
# Kill specific PIDs
kill <pid>

Activity

  1. added
    bug
    app
    app-server
    on Jun 6, 2026
  2. vladysmd commented on Oct 6, 2026

    @vladysmd

    Follow-up: retained native CUA workers and nested App Servers on macOS

    Related report: openai/codex#26773.

    Observed on 2026-10-06:

    • macOS 27.0.1, build 26A434, Apple Silicon.
    • Codex Desktop 26.930.61225, build 13232; bundled CLI 0.160.1.
    • A process snapshot approximately one hour after Desktop startup contained 23 native Node REPL workers and six App Servers. One App Server was directly below Desktop; five were children of native CUA Node REPL workers.
    • The separate manually configured mcp_servers.node_repl was disabled. Native CUA workers were still present.
    • No recognized Node REPL worker was below another recognized worker. Descendant RSS was deduplicated by PID. The 23-worker count was not an overlapping-family accounting artifact.
    • A supported reset of the current chat's CUA JavaScript session preserved browser tabs and native applications, but the worker count remained 23. Family RSS was lower in the subsequent observation; this does not prove the reset caused the decrease.

    This is a retention observation, not a controlled reproduction proving that every retained worker belongs to a closed chat. Per-process chat ownership is unavailable to the current client. No processes were signaled and no signed application files were modified. Reported heat and earlier crashes are not causally attributed to this process snapshot.

    Separate read-only App Server clients can read terminal child turns, but process-local diagnostics and a new client's unsubscribe cannot prove retirement of Desktop's existing connections. The native-default stable and beta update-feed queries both listed this installed build as their newest entry; account-specific cohorts may differ.

    Is there a supported owner-bound API to dispose of a completed chat's native CUA worker and any nested App Server without restarting Desktop or interrupting other chats? If this retention has a maintained fix, which Desktop build contains it? A documented expected lifetime for idle/subscribed workers would also help distinguish retained sessions from abandoned workers.

    No logs, chat contents, account identifiers, credentials, local user paths or task UUIDs are included.

  3. TyceHerrman commented on Oct 19, 2026

    @TyceHerrman

    I captured a related leak on macOS Apple Silicon with Desktop 26.1013.40934, bundled CLI 0.163.0-alpha.10.2. Here the parent is a computer-history MCP worker, rather than node_repl:

    ChatGPT → codex app-server
      → SkyComputerUseClient computer-history mcp
        → codex app-server --listen stdio://
    

    The monitor records the history worker exiting while its Codex child survives and becomes a PID-1 orphan, retaining about 1 GiB physical footprint.

    On October 19, 2026:

    • Initially, nested backends disappeared by the next 15–18 second sample.
    • Around 12:41 p.m. Eastern, they began persisting.
    • By 12:48 p.m., 18 orphaned backends retained 18.2 GiB combined; the oldest had survived over seven minutes. The main backend separately held about 5.7 GiB, and the Mac became severely sluggish.

    The onset coincided with thread/resume, MCP initialization, and computer-history cancellation (quit_reason=Cancelled). That is correlation; I have not established the failing code path or a minimal reproduction.

    Measurements use proc_pid_rusage physical footprint, not summed RSS. No monitored processes were killed or restarted, and no raw logs or private task data are attached.

    if this issue shoudn't cover cleanup of backends launched by computer-history mcp, I can create new issue for this

    Update: paired startup stacks. Later captures show three computer-history-launched backends inside Codex authentication loading → age decryption → scrypt at startup ages of 22–30 seconds; paired helpers were waiting for the nested backend’s initialize response. A ~30-second handshake timeout was followed by helper exit and PID-1 orphaning; the children persisted for over eight minutes before manual cleanup. The auth file specifies scrypt work factor 20, requiring a 1 GiB buffer—matching #38435’s allocation mechanism. Concurrent decryptions worsening startup time is plausible, but unproven; orphan cleanup is a separate defect.

    Update: direct Keychain workaround

    After preserving the config and encrypted-auth backup, I signed in with features.secret_auth_storage=false, kept cli_auth_credentials_store = "keyring", and then persisted the feature setting and restarted Desktop.

    Verified:

    • login status succeeded in 0.07 seconds, with 40 MiB maximum RSS and 15.3 MiB peak physical footprint.
    • During computer-history testing in three chats, no ~1 GiB processes or sustained process accumulation appeared. Combined sampled RSS peaked at 646.1 MiB; additional processes generally disappeared by the next two-second sample.

    This supports direct Keychain storage as a local workaround for the earlier encrypted-auth startup/decryption problem. It does not establish that orphan cleanup is fixed.

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-serverbugperformance

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions