{"record":{"id":"dcf6604efcf3f394","repo":"thedotmack/claude-mem","slug":"session-sessiondbid-not-found","errorCode":null,"errorMessage":"Session ${sessionDbId} not found","messagePattern":"Session (.+?) not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/services/worker/DatabaseManager.ts","lineNumber":109,"sourceCode":"    if (!this.db) {\n      throw new Error('Database not initialized');\n    }\n    return this.db;\n  }\n\n  getSessionById(sessionDbId: number): {\n    id: number;\n    content_session_id: string;\n    memory_session_id: string | null;\n    project: string;\n    platform_source: string;\n    user_prompt: string;\n    custom_title: string | null;\n    status: string;\n  } {\n    const session = this.getSessionStore().getSessionById(sessionDbId);\n    if (!session) {\n      throw new Error(`Session ${sessionDbId} not found`);\n    }\n    return session;\n  }\n\n}\n","sourceCodeStart":91,"sourceCodeEnd":115,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d768ba364302d12b76e69e4f021f0bb1d2d50ed6/src/services/worker/DatabaseManager.ts#L91-L115","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before: const s = dbManager.getSessionById(id); // throws if missing\n// after:  const raw = dbManager.getSessionStore().getSessionById(id);\n//         if (!raw) { logger.warn('DB', 'session missing', { id }); return; }\n//         const s = raw;","handlingStrategy":"validation","validationCode":"// Check existence via the store (returns undefined, not throw) before the typed getter:\nfunction getSessionOrUndefined(db: DatabaseManager, id: number) {\n  const raw = db.getSessionStore().getSessionById(id);\n  return raw ?? null;\n}\n// usage:\nconst s = getSessionOrUndefined(dbManager, sessionDbId);\nif (!s) { logger.warn('DB', 'session not found', { sessionDbId }); return; }","typeGuard":null,"tryCatchPattern":"try { return dbManager.getSessionById(sessionDbId); }\ncatch (e) {\n  if (e instanceof Error && /^Session \\d+ not found$/.test(e.message)) {\n    logger.warn('DB', e.message); // stale id; skip\n    return null;\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["worker","database","session","not-found","validation"],"backgroundTag":null,"analyzedSha":"d768ba364302d12b76e69e4f021f0bb1d2d50ed6","analyzedAt":"2026-08-12T23:52:55.241Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}