xai-org/grok-build · warning

stop failed

Error message

stop failed: {body}

What it means

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.

Solutions

  1. Treat 'already dead' as success in cleanup code and ignore this error
  2. Verify the session/port before stopping
  3. Remove stale registry entries (`~/.ptyctl` registry dir) and re-run
  4. Use --force on subsequent run to replace stale entries

Example fix

// before
client.stop(session).await?;
// after
if let Err(e) = client.stop(session).await {
    eprintln!("stop ignored: {e}"); // cleanup path: tolerate
}
Defensive patterns

Strategy: try-catch

Validate before calling

if let Ok(info) = registry::lookup_session(name) {
    if !server_alive(info.port).await { /* already dead: skip stop */ }
}

Try / catch

// cleanup paths should tolerate stop failures
if let Err(e) = client.stop(target).await {
    eprintln!("stop ignored during cleanup: {e}");
}

Prevention

When it happens

Trigger: POST to the stop endpoint returning non-2xx — most often the session already died or the registry entry points to a dead/reused port.

Common situations: Cleanup in tests where the session already exited; double-stop from two cleanup paths; stale registry JSON after a crash.

Related errors


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

Appendix: source

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

    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")?;

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

View on GitHub (pinned to bc7f02eddd)