[codex] Handle Ctrl-C for non-TTY unified exec (#26734)

## Why

A long-running unified exec process started with `tty: false` could not
be interrupted via `write_stdin`: ordinary non-TTY stdin writes are
rejected once stdin is closed, but an exact U+0003 payload should still
map to a process interrupt. The interrupt should flow through the same
process lifecycle path as a real signal so Codex preserves
process-reported output and exit metadata instead of fabricating a
Ctrl-C exit code or tearing down the session early.

## What Changed

- Add `process/signal` to exec-server with `ProcessSignal::Interrupt`
and an empty response.
- Add a non-consuming `ProcessHandle::signal` path for spawned
processes; on Unix it sends SIGINT to the process group and leaves
terminate/hard-kill unchanged.
- Route non-TTY U+0003 `write_stdin` through `process.signal(...)`
instead of `terminate`, then let the normal post-write collection path
drain output and observe exit.
- Add exec-server coverage where a shell `trap INT` handler prints the
signal and exits with its own code.
- Add unified exec coverage where a `tty: false` process traps SIGINT,
emits output, and exits with its own code.

## Validation

- `just test -p codex-exec-server
exec_process_signal_interrupts_process`
- `just test -p codex-exec-server`
- `just test -p codex-core
write_stdin_ctrl_c_interrupts_non_tty_session`
This commit is contained in:
pakrym-oai
2026-06-09 15:10:17 -07:00
committed by GitHub
Unverified
parent f574946960
commit f2969f36e8
19 changed files with 659 additions and 44 deletions
+19 -1
View File
@@ -19,7 +19,9 @@ use tokio::task::JoinHandle;
use crate::process::ChildTerminator;
use crate::process::ProcessHandle;
use crate::process::ProcessSignal;
use crate::process::SpawnedProcess;
use crate::process::exit_code_from_status;
#[cfg(target_os = "linux")]
use libc;
@@ -32,6 +34,22 @@ struct PipeChildTerminator {
}
impl ChildTerminator for PipeChildTerminator {
fn signal(&mut self, signal: ProcessSignal) -> io::Result<()> {
match signal {
ProcessSignal::Interrupt => {
#[cfg(unix)]
{
crate::process_group::interrupt_process_group(self.process_group_id)
}
#[cfg(not(unix))]
{
Err(crate::process::unsupported_signal(signal))
}
}
}
}
fn kill(&mut self) -> io::Result<()> {
#[cfg(unix)]
{
@@ -209,7 +227,7 @@ async fn spawn_process_with_stdin_mode(
let wait_exit_code = Arc::clone(&exit_code);
let wait_handle: JoinHandle<()> = tokio::spawn(async move {
let code = match child.wait().await {
Ok(status) => status.code().unwrap_or(-1),
Ok(status) => exit_code_from_status(status),
Err(_) => -1,
};
wait_exit_status.store(true, std::sync::atomic::Ordering::SeqCst);