From bd5d95beff4cc43ae2c7c5d5ec18aa8255f2c604 Mon Sep 17 00:00:00 2001 From: Christian Gick Date: Wed, 4 Feb 2026 21:02:12 +0200 Subject: [PATCH] fix: Fallback to cached session ID in session_note_add When session_id is not provided, falls back to getSessionId() which reads from CLAUDE_SESSION_ID env or ~/.cache/session-memory/current_session. Fixes NOT NULL constraint violation on session_notes.session_id. Co-Authored-By: Claude Opus 4.5 --- src/tools/crud.ts | 2 +- src/tools/session-docs.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/tools/crud.ts b/src/tools/crud.ts index 3198291..800b51e 100644 --- a/src/tools/crud.ts +++ b/src/tools/crud.ts @@ -14,7 +14,7 @@ import * as os from 'os'; /** * Get current session ID from environment or cache file */ -function getSessionId(): string { +export function getSessionId(): string { // Check environment first if (process.env.CLAUDE_SESSION_ID) { return process.env.CLAUDE_SESSION_ID; diff --git a/src/tools/session-docs.ts b/src/tools/session-docs.ts index 57f1817..da94656 100644 --- a/src/tools/session-docs.ts +++ b/src/tools/session-docs.ts @@ -3,6 +3,7 @@ import { query, queryOne, execute } from '../db.js'; import { getEmbedding, formatEmbedding } from '../embeddings.js'; +import { getSessionId } from './crud.js'; // ============================================================================ // SESSION NOTES @@ -32,7 +33,8 @@ interface SessionNote { * Auto-generates embedding for semantic search */ export async function sessionNoteAdd(args: SessionNoteAddArgs): Promise { - const { session_id, note_type, content } = args; + const { session_id: providedSessionId, note_type, content } = args; + const session_id = providedSessionId || getSessionId(); // Generate embedding for semantic search const embedding = await getEmbedding(content);