xai-org/grok-build · error

wait failed: {body}

Error message

wait failed: {body}

What it means

wait() long-polls the session's wait endpoint until screen content matches an expected pattern (optionally stable for N ms). Non-2xx responses become this error with the server's body.

Source

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

        .get(format!("{url}/wait"))
        .query(&[("timeout_ms", timeout_secs.saturating_mul(1000).to_string())]);
    if let Some(t) = text {
        req = req.query(&[("text", t)]);
    }
    if let Some(r) = regex {
        req = req.query(&[("regex", r)]);
    }
    if let Some(g) = gone {
        req = req.query(&[("gone", g)]);
    }
    if let Some(ms) = stable_ms {
        req = req.query(&[("stable_ms", ms.to_string())]);
    }

    let resp = req.send().await.context("failed to call wait")?;
    if !resp.status().is_success() {
        let body = resp.text().await.unwrap_or_default();
        anyhow::bail!("wait failed: {body}");
    }

    let outcome: serde_json::Value = resp.json().await.context("invalid wait response")?;
    println!("{}", serde_json::to_string_pretty(&outcome)?);
    Ok(outcome
        .get("matched")
        .and_then(|m| m.as_bool())
        .unwrap_or(false))
}

/// Stop a session.
pub async fn stop(url: &str) -> Result<()> {
    let client = client_for(url)?;
    let resp = client
        .post(format!("{url}/control/stop"))
        .send()
        .await
        .context("failed to stop session")?;

View on GitHub (pinned to bc7f02eddd)

Solutions

  1. Read the server body in the error for the cause
  2. Verify the session is still running before waiting
  3. Validate pattern/stable_ms parameters
  4. Add retry with backoff around wait for transient server errors
Defensive patterns

Strategy: retry

Validate before calling

registry::lookup_session(name)?; // ensure session exists before long-polling

Try / catch

for attempt in 0..3 {
    match client.wait(target, pattern, stable_ms).await {
        Ok(outcome) => break outcome,
        Err(e) if attempt < 2 && e.to_string().contains("wait failed:") => {
            tokio::time::sleep(Duration::from_millis(500)).await;
        }
        Err(e) => return Err(e),
    }
}

Prevention

When it happens

Trigger: Long-poll request rejected by the server: session not found, timed out server-side, or malformed query params (pattern/stable_ms).

Common situations: CI/test suites waiting on TUI output from a session that died; passing invalid stable_ms values; wrong session name.

Related errors


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