Repository navigation
Handle stdout broken pipe during JSON streaming - #10259
etraut-openai wants to merge 1 commit into
Conversation
Fixes #10248. Replace println! in JSONL streaming with a locked stdout writer. Treat ErrorKind::BrokenPipe as a graceful shutdown signal instead of panicking. Add a regression test that closes stdout mid-stream and asserts a clean exit. Why this looked like a 0.92.0 regression: The panic-on-EPIPE behavior is older, but 0.92.0 appears to emit additional early --json stdout lines in some configurations. In particular, 0.92.0 includes a new “under-development features enabled” warning event (c900de2, #9954) that prints to stdout in JSON mode. More early stdout writes increase the chance of hitting EPIPE when downstream consumers (e.g., head, tee, detached runners) close the pipe mid-run. This change makes --json streaming robust to stdout closure regardless of when it happens.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e4aa2b2c3b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| match serde_json::to_string(&conv_event) { | ||
| Ok(line) => { | ||
| println!("{line}"); | ||
| if let Err(err) = writeln!(stdout, "{line}") { | ||
| if err.kind() == std::io::ErrorKind::BrokenPipe { | ||
| return CodexStatus::InitiateShutdown; |
There was a problem hiding this comment.
Propagate BrokenPipe from initial JSON output
The new BrokenPipe early-return makes sense for the main event loop, but print_config_summary calls process_event and ignores its return value. If stdout closes during the initial SessionConfigured JSON line (e.g., codex exec --json … | head -n1), this InitiateShutdown is dropped and the command still submits work/network calls until a later event hits the broken pipe. That’s a behavioral regression versus the previous panic exit and defeats the “graceful shutdown on closed pipe” goal for the very first line. Consider propagating the status from print_config_summary or tracking a shutdown flag so the run stops immediately after the first BrokenPipe.
Useful? React with 👍 / 👎.
Handle BrokenPipe in codex exec --json stdout streaming
Fixes #10248
Replaces println! in JSONL streaming with a locked stdout writer. Treats ErrorKind::BrokenPipe as a graceful shutdown signal instead of panicking.
This was a long-standing bug, but the user reported seeing it first in 0.91.0. Here's a theory about why. 0.92.0 includes a new “under-development features enabled” warning event (c900de2, #9954) that prints to stdout in JSON mode. More early stdout writes increase the chance of hitting EPIPE when downstream consumers (e.g., head, tee, detached runners) close the pipe mid-run.
This change makes --json streaming robust to stdout closure regardless of when it happens.