openai / openai/codex

Process lifecycle hardening: track and clean up descendants of nested commands on macOS

Open
#44,793 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement tool-calls
Dominant language
Rust
Stars
125k
Forks
19.4k
PR merge metrics
PR metrics pending

Description

Summary

Request explicit process ownership and cleanup guarantees for nested commands on macOS. Descendants can remain active after a nested wrapper exits, causing sustained background resource usage.

Scope: this observation involves a custom nested command runner used from a Codex workflow. It is not a standalone reproduction of a defect in Codex itself; the confirmed cleanup gap is in the nested runner. Please treat this as a containment/test-coverage consideration for Codex, not proof of a Codex-specific root cause.

Observed locally:

  • Several recursive search processes remained alive after their associated nested sessions had ended. Three sessions exited successfully; another stopped at an application-level limit.
  • The surviving processes had PPID 1 and separate process-group IDs. One persisted for more than an hour.
  • The searches traversed from the filesystem root. Sustained disk activity and elevated endpoint-scanner CPU were observed concurrently; their exact causal contribution was not isolated.
  • No original search terms, paths, process IDs, session identifiers, screenshots, or diagnostic dumps are included here.

The nested runner's cleanup pattern was effectively:

process = subprocess.Popen(command, start_new_session=True, ...)
try:
    process.communicate(timeout=limit)
except subprocess.TimeoutExpired:
    os.killpg(process.pid, signal.SIGKILL)
    process.communicate()
finally:
    close_service_connections()

There was no descendant cleanup on successful exit or application-level early exit. Killing only the original process group would also not cover descendants that create a different group/session. Permission to send termination signals alone does not establish complete cleanup.

Suggested regression coverage (not yet executed against standalone Codex):

  1. Use an inert, short-lived sleep process in a disposable directory, rather than a filesystem scan.
  2. Launch it through a nested wrapper, including a variant that creates a separate process group/session.
  3. Exercise normal wrapper exit, nonzero exit, cancellation, and timeout separately.
  4. Verify that all processes owned by the command have exited, or are explicitly tracked as intentionally persistent background work.
  5. Ensure cleanup does not target unrelated user processes and that a successful wrapper exit is not mistaken for confirmed descendant cleanup.

It would be useful to clarify the outer command runner's ownership/containment guarantees for this case and expose any surviving owned processes when cleanup is incomplete.

Related issue

Related to https://github.com/openai/codex/issues/15379. This standalone report focuses on nested wrappers, separate process groups, and cleanup after successful or application-limited exits. The same sanitized observations were previously added there as a comment.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating Codex's outer command runner and its existing process cleanup and ownership handling; no specific source file or test is named in the report. Add regression coverage using inert sleep processes through nested wrappers, including separate process groups, and cover normal exit, nonzero exit, cancellation, and timeout. Done means owned descendants are cleaned up or explicitly tracked, without affecting unrelated processes.

Written by the indexing model from the issue text.

Assessment

Tech stack
macos, python, rust
Domain
cli, operating-systems
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.