affaan-m/ECC · error · anyhow::Error

Session not found: {id}

Error message

Session not found: {id}

What it means

The resolve_session helper is the central session-ID resolver used by many public functions (merge, rebase, delete, resume, run_session, etc.). It accepts 'latest' as a special keyword to fetch the most recent session, or looks up by explicit ID. If neither yields a session, it bails. This error propagates through many call sites.

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 01e15490f0)

Solutions

  1. Verify the session ID exists by listing sessions before operating on one
  2. If using 'latest', check that at least one session exists in the DB first
  3. Ensure cfg.db_path points to the correct state store file
  4. Handle the not-found error gracefully in the calling layer with a user-facing message

Example fix

// before
let session = resolve_session(db, id)?;

// after
let session = resolve_session(db, id)
    .with_context(|| format!("Session '{id}' not found. Run `ecc2 sessions list` to see available sessions."))?
;
Defensive patterns

Strategy: validation

Validate before calling

fn session_exists(db: &StateStore, id: &str) -> Result<bool> {
    if id == "latest" {
        Ok(db.get_latest_session()?.is_some())
    } else {
        Ok(db.get_session(id)?.is_some())
    }
}

// Before calling any resolve_session-dependent function:
if !session_exists(db, id)? {
    return Err(anyhow!("Session '{id}' not found"));
}

Try / catch

match resolve_session(db, id) {
    Ok(session) => Ok(session),
    Err(e) if e.to_string().contains("Session not found") => {
        Err(anyhow!("Session '{id}' not found. Use `ecc2 sessions list` to see available IDs.").context(e))
    }
    Err(e) => Err(e),
}

Prevention

When it happens

Trigger: Calling any function that uses resolve_session with an ID that does not exist in the DB, or using 'latest' when the DB has no sessions at all.

Common situations: Empty database on first run. Session was deleted. Wrong DB file path. Using 'latest' before any sessions have been created.

Related errors


AI-assisted analysis of affaan-m/ECC@01e15490f0 (2026-08-13). Data as JSON: /api/errors/6baeb53ab8d681c8. Report an issue: GitHub.