affaan-m/ECC · error

Session not found

Error message

Session not found: {id}

What it means

Returned when a session lookup by id (or the literal "latest") yields no record in the state store. get_session/get_latest_session return Option and the manager converts None into an anyhow error embedding the requested id. This is the canonical 'unknown session id' error of the manager API.

Solutions

  1. List existing sessions and confirm the id before acting on it
  2. Fix the typo or use the correct session id
  3. Create a session first (run_session) before querying it; for 'latest', ensure at least one session exists

Example fix

// before
manager.stop_session("ses_abc123").await?;
// after
if manager.get_session("ses_abc123").await?.is_none() {
    eprintln!("session ses_abc123 not found");
    return Ok(());
}
manager.stop_session("ses_abc123").await?;
Defensive patterns

Strategy: validation

Validate before calling

let known = manager.list_sessions().await?;
if !known.iter().any(|s| s.id == id) {
    eprintln!("unknown session id: {id}");
    return Ok(());
}

Try / catch

match manager.get_session(id).await {
    Ok(Some(s)) => /* proceed */,
    Ok(None) => eprintln!("Session not found: {id}"),
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling stop/logs/status/rebase entry points with an id that was never created, a typo'd id, after the DB was deleted, or when no sessions exist at all and 'latest' resolves to nothing.

Common situations: Stale session ids in scripts after wiping the .claude state DB; querying 'latest' in a fresh checkout with zero recorded sessions; passing a foreign/other-project session id.

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 affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/6baeb53ab8d681c8. Report an issue: GitHub.

Appendix: source

Thrown at ecc2/src/session/manager.rs:2356

    }

    match harness {
        HarnessKind::Claude => Ok(PathBuf::from("claude")),
        HarnessKind::Codex => Ok(PathBuf::from("codex")),
        HarnessKind::OpenCode => Ok(PathBuf::from("opencode")),
        HarnessKind::Gemini => Ok(PathBuf::from("gemini")),
        other => anyhow::bail!("Unsupported agent type: {other}"),
    }
}

fn resolve_session(db: &StateStore, id: &str) -> Result<Session> {
    let session = if id == "latest" {
        db.get_latest_session()?
    } else {
        db.get_session(id)?
    };

    session.ok_or_else(|| anyhow::anyhow!("Session not found: {id}"))
}

fn parse_cron_schedule(expr: &str) -> Result<CronSchedule> {
    let trimmed = expr.trim();
    let normalized = match trimmed.split_whitespace().count() {
        5 => format!("0 {trimmed}"),
        6 | 7 => trimmed.to_string(),
        fields => {
            anyhow::bail!(
                "invalid cron expression `{trimmed}`: expected 5, 6, or 7 fields but found {fields}"
            )
        }
    };
    CronSchedule::from_str(&normalized)
        .with_context(|| format!("invalid cron expression `{trimmed}`"))
}

fn next_schedule_run_at(

View on GitHub (pinned to 8321021c54)