Skip to content

Handle stdout broken pipe during JSON streaming - #10259

Closed
etraut-openai wants to merge 1 commit into
mainfrom
codex/investigate-issue-10248-regression
Closed

etraut-openai wants to merge 1 commit into
mainfrom
codex/investigate-issue-10248-regression

Conversation

@etraut-openai

@etraut-openai etraut-openai commented Jan 30, 2026 •

Copy link
Copy Markdown
Contributor

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.

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.
@etraut-openai

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines 852 to +856
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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

codex-cli 0.92.0 panics on Broken pipe when stdout closes during --json streaming (macOS)

1 participant