{"record":{"id":"cadfa2781c93e653","repo":"xai-org/grok-build","slug":"wait-failed-body","errorCode":null,"errorMessage":"wait failed: {body}","messagePattern":"wait failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/ptyctl-cli/src/commands/client.rs","lineNumber":189,"sourceCode":"        .get(format!(\"{url}/wait\"))\n        .query(&[(\"timeout_ms\", timeout_secs.saturating_mul(1000).to_string())]);\n    if let Some(t) = text {\n        req = req.query(&[(\"text\", t)]);\n    }\n    if let Some(r) = regex {\n        req = req.query(&[(\"regex\", r)]);\n    }\n    if let Some(g) = gone {\n        req = req.query(&[(\"gone\", g)]);\n    }\n    if let Some(ms) = stable_ms {\n        req = req.query(&[(\"stable_ms\", ms.to_string())]);\n    }\n\n    let resp = req.send().await.context(\"failed to call wait\")?;\n    if !resp.status().is_success() {\n        let body = resp.text().await.unwrap_or_default();\n        anyhow::bail!(\"wait failed: {body}\");\n    }\n\n    let outcome: serde_json::Value = resp.json().await.context(\"invalid wait response\")?;\n    println!(\"{}\", serde_json::to_string_pretty(&outcome)?);\n    Ok(outcome\n        .get(\"matched\")\n        .and_then(|m| m.as_bool())\n        .unwrap_or(false))\n}\n\n/// Stop a session.\npub async fn stop(url: &str) -> Result<()> {\n    let client = client_for(url)?;\n    let resp = client\n        .post(format!(\"{url}/control/stop\"))\n        .send()\n        .await\n        .context(\"failed to stop session\")?;","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/ptyctl-cli/src/commands/client.rs#L171-L207","documentation":"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.","triggerScenarios":"Long-poll request rejected by the server: session not found, timed out server-side, or malformed query params (pattern/stable_ms).","commonSituations":"CI/test suites waiting on TUI output from a session that died; passing invalid stable_ms values; wrong session name.","solutions":["Read the server body in the error for the cause","Verify the session is still running before waiting","Validate pattern/stable_ms parameters","Add retry with backoff around wait for transient server errors"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"registry::lookup_session(name)?; // ensure session exists before long-polling","typeGuard":null,"tryCatchPattern":"for attempt in 0..3 {\n    match client.wait(target, pattern, stable_ms).await {\n        Ok(outcome) => break outcome,\n        Err(e) if attempt < 2 && e.to_string().contains(\"wait failed:\") => {\n            tokio::time::sleep(Duration::from_millis(500)).await;\n        }\n        Err(e) => return Err(e),\n    }\n}","preventionTips":["Use retry with backoff around long-polls; servers may reject transiently","Check session liveness before waiting on output","Keep stable_ms within server-accepted ranges"],"tags":["http","network","cli","timeout"],"backgroundTag":"http-non-2xx-response","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}