{"record":{"id":"5852b41e6a4bfabd","repo":"nikivdev/code","slug":"codex-app-server-closed-stdout-unexpectedly","errorCode":null,"errorMessage":"codex app-server closed stdout unexpectedly","messagePattern":"codex app-server closed stdout unexpectedly","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/commit.rs","lineNumber":4728,"sourceCode":"        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        };\n        if msg.get(\"id\").and_then(|id| id.as_u64()) == Some(expected_id) {","sourceCodeStart":4710,"sourceCodeEnd":4746,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/commit.rs#L4710-L4746","documentation":"The codex app-server reader thread signaled that the process closed its stdout (CodexAppServerEvent::Closed). Since the tool expects an ongoing JSON-RPC conversation, an unexpected EOF means the codex process exited or terminated its output stream and the operation must fail.","triggerScenarios":"Waiting for JSON-RPC messages from codex when the reader reports stdout closed — i.e., the codex app-server process exited while the tool was mid-conversation.","commonSituations":"Codex crashed (panic, OOM kill); user or system stopped the process; codex exited early due to invalid config or auth failure; version mismatch causing protocol abort.","solutions":["Inspect the codex process stderr/logs for the reason it exited.","Verify codex configuration and authentication, then restart the flow.","Re-run the command after confirming codex stays up (watch the process while it runs).","Update or reinstall the codex binary if crashes are reproducible."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match codex_review() {\n    Err(e) if e.to_string().contains(\"closed stdout unexpectedly\") => {\n        // capture codex stderr/logs, restart codex, then retry once\n    }\n    other => other?,\n}","preventionTips":["Capture codex stderr to logs so exit causes are diagnosable.","Validate codex config/auth before starting long review sessions.","Upgrade codex if crashes are reproducible with your workload."],"tags":["codex","ipc","process-exit","stdio"],"backgroundTag":"process-exited-unexpectedly","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}