{"record":{"id":"92ca0b6dbfb9a1a4","repo":"Hmbown/CodeWhale","slug":"stdio-transport-closed-stderr","errorCode":null,"errorMessage":"Stdio transport closed\n{stderr}","messagePattern":"Stdio transport closed\n(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/mcp/stdio.rs","lineNumber":325,"sourceCode":"        let mut line_bytes: Vec<u8> = Vec::new();\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 =\n                match read_line_capped(&mut self.reader, &mut line_bytes, MAX_MCP_RESPONSE_BYTES)\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                if let Some(stderr) = format_stderr_context(&self.stderr_tail).await {\n                    anyhow::bail!(\"Stdio transport closed\\n{stderr}\");\n                }\n                anyhow::bail!(\"Stdio transport closed\");\n            }\n\n            let line = String::from_utf8_lossy(&line_bytes);\n            let trimmed = line.trim();\n            if trimmed.is_empty() {\n                continue;\n            }\n\n            return Ok(trimmed.as_bytes().to_vec());\n        }\n    }\n\n    /// Send SIGTERM and wait up to `STDIO_SHUTDOWN_GRACE` for graceful exit,\n    /// then force termination and reap the child as the backstop.\n    async fn shutdown(&mut self) {\n        let mut child = self.child.lock().await;","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/tui/src/mcp/stdio.rs#L307-L343","documentation":"read_line_capped returned 0 bytes (EOF) — the server process closed its stdout, i.e. it exited. When the stderr tail ring buffer captured output, it is appended (stdio.rs:325) so the exit reason travels with the error. This is the crash-with-evidence variant of the plain 'Stdio transport closed' (579).","triggerScenarios":"The MCP server process exits (panic, fatal error, sys.exit) while the transport is connected; the process prints a traceback to stderr then terminates, and the client's next read hits EOF.","commonSituations":"Python server hitting an unhandled exception and exiting; Node server calling process.exit on an error; server failing on startup arguments after a version upgrade; missing runtime (interpreter dies immediately after printing an error).","solutions":["Read the stderr excerpt in the error message — it is the server's dying words and usually names the bug","Reproduce by running the server's command + args manually in a shell and observe the failure directly","Fix the server-side crash (or its args/env), then let the client respawn/reconnect the transport"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"match transport.recv().await {\n    Err(err) if err.to_string().starts_with(\"Stdio transport closed\\n\") => {\n        // stderr excerpt embedded: surface it, mark tools unavailable, optionally respawn\n        report_server_exit(&err);\n        transport = respawn_stdio_server(&server).await.ok();\n    }\n    other => other?,\n}","preventionTips":["Test the server command + args manually before adding it to long-lived sessions","Pin server versions and re-verify args/env on upgrade — crashes on startup are usually arg-schema changes","Degrade gracefully: mark the server's tools unavailable instead of failing the whole session"],"tags":["stdio","mcp","process-exit","stderr"],"backgroundTag":"process-exited-unexpectedly","analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}