Hmbown/CodeWhale · error

Stdio transport closed

Error message

Stdio transport closed

What it means

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.

Solutions

  1. Run the exact command and args from the server config manually and observe the exit — most silent exits reproduce immediately
  2. Check the server's args/env against its current version (arg parsing changes after upgrades are the most common cause)
  3. If the wrapper forks/daemonizes, keep the foreground process holding stdout open, or switch the server config to its URL-based mode
Defensive patterns

Strategy: fallback

Validate before calling

fn server_command_runs(server: &McpServerConfig) -> bool {
    std::process::Command::new(&server.command)
        .args(&server.args)
        .env_clear()
        .envs(&server.env)
        .stdout(std::process::Stdio::null())
        .stderr(std::process::Stdio::null())
        .status()
        .map(|s| s.success())
        .unwrap_or(false)
}

Try / catch

match transport.recv().await {
    Err(err) if err.to_string() == "Stdio transport closed" => {
        // silent exit: no stderr evidence. Fall back to spawning the command manually to diagnose
        transport = respawn_stdio_server(&server).await?;
    }
    other => other?,
}

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Related errors


AI-assisted analysis of Hmbown/CodeWhale@0c42157ee5 (2026-08-20). Data as JSON: /api/errors/3dbe67f9304f390f. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/mcp/stdio.rs:327

            // Bounded read: a server emitting a newline-free multi-GB "line"
            // must not OOM us (read_line is unbounded).
            let bytes =
                match read_line_capped(&mut self.reader, &mut line_bytes, MAX_MCP_RESPONSE_BYTES)
                    .await
                {
                    Ok(b) => b,
                    Err(err) => {
                        if let Some(stderr) = format_stderr_context(&self.stderr_tail).await {
                            anyhow::bail!("Stdio transport read error: {err}\n{stderr}");
                        }
                        return Err(err.into());
                    }
                };
            if bytes == 0 {
                if let Some(stderr) = format_stderr_context(&self.stderr_tail).await {
                    anyhow::bail!("Stdio transport closed\n{stderr}");
                }
                anyhow::bail!("Stdio transport closed");
            }

            let line = String::from_utf8_lossy(&line_bytes);
            let trimmed = line.trim();
            if trimmed.is_empty() {
                continue;
            }

            return Ok(trimmed.as_bytes().to_vec());
        }
    }

    /// Send SIGTERM and wait up to `STDIO_SHUTDOWN_GRACE` for graceful exit,
    /// then force termination and reap the child as the backstop.
    async fn shutdown(&mut self) {
        let mut child = self.child.lock().await;
        terminate_child(&mut child).await;
    }

View on GitHub (pinned to 0c42157ee5)