From fe2b1a04236a7619cb082b4786f047efdaae8993 Mon Sep 17 00:00:00 2001 From: Christian Gick Date: Sun, 18 Jan 2026 10:37:50 +0200 Subject: [PATCH] fix: Remove redundant session_id validation in memoryAdd (CF-195) Problem: session_id validation added extra SELECT query before each memory insertion, causing session-start delays. Root cause: Foreign key constraint already enforces referential integrity (migrations/011_memories.sql:16-19). Validation was redundant. Solution: Remove validation (lines 50-59 in memories.ts). Let database handle referential integrity with proper error messages. Benefits: - Faster memoryAdd calls (one less query) - Proper error messages from PostgreSQL on constraint violations - No silent NULL conversion for invalid session_ids Co-Authored-By: Claude Sonnet 4.5 --- src/tools/memories.ts | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/tools/memories.ts b/src/tools/memories.ts index f1c069e..84930d0 100644 --- a/src/tools/memories.ts +++ b/src/tools/memories.ts @@ -45,18 +45,7 @@ interface MemoryListArgs { * Add a new memory/learning (enhanced with session_id and task_id) */ export async function memoryAdd(args: MemoryAddArgs): Promise { - let { category, title, content, context, project, session_id, task_id } = args; - - // Validate session_id exists if provided (graceful degradation) - if (session_id) { - const sessionExists = await queryOne<{ exists: boolean }>( - 'SELECT EXISTS(SELECT 1 FROM sessions WHERE id = $1)', - [session_id] - ); - if (!sessionExists?.exists) { - session_id = undefined; // Set to null if session doesn't exist - } - } + const { category, title, content, context, project, session_id, task_id } = args; // Generate embedding for semantic search const embedText = `${title}. ${content}`;