{"record":{"id":"aad3cf97eaa5ccfa","repo":"nikivdev/code","slug":"failed-to-read-from-codex","errorCode":null,"errorMessage":"failed to read from codex: {}","messagePattern":"failed to read from codex: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/commit.rs","lineNumber":4727,"sourceCode":"        let now = Instant::now();\n        if now >= deadline {\n            return Ok(CodexReadOutcome::TimedOut);\n        }\n\n        let wait = cmp::min(\n            Duration::from_millis(250),\n            deadline.saturating_duration_since(now),\n        );\n        match rx.recv_timeout(wait) {\n            Ok(CodexAppServerEvent::Line(line)) => {\n                if line.trim().is_empty() {\n                    continue;\n                }\n                let msg: serde_json::Value = serde_json::from_str(&line)\n                    .with_context(|| format!(\"invalid JSON from codex: {}\", line))?;\n                return Ok(CodexReadOutcome::Message(msg));\n            }\n            Ok(CodexAppServerEvent::ReadError(err)) => bail!(\"failed to read from codex: {}\", err),\n            Ok(CodexAppServerEvent::Closed) => bail!(\"codex app-server closed stdout unexpectedly\"),\n            Err(RecvTimeoutError::Timeout) => continue,\n            Err(RecvTimeoutError::Disconnected) => bail!(\"codex app-server reader disconnected\"),\n        }\n    }\n}\n\n/// Read lines until a JSON-RPC response with the expected id arrives.\nfn codex_read_response(\n    rx: &std::sync::mpsc::Receiver<CodexAppServerEvent>,\n    expected_id: u64,\n    deadline: std::time::Instant,\n) -> Result<serde_json::Value> {\n    loop {\n        let msg = match codex_read_next_message(rx, deadline)? {\n            CodexReadOutcome::Message(msg) => msg,\n            CodexReadOutcome::TimedOut => bail!(\"codex app-server response timed out\"),\n        };","sourceCodeStart":4709,"sourceCodeEnd":4745,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/commit.rs#L4709-L4745","documentation":"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.","triggerScenarios":"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).","commonSituations":"Codex process crashed or was killed mid-session; stdout pipe closed/broken; OS resource limits (fd exhaustion); codex binary version change altering protocol/output.","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."],"exampleFix":"// before: codex binary not running/old\ncodex app-server --version  // verify installed & compatible\n// after: restart the flow with a healthy codex process\nf commit  // retried after codex is responsive","handlingStrategy":"retry","validationCode":"// verify codex is installed, executable, and the pipe can open\n// e.g. spawn a trivial codex app-server request before the real review","typeGuard":null,"tryCatchPattern":"match codex_review() {\n    Err(e) if e.to_string().starts_with(\"failed to read from codex\") => {\n        eprintln!(\"codex stdout read failed: {e}; restarting codex and retrying\");\n    }\n    other => other?,\n}","preventionTips":["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."],"tags":["codex","ipc","stdio","process"],"backgroundTag":"stdio-pipe-read-failed","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}