mirror of
https://github.com/openai/codex.git
synced 2026-11-20 22:40:37 +00:00
Preserve output from hooks that exit before reading stdin (#35194)
## Why A hook can exit successfully without consuming its JSON input. If it closes stdin while Codex is still writing, the resulting broken pipe should not hide the hook's exit status and output. ## What changed Ignore broken-pipe errors when writing hook stdin and continue waiting for the process result. Other stdin write errors remain failures. ## Testing Add a cross-platform regression test that sends a large input to a fast-exiting hook and verifies that its successful status and stdout are preserved. GitOrigin-RevId: e1b6e7c6ac5e39232e49b45245ea0df9d34d1fe6
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use std::io::ErrorKind;
|
||||
use std::path::Path;
|
||||
use std::process::Stdio;
|
||||
use std::time::Duration;
|
||||
@@ -83,6 +84,7 @@ pub(crate) async fn run_command(
|
||||
|
||||
if let Some(mut stdin) = child.stdin.take()
|
||||
&& let Err(err) = stdin.write_all(input_json.as_bytes()).await
|
||||
&& err.kind() != ErrorKind::BrokenPipe
|
||||
{
|
||||
let _ = child.kill().await;
|
||||
return finish_command_run(
|
||||
@@ -208,6 +210,6 @@ fn default_shell_command() -> Command {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(test, windows))]
|
||||
#[cfg(test)]
|
||||
#[path = "command_runner_tests.rs"]
|
||||
mod tests;
|
||||
|
||||
Reference in New Issue
Block a user