xai-org/grok-build · error

send failed: {body}

Error message

send failed: {body}

What it means

send() POSTs key events to a running pty session's HTTP endpoint. If the server responds with a non-2xx status, the response body (usually an error message from the server) is surfaced via this error.

Source

Thrown at crates/codegen/ptyctl-cli/src/commands/client.rs:40

/// Send keystrokes to a session.
pub async fn send(url: &str, keys: &str, enter: bool) -> Result<()> {
    let mut keys = keys.to_string();
    if enter {
        keys.push_str("<CR>");
    }

    let client = client_for(url)?;
    let resp = client
        .post(format!("{url}/control/send"))
        .json(&serde_json::json!({"keys": keys}))
        .send()
        .await
        .context("failed to send keys")?;

    if !resp.status().is_success() {
        let body = resp.text().await.unwrap_or_default();
        anyhow::bail!("send failed: {body}");
    }
    Ok(())
}

/// Query screen content.
pub async fn screen(
    url: &str,
    rows: Option<&str>,
    cols: Option<&str>,
    cursor: Option<char>,
    format: &str,
    full: bool,
    line_numbers: bool,
) -> Result<()> {
    let client = client_for(url)?;
    let mut req = client.get(format!("{url}/query/screen"));

    if let Some(r) = rows {

View on GitHub (pinned to bc7f02eddd)

Solutions

  1. Read the body in the error message — it contains the server's actual error
  2. Verify the session is alive (`ptyctl screen --name <s>` or process check)
  3. Re-check the key notation being sent; fix anything the server rejected
  4. If the session died, restart it (`ptyctl run ...`) and resend
Defensive patterns

Strategy: try-catch

Validate before calling

let info = registry::lookup_session(name)?; // fails fast if session unknown
// probe liveness before sending

Try / catch

match client.send(target, keys).await {
    Ok(()) => {},
    Err(e) if e.to_string().contains("send failed:") => {
        eprintln!("server rejected: {e}"); // inspect body, restart session if dead
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Any keys/send request where the server returns a non-success HTTP status, e.g. unknown session, session crashed mid-request, or malformed key payload rejected server-side.

Common situations: Session was stopped or crashed between listing and sending; targeting the wrong port; server-side validation rejecting a key notation.

Related errors


AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31). Data as JSON: /api/errors/bcdba8a75387da8f. Report an issue: GitHub.