Repository navigation
Description
What version of Codex CLI is running?
`codex-cli 0.144.1`
What subscription do you have?
Pro
Which model were you using?
Not applicable; this is an app-server process-lifecycle bug.
What platform is your computer?
`Darwin 25.3.0 arm64 arm`
What terminal emulator and version are you using?
RepoPrompt CE invoking `codex app-server`; no terminal emulator is involved.
Codex doctor report
`codex doctor --json` produced no output with `codex-cli 0.144.1`.
What issue are you seeing?
Terminating or dropping a PTY/pipe `ProcessHandle` can kill its child and then abort the only task responsible for waiting on that child.
The exited process remains a zombie while the Codex app-server parent stays alive. During a local app-server run, repeated exec/tool calls accumulated dozens of defunct children beneath the active app-server processes.
The source establishes a direct ownership path:
- `ProcessHandle::terminate()` calls `request_terminate()`, which kills the child.
- It aborts the reader and writer helpers.
- It also aborts `wait_handle`.
- The wait task owns the child and is the only code calling `child.wait()`.
`Drop for ProcessHandle` calls the same `terminate()` method.
The behavior is present in the `rust-v0.144.1` source and the same ownership pattern is present on current `main`.
What steps can reproduce the bug?
-
Start `codex app-server`.
-
Run repeated exec/tool calls that spawn short-lived child processes.
-
Allow the associated `ProcessHandle` values to be terminated or dropped while keeping the app-server alive.
-
Inspect children of the app-server:
```sh
ps -axo pid,ppid,state,command
``` -
Observe that completed children remain in state `Z` and that their count increases with additional exec calls.
A repository-level regression can reproduce the ownership bug more directly:
- Spawn a pipe or PTY child through `codex-rs/utils/pty`.
- Call `ProcessHandle::terminate()` or drop the handle before natural exit.
- Wait for the child to exit.
- Verify that it is reaped rather than remaining a zombie.
The relevant implementation is `codex-rs/utils/pty/src/process.rs`.
What is the expected behavior?
Terminating or dropping a process handle must not abandon child reaping.
Reader and writer helpers may be cancelled, but the child waiter must be allowed to finish or be replaced by another owner that performs `wait`.
Additional information
Suggested regression coverage:
- explicit termination of a pipe child
- dropping a pipe handle before child exit
- explicit termination of a PTY child
- dropping a PTY handle before child exit
- repeated short exec calls leaving no zombie children
This may be related to #12491, but the concrete path here is `utils/pty::ProcessHandle`.
PR #19753 addresses stdio MCP-server shutdown rather than this PTY/pipe waiter-abort path.
Activity
1837620622 commentedon Jul 11, 2026
Analysis + local fix (branch ready)
I investigated the ownership path called out in this issue and confirmed it is still present on current
main.Root cause
In
codex-rs/utils/pty/src/process.rs,ProcessHandle::terminate()(also used byDrop) does:request_terminate()— kill the child / process groupwait_handleFor pipe and PTY spawns,
wait_handleis the only task that owns the child and callschild.wait()/ reaps it. Aborting that task after kill leaves exited children as zombies under long-lived parents such ascodex app-server.Minimal fix
Drop, detach the waitJoinHandlewithout aborting so reaping can finish in the backgroundBranch / commit
e3a6ff2a0a65528c016b84eec00ec72929b707d9Tests added / run
New regressions in
codex-rs/utils/pty/src/tests.rs:pipe_terminate_reaps_childpipe_drop_reaps_childpty_terminate_reaps_childLocal validation:
All
codex-utils-ptylib tests passed (19/19).Happy to open a PR if a Codex team member invites an external contribution for this issue (per
docs/contributing.md).Add codex-mcp-reaper for live-parented MCP server leaks