affaan-m/ECC · error · anyhow::Error
Session not found
Error message
Session not found: {resolved_id} What it means
`worktree-status` without `--all` resolves the session ID (defaulting to "latest") and loads the session from the database. If the resolved ID has no row, the command bails with this error before building the worktree status report.
Solutions
- Run the sessions list command to confirm the ID exists and copy it exactly.
- Ensure at least one session exists; create/start a session first if the database is empty.
- Run from the correct project directory so ecc2 opens the database containing the session.
- If a custom ID was passed, check for typos or stale short IDs and re-resolve.
Example fix
// before
let resolved_id = resolve_session_id(&db, &id)?;
let session = db.get_session(&resolved_id)?.ok_or_else(|| anyhow::anyhow!("Session not found: {resolved_id}"))?;
// after
let resolved_id = resolve_session_id(&db, &id)?;
let session = db.get_session(&resolved_id)?.ok_or_else(|| anyhow::anyhow!(
"Session not found: {resolved_id}; list sessions with `ecc2 sessions`"
))?; Defensive patterns
Strategy: validation
Validate before calling
// shell: ensure the session exists (or default to latest only when sessions exist)
ecc2 sessions --json | jq -e --arg id "${SESSION_ID:-}" '($id == "") or (map(.id) | index($id))' >/dev/null || { echo "session $SESSION_ID not found"; exit 1; } Type guard
fn session_exists(db: &Db, id: &str) -> anyhow::Result<bool> {
Ok(db.get_session(id)?.is_some())
} Try / catch
// handle the empty-DB case explicitly before reporting not-found
if db.get_session(&resolved_id)?.is_none() {
eprintln!("no session {resolved_id}; create one or list with `ecc2 sessions`");
std::process::exit(1);
} Prevention
- Create at least one session before running worktree status commands.
- Verify IDs against `ecc2 sessions` output in scripts.
- Run commands from the project root so the correct database is opened.
- Don't hardcode session IDs in long-lived scripts; resolve 'latest' at runtime.
When it happens
Trigger: Running `ecc2 worktree-status [<session-id>]` where the ID (or the session resolved by "latest") is missing from the sessions table.
Common situations: Running the command in a fresh repo with no sessions yet (so even "latest" resolves to nothing); referencing a deleted session; wrong data directory or project so the ID is not in this database.
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
- No sessions found
- Session not found
- Session not found
- Context graph entity not found
- Context graph observation #
AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16).
Data as JSON: /api/errors/452cdcd85e2ae079.
Report an issue: GitHub.
Appendix: source
Thrown at ecc2/src/main.rs:2009
patch,
check,
}) => {
if all && session_id.is_some() {
return Err(anyhow::anyhow!(
"worktree-status does not accept a session ID when --all is set"
));
}
let reports = if all {
session::manager::list_sessions(&db)?
.into_iter()
.map(|session| build_worktree_status_report(&session, patch))
.collect::<Result<Vec<_>>>()?
} else {
let id = session_id.unwrap_or_else(|| "latest".to_string());
let resolved_id = resolve_session_id(&db, &id)?;
let session = db
.get_session(&resolved_id)?
.ok_or_else(|| anyhow::anyhow!("Session not found: {resolved_id}"))?;
vec![build_worktree_status_report(&session, patch)?]
};
if json {
if all {
println!("{}", serde_json::to_string_pretty(&reports)?);
} else {
println!("{}", serde_json::to_string_pretty(&reports[0])?);
}
} else {
println!("{}", format_worktree_status_reports_human(&reports));
}
if check {
std::process::exit(worktree_status_reports_exit_code(&reports));
}
}
Some(Commands::WorktreeResolution {
session_id,
all,View on GitHub (pinned to 8321021c54)