Skip to content

Commit 9ce6bbc

Browse files
Avoid setpgid for inherited stdio on macOS (#8691)
## Summary - avoid setting a new process group when stdio is inherited (keeps child in foreground PG) - keep process-group isolation when stdio is redirected so killpg cleanup still works - prevents macOS job-control SIGTTIN stops that look like hangs after output ## Testing - `cargo build -p codex-cli` - `GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_NOSYSTEM=1 CARGO_BIN_EXE_codex=/Users/denis/Code/codex/codex-rs/target/debug/codex /opt/homebrew/bin/timeout 30m cargo test -p codex-core -p codex-exec` ## Context This fixes macOS sandbox hangs for commands like `elixir -v` / `erl -noshell`, where the child was moved into a new process group while still attached to the controlling TTY. See issue #8690. ## Authorship & collaboration - This change and analysis were authored by **Codex** (AI coding agent). - Human collaborator: @seeekr provided repro environment, context, and review guidance. - CLI used: `codex-cli 0.77.0`. - Model: `gpt-5.2-codex (xhigh)`. Co-authored-by: Eric Traut <[email protected]>
1 parent 7520d8b commit 9ce6bbc

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

codex-rs/core/src/spawn.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@ pub(crate) async fn spawn_child_async(
6666

6767
#[cfg(unix)]
6868
unsafe {
69+
let set_process_group = matches!(stdio_policy, StdioPolicy::RedirectForShellTool);
6970
#[cfg(target_os = "linux")]
7071
let parent_pid = libc::getpid();
7172
cmd.pre_exec(move || {
72-
if libc::setpgid(0, 0) == -1 {
73+
if set_process_group && libc::setpgid(0, 0) == -1 {
7374
return Err(std::io::Error::last_os_error());
7475
}
7576

0 commit comments

Comments
 (0)