thedotmack/claude-mem · error · Error
Session ${sessionDbId} not found
Error message
Session ${sessionDbId} not found What it means
Thrown by DatabaseManager.getSessionById when the underlying session store returns no row for the given sessionDbId. This is a thin existence guard: the numeric id was passed in but does not correspond to any sdk_sessions row. The caller gets a typed session object or this error — there is no null return.
Source
Thrown at src/services/worker/DatabaseManager.ts:109
if (!this.db) {
throw new Error('Database not initialized');
}
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;
} {
const session = this.getSessionStore().getSessionById(sessionDbId);
if (!session) {
throw new Error(`Session ${sessionDbId} not found`);
}
return session;
}
}
View on GitHub (pinned to d768ba3643)
Solutions
- Verify the sessionDbId exists: query `SELECT id FROM sdk_sessions WHERE id = ?` before calling getSessionById, or use the store's own getter that returns undefined.
- If the id came from a message/event, confirm it was produced by the same database the worker is using.
- Handle the 'not found' case gracefully (skip/log) rather than letting it propagate if stale ids are expected.
- Check for a pruning/cleanup job that removed the session between id capture and lookup.
Example fix
// before: const s = dbManager.getSessionById(id); // throws if missing
// after: const raw = dbManager.getSessionStore().getSessionById(id);
// if (!raw) { logger.warn('DB', 'session missing', { id }); return; }
// const s = raw; Defensive patterns
Strategy: validation
Validate before calling
// Check existence via the store (returns undefined, not throw) before the typed getter:
function getSessionOrUndefined(db: DatabaseManager, id: number) {
const raw = db.getSessionStore().getSessionById(id);
return raw ?? null;
}
// usage:
const s = getSessionOrUndefined(dbManager, sessionDbId);
if (!s) { logger.warn('DB', 'session not found', { sessionDbId }); return; } Try / catch
try { return dbManager.getSessionById(sessionDbId); }
catch (e) {
if (e instanceof Error && /^Session \d+ not found$/.test(e.message)) {
logger.warn('DB', e.message); // stale id; skip
return null;
}
throw e;
} Prevention
- Use the store-level getter (returns undefined) when absence is expected; reserve getSessionById for cases where absence is an error.
- Re-verify session ids captured from events against the live DB before heavy use.
- Guard pruning jobs so they don't remove sessions still referenced by in-flight work.
When it happens
Trigger: getSessionById(sessionDbId) delegates to getSessionStore().getSessionById(id); if it returns falsy, throw `Session ${sessionDbId} not found`. Reachable from any code path that resolves a numeric session id to a full row (worker processing, timeline, search).
Common situations: A stale/cached sessionDbId after the session was deleted, an id from a different database/profile, a race where the session was pruned between lookup and use, or an off-by-one/wrong id passed by the caller. Common in multi-device setups where ids are not globally aligned.
Related errors
- Invalid CLAUDE_MEM_WORKER_PORT in settings.json: missing
- server startup configuration is invalid: - ${line}
- ingestObservation failed: ${result.reason}
- agent_event source_id must belong to project_id and team_id
- SSE stream returned HTTP ${response.status}
AI-assisted analysis of thedotmack/claude-mem@d768ba3643 (2026-08-12).
Data as JSON: /api/errors/dcf6604efcf3f394.
Report an issue: GitHub.