astrid-runtime/astrid · error

Session not found

Error message

Session not found: {id}

What it means

delete_session validates the ID as a UUID, resolves the Astrid home, and removes the session's directory under run_dir. If no directory with that ID exists, it bails with "Session not found" instead of attempting removal. The check prevents silently 'succeeding' on a typo'd or already-deleted session.

Solutions

  1. List current sessions (`astrid sessions list`) and copy the exact UUID to delete.
  2. If the session already ended, treat the delete as a no-op — the directory is already gone.
  3. Verify ASTRID_HOME points to the home that owned the session before deleting.

Example fix

// before
astrid sessions delete 9f0c...typo-id

// after
ID=$(astrid sessions list --json | jq -r '.[0].id')
astrid sessions delete "$ID"
Defensive patterns

Strategy: validation

Validate before calling

let dir = AstridHome::resolve()?.run_dir().join(id);
if !dir.exists() {
    eprintln!("session {id} is not live; nothing to delete");
    return Ok(()); // treat as idempotent no-op
}

Try / catch

match delete_session(id) {
    Err(e) if e.to_string().starts_with("Session not found") => {
        eprintln!("already gone; ignoring"); // idempotent delete
    }
    other => other?,
}

Prevention

When it happens

Trigger: `astrid sessions delete <id>` where run_dir/<id> does not exist: the session already ended and was cleaned up, the ID was mistyped, or the session belongs to a different ASTRID_HOME.

Common situations: Deleting the same session twice in a script; copying a session ID from another machine; ASTRID_HOME pointing at a different home than the daemon that created the session.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of astrid-runtime/astrid@affd8760f4 (2026-09-09). Data as JSON: /api/errors/2eb37e4ffb42e640. Report an issue: GitHub.

Appendix: source

Thrown at crates/astrid-cli/src/commands/sessions.rs:61

        let time = chrono::DateTime::<chrono::Local>::from(modified)
            .format("%Y-%m-%d %H:%M:%S")
            .to_string();
        println!("  {} ({})", Theme::session_id(&id), Theme::dimmed(&time));
    }

    Ok(())
}

/// Delete a session by UUID.
pub(crate) fn delete_session(id: &str) -> Result<()> {
    // Validate as UUID to prevent path traversal (e.g. "../../config")
    uuid::Uuid::parse_str(id)
        .map_err(|_| anyhow::anyhow!("Invalid session ID (must be a UUID): {id}"))?;
    let home = AstridHome::resolve().context("Failed to resolve Astrid home directory")?;
    let session_dir = home.run_dir().join(id);

    if !session_dir.exists() {
        anyhow::bail!("Session not found: {id}");
    }

    fs::remove_dir_all(&session_dir)?;
    println!("{}", Theme::success(&format!("Deleted session {id}")));
    Ok(())
}

/// Show information about a session by UUID.
pub(crate) fn session_info(id: &str) -> Result<()> {
    uuid::Uuid::parse_str(id)
        .map_err(|_| anyhow::anyhow!("Invalid session ID (must be a UUID): {id}"))?;
    let home = AstridHome::resolve().context("Failed to resolve Astrid home directory")?;
    let session_dir = home.run_dir().join(id);

    if !session_dir.exists() {
        anyhow::bail!("Session not found: {id}");
    }

View on GitHub (pinned to affd8760f4)