zed-industries/zed · error
Cannot have two different hosts in debug configuration
Error message
Cannot have two different hosts in debug configuration
What it means
debugpy attach validation in Zed's Python adapter: when `request` is `"attach"` and both the task-level `tcp_connection` block already carry a `host` AND the adapter `config` object also has a `"host"` key, Zed cannot tell which host to dial and bails instead of guessing (python.rs:377). This guards against silently attaching to the wrong machine.
Source
Thrown at crates/dap_adapters/src/python.rs:377
)
})
.unwrap_or_else(|| {
(
config
.config
.get("port")
.and_then(|port| port.as_u64().map(|p| p as u16)),
config.config.get("host").and_then(|host| host.as_str()),
)
});
let is_attach_with_connect = if config
.config
.get("request")
.is_some_and(|val| val.as_str().is_some_and(|request| request == "attach"))
{
if tcp_connection.host.is_some() && config_host.is_some() {
bail!("Cannot have two different hosts in debug configuration")
} else if tcp_connection.port.is_some() && config_port.is_some() {
bail!("Cannot have two different ports in debug configuration")
}
if let Some(hostname) = config_host {
tcp_connection.host = Some(hostname.parse().context("invalid IP address")?);
}
tcp_connection.port = config_port;
DebugpyLaunchMode::AttachWithConnect { host: config_host }
} else {
DebugpyLaunchMode::Normal
};
let (host, port, timeout) = crate::configure_tcp_connection(tcp_connection).await?;
let python_path = if let Some(toolchain) = python_from_toolchain {
Some(toolchain)
} else {View on GitHub (pinned to f4178619ac)
Solutions
- Remove `host` from the `config` object and keep it only in `tcp_connection` (or the reverse) so exactly one source defines it.
- For local debugpy attach, prefer `"tcp_connection": { "host": "127.0.0.1", "port": 5678 }` with `"request": "attach"` and no host inside config.
Example fix
// before (debug.json)
{
"adapter": "Python",
"request": "attach",
"tcp_connection": { "host": "127.0.0.1", "port": 5678 },
"config": { "host": "localhost", "port": 5678 }
}
// after
{
"adapter": "Python",
"request": "attach",
"tcp_connection": { "host": "127.0.0.1", "port": 5678 },
"config": { "request": "attach" }
} Defensive patterns
Strategy: validation
Validate before calling
// reject attach configs that define host in two places, before starting a session
let has_tcp_host = task.tcp_connection.as_ref().is_some_and(|t| t.host.is_some());
let has_config_host = task.config.get("request") == Some("attach") && task.config.get("host").is_some();
if has_tcp_host && has_config_host {
return Err(anyhow!("remove `host` from either tcp_connection or config"));
} Type guard
fn defines_host_once(tcp: &Option<TcpConnection>, config: &serde_json::Value) -> bool {
let in_tcp = tcp.as_ref().is_some_and(|t| t.host.is_some());
let in_config = config.get("host").is_some_and(|v| !v.is_null());
!(in_tcp && in_config)
} Try / catch
Catch before session start and print both offending values (tcp_connection.host vs config.host) so the user sees the conflict instead of a generic failure.
Prevention
- Adopt a convention: connection transport fields live only in tcp_connection; adapter behavior fields live only in config.
- Lint debug configs on save for duplicate host/port keys.
- When migrating from VS Code launch.json, delete transport keys from the pasted config.
When it happens
Trigger: A Zed debug task with `adapter: "Python"`, `tcp_connection: { "host": "127.0.0.1", "port": 5678 }`, and a `config` that also contains `"host": "localhost"` under an attach request. Both sources being non-null on an attach request is the exact trigger.
Common situations: Pasting a VS Code launch.json (which puts host/port inside the config) into a Zed debug configuration that already declares tcp_connection; incrementally migrating attach configs and leaving the old host key behind.
Related errors
- Cannot have two different ports in debug configuration
- debug config not found in mode: {mode}
- No process selected with config that contains {}
- Zed cannot determine how to run this debug scenario. `build`
- Expected exactly one context server configuration
AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20).
Data as JSON: /api/errors/2a5f8d9e0a21d7f4.
Report an issue: GitHub.