Skip to content

Kill shell tool process groups on timeout - #5258

Merged
bolinfest merged 9 commits into
openai:mainfrom
willsmanley:shell-process-group-timeout
Nov 8, 2025
Merged

bolinfest merged 9 commits into
openai:mainfrom
willsmanley:shell-process-group-timeout

Conversation

@willsmanley

@willsmanley willsmanley commented Oct 16, 2025 •

Copy link
Copy Markdown

Summary

  • launch shell tool processes in their own process group so Codex owns the full tree
  • on timeout or ctrl-c, send SIGKILL to the process group before terminating the tracked child
  • document that the default shell/unified_exec timeout remains 1000 ms

Original Bug

Long-lived shell tool commands hang indefinitely because the timeout handler only terminated the direct child process; any grandchildren it spawned kept running and held the PTY open, preventing Codex from regaining control.

Repro Original Bug

Install next.js and run next dev (which is a long-running shell process with children). On openai:main, it will cause the agent to permanently get stuck here until human intervention. On this branch, this command will be terminated successfully after timeout_ms which will unblock the agent. This is a critical fix for unmonitored / lightly monitored agents that don't have immediate human observation to unblock them.

@etraut-openai

Copy link
Copy Markdown
Contributor

Thanks for the contribution, and apologies for the slow response. We received many PRs, and we're just now getting through the backlog.

It looks like this PR has gone stale. If you're still interested in submitting it, could you please resolve the merge conflicts and prepare it for review? Thanks!

@etraut-openai etraut-openai added the needs-response Additional information is requested label Nov 7, 2025
Comment thread codex-rs/core/src/tools/spec.rs Outdated
JsonSchema::Number {
description: Some(
"Maximum time in milliseconds to wait for output after writing the input."
"Maximum time in milliseconds to wait for output after writing the input (default: 1000)."

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this default value coming from?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DEFAULT_TIMEOUT_MS. We should remove these for now and make the change separately if we think the model is confused.

Comment thread codex-rs/core/src/spawn.rs Outdated
// run _after_ the parent (i.e., the Codex process) has already
// exited, then the parent is the _init_ process (which will never
// die), so we should just terminate the child process now.
if libc::getppid() == 1 {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was recently a PR merged around mishandling Codex run as PID 1: #4200

@bolinfest

Copy link
Copy Markdown
Collaborator

I also want to make note of #1852, which admittedly I never made time to review.

Comment thread codex-rs/core/src/exec.rs
}
}
_ = tokio::signal::ctrl_c() => {
kill_child_process_group(&mut child)?;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the child.start_kill() call be moved into kill_child_process_group()? Is it necessary if killpg succeeds?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

bolinfest and others added 8 commits November 7, 2025 16:50
revert author's comment
undo property description changes for now
another docstring change
linux only gepid
add move keyword that got lost
added a test
remove hashmap import in test block; already at top of file
@bolinfest
bolinfest merged commit a2fdfce into openai:main Nov 8, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

needs-response Additional information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants