zed-industries/zed · error
failed to connect: {}
Error message
failed to connect: {} What it means
Immediately after the connection race, Zed checks whether the ssh master already terminated (try_status() is Some); if so it drains the process's stderr and reports it verbatim as `failed to connect: <stderr>`. The embedded text is ssh's own error output and pinpoints why the connection dropped.
Source
Thrown at crates/remote/src/transport/ssh.rs:712
_ = master_process.wait_connected().fuse() => {
anyhow::Ok(())
}
};
if let Err(e) = result {
return Err(e.context("Failed to connect to host"));
}
if master_process.as_mut().try_status()?.is_some() {
let mut output = Vec::new();
let mut stderr = master_process.as_mut().stderr.take().unwrap();
stderr.read_to_end(&mut output).await?;
let error_message = format!(
"failed to connect: {}",
String::from_utf8_lossy(&output).trim()
);
anyhow::bail!(error_message);
}
let socket = SshSocket::new(connection_options, socket_path).await?;
drop(askpass);
(socket, Some(master_process))
};
#[cfg(windows)]
let (socket, master_process_option) = {
let askpass_delegate = askpass::AskPassDelegate::new_with_cancellation(cx, {
let delegate = delegate.clone();
move |prompt, tx, cancellation, cx| {
delegate.ask_password(prompt, tx, cancellation, cx)
}
});
let mut askpass =
askpass::AskPassSession::new(cx.background_executor().clone(), askpass_delegate)View on GitHub (pinned to f4178619ac)
Solutions
- Read the embedded ssh stderr — it names the exact cause (host key, auth, network)
- Host key changed after rebuild: `ssh-keygen -R <host>` (or edit known_hosts), then reconnect
- Auth: confirm the key is loaded (`ssh-add -l`) and the username is correct
- Re-check any additional ssh arguments in the connection options for validity
Example fix
# before: stderr says 'Host key verification failed.' ssh-keygen -R host.example.com # after: reconnect from Zed; handshake completes
Defensive patterns
Strategy: try-catch
Validate before calling
// Preflight the same options Zed will use: // ssh -o BatchMode=yes -o ConnectTimeout=5 <user>@<host> true // non-zero exit + stderr predicts this failure before opening Zed's session
Try / catch
if let Err(e) = connect(&opts, cx).await {
if let Some(stderr) = e.to_string().strip_prefix("failed to connect: ") {
// display ssh's own stderr (host key, auth, network) to the user verbatim
}
return Err(e);
} Prevention
- Clear changed host keys with ssh-keygen -R after server rebuilds
- Keep needed keys loaded in the agent (ssh-add -l before connecting)
- Validate extra ssh args in connection options against `ssh -G`
When it happens
Trigger: The Unix master ssh process exits during/right after establishment: host key verification failure, permission denied (publickey/password), connection reset, unsupported KEX/ciphers, or invalid options passed through connection_options additional args.
Common situations: REMOTE HOST IDENTIFICATION HAS CHANGED after a server rebuild; agent missing the right key (Permission denied (publickey)); bastions or middleboxes resetting the session; typos in extra ssh arguments configured for the connection.
Related errors
- ssh process exited before connection established
- connecting to host timed out
- build ids may only contain lowercase letters, numbers, '.',
- unknown judge preset '{name}' (valid: {valid})
- registry dataset requires a name
AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20).
Data as JSON: /api/errors/8a0eeaf876007622.
Report an issue: GitHub.