{"record":{"id":"ae81b9813dccdc98","repo":"Hmbown/CodeWhale","slug":"stdio-transport-read-error-err-stderr","errorCode":null,"errorMessage":"Stdio transport read error: {err}\n{stderr}","messagePattern":"Stdio transport read error: (.+?)\n(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/mcp/stdio.rs","lineNumber":329,"sourceCode":"        self.stdin.flush().await?;\n        Ok(())\n    }\n\n    async fn recv(&mut self) -> Result<Vec<u8>> {\n        loop {\n            // Bounded read: a server emitting a newline-free multi-GB \"line\"\n            // must not OOM us (read_line is unbounded).\n            let bytes = match read_line_capped(\n                &mut self.reader,\n                &mut self.pending_line,\n                MAX_MCP_RESPONSE_BYTES,\n            )\n            .await\n            {\n                Ok(b) => b,\n                Err(err) => {\n                    if let Some(stderr) = format_stderr_context(&self.stderr_tail).await {\n                        anyhow::bail!(\"Stdio transport read error: {err}\\n{stderr}\");\n                    }\n                    return Err(err.into());\n                }\n            };\n            if bytes == 0 {\n                // Let the stderr drain task catch up before snapshotting, and\n                // name the exit status: a reviewed plugin's stderr is never\n                // retained, so the status is the only reason the operator\n                // gets when the child dies before the handshake (#5916).\n                tokio::task::yield_now().await;\n                let exit = self.child.lock().await.try_wait().ok().flatten();\n                let exit = exit.map_or_else(String::new, |status| format!(\" ({status})\"));\n                if let Some(stderr) = format_stderr_context(&self.stderr_tail).await {\n                    anyhow::bail!(\"Stdio transport closed{exit}\\n{stderr}\");\n                }\n                anyhow::bail!(\"Stdio transport closed{exit}\");\n            }\n","sourceCodeStart":311,"sourceCodeEnd":347,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/crates/tui/src/mcp/stdio.rs#L311-L347","documentation":"Thrown by the stdio MCP transport's `recv` when reading a JSON-RPC message line from the child process's stdout fails. The error wraps the underlying I/O error and appends a tail of the child's captured stderr, since stderr is usually the only place the child explains why it stopped producing output.","triggerScenarios":"The child MCP server process read on stdout returns an Err from `read` (e.g. child died mid-line, pipe broken, OS-level I/O error), and `format_stderr_context` finds non-empty stderr output to attach.","commonSituations":"The MCP server binary crashes while handling a request; the child writes a panic to stderr and exits; the command is killed by OOM or a signal mid-communication; a broken pipe after the child terminates unexpectedly.","solutions":["Inspect the stderr excerpt in the message to find the child's actual failure (panic, missing module, bad flag).","Fix the MCP server command/config so the child starts and stays healthy (correct binary path, args, env).","Restart the MCP server process / reopen the transport and retry.","Check for resource issues (OOM, disk, permissions) that killed the child."],"exampleFix":"// before: broken command kills child mid-session\n\"command\": \"npx\", \"args\": [\"-y\", \"@acme/server@0.1.0\"]\n// after: stderr excerpt showed 'Cannot find module'; pin a working version\n\"command\": \"npx\", \"args\": [\"-y\", \"@acme/server@0.3.2\"]","handlingStrategy":"try-catch","validationCode":"// Smoke-test the child command before wiring it into the transport\nlet out = std::process::Command::new(\"npx\").args([\"-y\", \"@acme/server\", \"--help\"]).output()?;\nif !out.status.success() { bail!(\"MCP server command fails: {}\", String::from_utf8_lossy(&out.stderr)); }","typeGuard":null,"tryCatchPattern":"// Surface the stderr excerpt verbatim to the operator, then restart the transport\nmatch transport.recv().await {\n    Err(e) if e.to_string().starts_with(\"Stdio transport read error\") => {\n        log::error!(\"{e}\");\n        transport = spawn_stdio_transport(config)?;\n    }\n    other => other,\n}","preventionTips":["Always capture and retain child stderr; it is the primary diagnostic.","Smoke-test the server command standalone before configuring it.","Monitor child process health and restart on unexpected exit."],"tags":["mcp","stdio","io-error","child-process"],"backgroundTag":"broken-pipe","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}