nikivdev/code · error
failed to read from codex: {}
Error message
failed to read from codex: {} What it means
The codex app-server reader thread surfaced a ReadError while reading stdout, and this function converts it into an error via bail! with the underlying I/O error. It means the tool lost the ability to read JSON-RPC messages from the codex app-server process, so the review/automation step cannot continue.
Source
Thrown at src/commit.rs:4727
let now = Instant::now();
if now >= deadline {
return Ok(CodexReadOutcome::TimedOut);
}
let wait = cmp::min(
Duration::from_millis(250),
deadline.saturating_duration_since(now),
);
match rx.recv_timeout(wait) {
Ok(CodexAppServerEvent::Line(line)) => {
if line.trim().is_empty() {
continue;
}
let msg: serde_json::Value = serde_json::from_str(&line)
.with_context(|| format!("invalid JSON from codex: {}", line))?;
return Ok(CodexReadOutcome::Message(msg));
}
Ok(CodexAppServerEvent::ReadError(err)) => bail!("failed to read from codex: {}", err),
Ok(CodexAppServerEvent::Closed) => bail!("codex app-server closed stdout unexpectedly"),
Err(RecvTimeoutError::Timeout) => continue,
Err(RecvTimeoutError::Disconnected) => bail!("codex app-server reader disconnected"),
}
}
}
/// Read lines until a JSON-RPC response with the expected id arrives.
fn codex_read_response(
rx: &std::sync::mpsc::Receiver<CodexAppServerEvent>,
expected_id: u64,
deadline: std::time::Instant,
) -> Result<serde_json::Value> {
loop {
let msg = match codex_read_next_message(rx, deadline)? {
CodexReadOutcome::Message(msg) => msg,
CodexReadOutcome::TimedOut => bail!("codex app-server response timed out"),
};View on GitHub (pinned to a747e741ae)
Solutions
- Check that the codex app-server process is alive and that its version is compatible with this tool.
- Re-run the command; a transient pipe failure often clears on retry.
- Inspect system logs/resource limits if the codex process is being killed (OOM, fd limits).
- Update the codex binary or the tool to matching supported versions.
Example fix
// before: codex binary not running/old codex app-server --version // verify installed & compatible // after: restart the flow with a healthy codex process f commit // retried after codex is responsive
Defensive patterns
Strategy: retry
Validate before calling
// verify codex is installed, executable, and the pipe can open // e.g. spawn a trivial codex app-server request before the real review
Try / catch
match codex_review() {
Err(e) if e.to_string().starts_with("failed to read from codex") => {
eprintln!("codex stdout read failed: {e}; restarting codex and retrying");
}
other => other?,
} Prevention
- Keep the codex process alive for the whole session (watch for OOM kills).
- Check fd/pipe resource limits on CI machines.
- Pin compatible codex and tool versions.
When it happens
Trigger: Calling the codex-driven review flow when the reader thread's line read from the codex process stdout fails (I/O error on the pipe).
Common situations: Codex process crashed or was killed mid-session; stdout pipe closed/broken; OS resource limits (fd exhaustion); codex binary version change altering protocol/output.
Related errors
- codex app-server closed stdout unexpectedly
- codex app-server response timed out
- failed to read from codex app-server: {}
- codex app-server closed stdout unexpectedly
- codex app-server reader disconnected
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/aad3cf97eaa5ccfa.
Report an issue: GitHub.