Orphaned child processes persist after Codex parent exits
Open 💬 3 comments Opened Mar 21, 2026 by duroey
What version of Codex CLI is running?
codex-cli 0.116.0
What subscription do you have?
plus
Which model were you using?
gpt-5.4
What platform is your computer?
macOS m4
What terminal emulator and version are you using (if applicable)?
VSCode
What issue are you seeing?
When running command execution flows in Codex CLI (especially PTY/sandbox-like flows), child processes may continue running in the background after the parent Codex process exits.
Observed behavior:
- A spawned task/session can enter a persistent loop and not terminate as expected.
- Exiting or force-stopping the parent Codex process does not always terminate the spawned process tree.
- Residual processes remain as orphan/background processes and require manual cleanup.
Context from code inspection:
- Process lifecycle logic appears in:
codex-rs/utils/pty/src/process.rscodex-rs/utils/pty/src/process_group.rscodex-rs/utils/pty/src/pipe.rscodex-rs/exec-server/src/local_process.rscodex-rs/app-server/src/command_exec.rs- There is explicit process-group / parent-death handling, but termination paths that abort waiter tasks may allow race conditions where full reap/cleanup is not guaranteed under some shutdown timings.
What steps can reproduce the bug?
- Start a Codex CLI execution that spawns a long-running child process (for example, an interactive shell, loop, or command that does not exit quickly).
- Ensure the child process is still running (or producing periodic output).
- Exit Codex CLI normally, or terminate it abruptly (e.g., signal/force close).
- Inspect system processes and observe that one or more child/background processes from that execution remain alive.
Optional validation:
- Repeat several times and check for accumulating residual processes.
What is the expected behavior?
On any Codex CLI shutdown path (normal exit, cancellation, forced termination), all child processes and descendants created for that execution should be terminated and reaped promptly.
No orphan/zombie/background residual processes should remain after parent exit.
Additional information
Suggested areas for maintainers to verify:
- Parent-child lifecycle binding and whole-process-group teardown.
- Consistent cleanup on all exit/cancel/error paths.
- Ensure waiter/reaper tasks are not aborted before child exit is fully observed and cleanup is complete.
- Validate behavior for descendants spawned by shells/REPLs.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗