xai-org/x-algorithm · error · std::io::Error

InvalidInput

InvalidInput

Error message

copy_url must be host:port, got {}

What it means

resolve_and_connect splits copy_url on the LAST colon via rsplit_once(':'); if there is no colon at all (no host:port), it returns InvalidInput. The URL scheme prefix is stripped beforehand, so the remainder must literally contain host:port.

Source

Thrown at phoenix/crates/serving/xai-recsys-engine/src/checkpoint_proxy.rs:97

            num_trainers,
            last_prefix: tokio::sync::Mutex::new(String::new()),
            downloading: AtomicBool::new(false),
            max_entries,
            verify_checksums,
            download_concurrency,
            request_timeout,
        }
    }

    async fn resolve_and_connect(&self) -> Result<Vec<transport::Channel>, io::Error> {
        let (scheme, hostport) = if let Some(rest) = self.copy_url.strip_prefix("https://") {
            ("https", rest)
        } else {
            ("http", self.copy_url.trim_start_matches("http://"))
        };
        let tls = crate::tls::ClientTlsOptions::from_env()?;
        let (name, port) = hostport.rsplit_once(':').ok_or_else(|| {
            io::Error::new(
                io::ErrorKind::InvalidInput,
                format!("copy_url must be host:port, got {}", self.copy_url),
            )
        })?;

        let addrs: Vec<SocketAddr> = format!("{}:{}", name, port).to_socket_addrs()?.collect();

        if addrs.is_empty() {
            return Err(io::Error::new(
                io::ErrorKind::NotFound,
                format!("DNS resolution returned 0 addresses for {}", name),
            ));
        }

        let dns_count = addrs.len();

        let connect_timeout = std::time::Duration::from_secs(
            std::env::var("COPY_PORT_CONNECT_TIMEOUT_SECS")

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Set copy_url to explicit host:port, e.g. 'trainer-0:50051'
  2. Include the port even when using https (the code only auto-handles the scheme)
  3. Check for empty/mispasted env values (COPY_URL) before launch

Example fix

# before
--copy-url trainer-0

# after
--copy-url trainer-0:50051
Defensive patterns

Strategy: validation

Validate before calling

fn valid_copy_url(u: &str) -> bool {
    let s = u.trim().trim_start_matches("http://").trim_start_matches("https://");
    match s.rsplit_once(':') { Some((h, p)) => !h.is_empty() && p.parse::<u16>().is_ok(), _ => false }
}

Prevention

When it happens

Trigger: Setting copy_url to a bare hostname like 'trainer1' with no port, or a malformed value like 'host:' / trailing garbage where rsplit_once fails, when poll_and_download runs.

Common situations: Env var or CLI flag for the checkpoint copy URL misconfigured; passing an https:// URL with no explicit port; whitespace or empty string in copy_url.

Related errors


AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28). Data as JSON: /api/errors/7229bf803a2d6dee. Report an issue: GitHub.