Hmbown/CodeWhale · error

Stdio transport closed

Error message

Stdio transport closed
{stderr}

What it means

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).

Solutions

  1. Read the stderr excerpt in the error message — it is the server's dying words and usually names the bug
  2. Reproduce by running the server's command + args manually in a shell and observe the failure directly
  3. Fix the server-side crash (or its args/env), then let the client respawn/reconnect the transport
Defensive patterns

Strategy: fallback

Try / catch

match transport.recv().await {
    Err(err) if err.to_string().starts_with("Stdio transport closed\n") => {
        // stderr excerpt embedded: surface it, mark tools unavailable, optionally respawn
        report_server_exit(&err);
        transport = respawn_stdio_server(&server).await.ok();
    }
    other => other?,
}

Prevention

When it happens

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

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

Related errors


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

Appendix: source

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

        let mut line_bytes: Vec<u8> = Vec::new();
        loop {
            // 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;

View on GitHub (pinned to 0c42157ee5)