{"record":{"id":"3dbe67f9304f390f","repo":"Hmbown/CodeWhale","slug":"stdio-transport-closed","errorCode":null,"errorMessage":"Stdio transport closed","messagePattern":"Stdio transport closed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/mcp/stdio.rs","lineNumber":327,"sourceCode":"            // 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;\n        terminate_child(&mut child).await;\n    }","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/tui/src/mcp/stdio.rs#L309-L345","documentation":"EOF on the server's stdout with an empty stderr tail (stdio.rs:327): the process exited without printing anything the client captured. This is the silent-exit variant — the transport cannot distinguish crash-without-output from a deliberate clean shutdown because no stderr evidence was collected.","triggerScenarios":"The server process exits immediately after spawn or mid-session with no stderr output: invalid CLI arguments handled by printing usage to stdout then exiting, a successful exit(0) after finishing, or a failure in code paths that never write to stderr.","commonSituations":"Argument schema changed after a server upgrade and old args now trigger argparse-style exit; wrapper script exiting cleanly on a condition; the server daemonizing/forking and closing the original stdout; runtime missing in a way that exits silently (e.g. shell 'command not found' semantics when spawned via sh -c).","solutions":["Run the exact command and args from the server config manually and observe the exit — most silent exits reproduce immediately","Check the server's args/env against its current version (arg parsing changes after upgrades are the most common cause)","If the wrapper forks/daemonizes, keep the foreground process holding stdout open, or switch the server config to its URL-based mode"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"fn server_command_runs(server: &McpServerConfig) -> bool {\n    std::process::Command::new(&server.command)\n        .args(&server.args)\n        .env_clear()\n        .envs(&server.env)\n        .stdout(std::process::Stdio::null())\n        .stderr(std::process::Stdio::null())\n        .status()\n        .map(|s| s.success())\n        .unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match transport.recv().await {\n    Err(err) if err.to_string() == \"Stdio transport closed\" => {\n        // silent exit: no stderr evidence. Fall back to spawning the command manually to diagnose\n        transport = respawn_stdio_server(&server).await?;\n    }\n    other => other?,\n}","preventionTips":["Dry-run every stdio server command at config-load time to catch silent immediate exits early","Prefer servers that log startup failures to stderr (or wrap them in a shell that redirects stderr)","Keep the foreground process holding stdout open; do not daemonize/fork from the spawned command"],"tags":["stdio","mcp","process-exit","eof"],"backgroundTag":"process-exited-unexpectedly","analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}