Skip to content

codex exec --json panics with "failed printing to stdout: Resource temporarily unavailable (os error 11)" when the stdout reader is slow #55242

Open

Description

@MarsGotta

Version: codex-cli 0.162.1 (also seen on 0.156.1), x86_64-unknown-linux-musl, launched through the npm codex.js wrapper.

What happens. A supervisor process (Node.js) runs codex exec --json and reads its stdout through a pipe. While it persists each chunk, the supervisor pauses reading. Sometimes Codex then exits with code 101:

thread 'codex-main' panicked at library/std/src/io/stdio.rs:1165:9:
failed printing to stdout: Resource temporarily unavailable (os error 11)

Pattern (9 of 71 runs over 3 days). Each panic comes right after Codex writes an item.completed event for a command_execution with a large aggregated_output. The JSON line is 31–65 KB, close to the 64 KiB pipe buffer. Runs without such large events do not crash. A retry of the same task usually succeeds.

Why we think it happens. print!/println! panic on any write error, including WouldBlock. A blocking write cannot return EAGAIN, so fd 1 has O_NONBLOCK set at that moment. We did not confirm which process in the chain sets it.

Expected. The JSONL writer should not panic on EAGAIN. It can wait for the fd to be writable and retry, or clear O_NONBLOCK on fd 1 at startup.

Activity

  1. added
    bug
    CLI
    exec
    on Oct 19, 2026
  2. jimmystacks commented on Nov 12, 2026

    @jimmystacks

    We hit the same panic on stderr with codex-cli 0.166.0 (x86_64-unknown-linux-musl) and traced which process sets O_NONBLOCK: it is the codex process itself.

    What we saw

    thread 'codex-main' panicked at library/std/src/io/stdio.rs:1165:9:
    failed printing to stderr: Resource temporarily unavailable (os error 11)
    

    Exit code 101, in codex exec runs started by a Node.js supervisor with default child_process stdio (which on Linux are Unix socketpairs). It happened early in the run, while Codex was echoing a large prompt to stderr and the supervisor was slow to read.

    Who sets the flag

    We ran a kernel syscall trace (the sys_enter_ioctl and sys_enter_fcntl tracepoints, filtered to FIONBIO and F_SETFL with O_NONBLOCK on fds 0–2) across the whole process tree. The only process that touched Codex's stderr was Codex:

    sys_ioctl pid=<codex> fd=2 -> socket:[...]      # cmd 0x5421, FIONBIO
    cmd: .../x86_64-unknown-linux-musl/bin/codex exec --model ... --sandbox danger-full-access ...
    

    This happens at startup, before the prompt echo. No parent, wrapper or child process set the flag on that description. The npm codex.js launcher is not involved: on Node 24 it replaces itself with the native binary through process.execve, and we see the same thing when the native binary is started directly. Earlier checks of /proc/<pid>/fdinfo/2 showed the fd as blocking only because they were taken before Codex made the call.

    Reproduction

    Start codex exec with stderr on a socketpair or pipe, give it a prompt of about 400 KB on stdin, and do not read stderr for a few seconds. It exits 101 in under a second, as soon as the socket buffer is full.

    With stdout and stderr opened as regular files instead, the same run writes the whole echo (about 410 KB) and exits 0, and the trace shows no FIONBIO call at all. So Codex appears to set non-blocking mode only when the stream is a socket or pipe.

    Workaround

    Give Codex regular files for fds 1 and 2 and tail them from the supervisor. A write to a regular file cannot return EAGAIN.

    Suggested fix

    Either do not put the process's own stdout/stderr into non-blocking mode, or make the writers that use print!/eprintln! tolerate WouldBlock (wait for writability and retry). As it stands, any supervisor that reads slower than Codex writes can crash it. We only traced fd 2; the report above on fd 1 with --json looks like the same mechanism, but we have not traced that case.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIbugexec

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions