From 9ce6bbc43e2da2f8c8c08fa8d2cdaf496d35cb9c Mon Sep 17 00:00:00 2001 From: Denis Andrejew Date: Thu, 8 Jan 2026 15:50:40 +0100 Subject: [PATCH] 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 --- codex-rs/core/src/spawn.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/codex-rs/core/src/spawn.rs b/codex-rs/core/src/spawn.rs index d738f1223..48c57c2cd 100644 --- a/codex-rs/core/src/spawn.rs +++ b/codex-rs/core/src/spawn.rs @@ -66,10 +66,11 @@ pub(crate) async fn spawn_child_async( #[cfg(unix)] unsafe { + let set_process_group = matches!(stdio_policy, StdioPolicy::RedirectForShellTool); #[cfg(target_os = "linux")] let parent_pid = libc::getpid(); cmd.pre_exec(move || { - if libc::setpgid(0, 0) == -1 { + if set_process_group && libc::setpgid(0, 0) == -1 { return Err(std::io::Error::last_os_error()); }