{"record":{"id":"32701aa7eb510626","repo":"nikivdev/code","slug":"codex-app-server-reader-disconnected","errorCode":null,"errorMessage":"codex app-server reader disconnected","messagePattern":"codex app-server reader disconnected","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/commit.rs","lineNumber":4730,"sourceCode":"        }\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) {\n            if let Some(err) = msg.get(\"error\") {\n                bail!(","sourceCodeStart":4712,"sourceCodeEnd":4748,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/commit.rs#L4712-L4748","documentation":"The channel from the codex stdout reader thread was disconnected (RecvTimeoutError::Disconnected), meaning the reader thread has terminated and no further events will arrive. The tool bails because the JSON-RPC conversation with codex can no longer make progress.","triggerScenarios":"Blocking on codex_read_next_message with a recv_timeout when the reader thread has already exited (after a read error, EOF, or thread panic), so the channel is closed.","commonSituations":"Codex process died causing reader thread teardown; reader thread panicked on malformed input; internal concurrency bug shutting down the reader while a request is pending.","solutions":["Re-run the command to restart the codex app-server and its reader thread.","Check codex process health/logs to find why the reader shut down.","Look for panics or errors in the tool's output from the reader thread.","Update the tool/codex if a known protocol mismatch causes reader shutdown."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match codex_review() {\n    Err(e) if e.to_string().contains(\"reader disconnected\") => {\n        // reader thread died: restart the app-server session and retry once\n    }\n    other => other?,\n}","preventionTips":["Ensure the reader thread's lifetime covers the entire request window.","Log reader-thread panics/errors to find the shutdown cause.","Restart the whole codex session rather than reusing a torn-down channel."],"tags":["codex","ipc","channel","concurrency"],"backgroundTag":"reader-disconnected","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}