{"record":{"id":"cc25ece2611cc10e","repo":"xai-org/grok-build","slug":"stop-failed-body","errorCode":null,"errorMessage":"stop failed: {body}","messagePattern":"stop failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/codegen/ptyctl-cli/src/commands/client.rs","lineNumber":211,"sourceCode":"    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\")?;\n\n    if !resp.status().is_success() {\n        let body = resp.text().await.unwrap_or_default();\n        anyhow::bail!(\"stop failed: {body}\");\n    }\n    println!(\"Session stopped\");\n    Ok(())\n}\n","sourceCodeStart":193,"sourceCodeEnd":216,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/ptyctl-cli/src/commands/client.rs#L193-L216","documentation":"stop() asks the session server to shut down. A non-2xx response is surfaced as this error with the server's body, typically because the session already exited or the port is stale.","triggerScenarios":"POST to the stop endpoint returning non-2xx — most often the session already died or the registry entry points to a dead/reused port.","commonSituations":"Cleanup in tests where the session already exited; double-stop from two cleanup paths; stale registry JSON after a crash.","solutions":["Treat 'already dead' as success in cleanup code and ignore this error","Verify the session/port before stopping","Remove stale registry entries (`~/.ptyctl` registry dir) and re-run","Use --force on subsequent run to replace stale entries"],"exampleFix":"// before\nclient.stop(session).await?;\n// after\nif let Err(e) = client.stop(session).await {\n    eprintln!(\"stop ignored: {e}\"); // cleanup path: tolerate\n}","handlingStrategy":"try-catch","validationCode":"if let Ok(info) = registry::lookup_session(name) {\n    if !server_alive(info.port).await { /* already dead: skip stop */ }\n}","typeGuard":null,"tryCatchPattern":"// cleanup paths should tolerate stop failures\nif let Err(e) = client.stop(target).await {\n    eprintln!(\"stop ignored during cleanup: {e}\");\n}","preventionTips":["Guard stop behind a liveness check to avoid double-stop noise","Idempotent cleanup: treat 'already stopped' as success","Run `ptyctl run --force` when registry entries may be stale"],"tags":["http","network","cli","cleanup"],"backgroundTag":"http-non-2xx-response","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}