thedotmack/claude-mem · error · Error
Session not found
Error message
Session ${sessionDbId} not found What it means
DatabaseManager.getSessionById delegates to the session store and throws when no session row exists for the given numeric sessionDbId. It is a strict accessor: callers that require an existing session (to attach prompts, observations, etc.) get a loud failure rather than a null to mishandle downstream.
Solutions
- Verify the sessionDbId against the sessions table (SELECT id FROM sessions ...).
- Look up the session again by its current id rather than reusing a cached/stale id.
- If sessions may legitimately disappear, use the store's nullable getter and handle null.
- Confirm the worker points at the intended DB (~/.claude-mem/claude-mem.db), not another copy.
Example fix
// before const s = db.getSessionById(id); // throws // after const s = db.getSessionStore().getSessionById(id); if (!s) return; // or recreate the session
Defensive patterns
Strategy: try-catch
Validate before calling
const exists = db.getSessionStore().getSessionById(sessionDbId); if (!exists) return; // handle missing session before strict call
Try / catch
try { const s = db.getSessionById(id); } catch (e) { if (e.message.startsWith('Session ') && e.message.endsWith(' not found')) { /* recreate or skip */ } } Prevention
- Use nullable getters when absence is an expected case.
- Purge cached session ids when the DB is reset or migrated.
- Log the id and DB path when a session lookup fails.
When it happens
Trigger: Calling getSessionById(sessionDbId) with an id that is not in the sessions table — deleted session row, stale id from a previous DB, or an id belonging to a different database file.
Common situations: Worker resumed after the DB was reset/migrated; message referencing a session id from a removed record; concurrent process deleted the session; hardcoding an id from logs against a fresh DB.
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
- Session not found in sdk_sessions
- Cannot bootstrap server API key…
- Cannot process observations: memorySessionId not yet…
- Cannot process summary: memorySessionId not yet captured…
- cloud sync unavailable; refusing an unreplicated delete
AI-assisted analysis of thedotmack/claude-mem@d8bc9755e7 (2026-09-17).
Data as JSON: /api/errors/dcf6604efcf3f394.
Report an issue: GitHub.
Appendix: source
Thrown at src/services/worker/DatabaseManager.ts:116
}
return this.db;
}
getSessionById(sessionDbId: number): {
id: number;
content_session_id: string;
memory_session_id: string | null;
project: string;
platform_source: string;
user_prompt: string;
custom_title: string | null;
status: string;
observed_model: string | null;
observed_billing: string | null;
} {
const session = this.getSessionStore().getSessionById(sessionDbId);
if (!session) {
throw new Error(`Session ${sessionDbId} not found`);
}
return session;
}
}
View on GitHub (pinned to d8bc9755e7)