{"record":{"id":"bcdba8a75387da8f","repo":"xai-org/grok-build","slug":"send-failed-body","errorCode":null,"errorMessage":"send failed: {body}","messagePattern":"send failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/ptyctl-cli/src/commands/client.rs","lineNumber":40,"sourceCode":"\n/// Send keystrokes to a session.\npub async fn send(url: &str, keys: &str, enter: bool) -> Result<()> {\n    let mut keys = keys.to_string();\n    if enter {\n        keys.push_str(\"<CR>\");\n    }\n\n    let client = client_for(url)?;\n    let resp = client\n        .post(format!(\"{url}/control/send\"))\n        .json(&serde_json::json!({\"keys\": keys}))\n        .send()\n        .await\n        .context(\"failed to send keys\")?;\n\n    if !resp.status().is_success() {\n        let body = resp.text().await.unwrap_or_default();\n        anyhow::bail!(\"send failed: {body}\");\n    }\n    Ok(())\n}\n\n/// Query screen content.\npub async fn screen(\n    url: &str,\n    rows: Option<&str>,\n    cols: Option<&str>,\n    cursor: Option<char>,\n    format: &str,\n    full: bool,\n    line_numbers: bool,\n) -> Result<()> {\n    let client = client_for(url)?;\n    let mut req = client.get(format!(\"{url}/query/screen\"));\n\n    if let Some(r) = rows {","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/ptyctl-cli/src/commands/client.rs#L22-L58","documentation":"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.","triggerScenarios":"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.","commonSituations":"Session was stopped or crashed between listing and sending; targeting the wrong port; server-side validation rejecting a key notation.","solutions":["Read the body in the error message — it contains the server's actual error","Verify the session is alive (`ptyctl screen --name <s>` or process check)","Re-check the key notation being sent; fix anything the server rejected","If the session died, restart it (`ptyctl run ...`) and resend"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"let info = registry::lookup_session(name)?; // fails fast if session unknown\n// probe liveness before sending","typeGuard":null,"tryCatchPattern":"match client.send(target, keys).await {\n    Ok(()) => {},\n    Err(e) if e.to_string().contains(\"send failed:\") => {\n        eprintln!(\"server rejected: {e}\"); // inspect body, restart session if dead\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Probe session liveness (screen query) before bulk key sends","Log the response body included in the error to diagnose server-side causes","Restart sessions proactively in CI between test cases"],"tags":["http","network","cli"],"backgroundTag":"http-non-2xx-response","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}