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 <noreply@anthropic.com>
This commit is contained in:
Christian Gick
2026-01-18 10:37:50 +02:00
parent 2e2f0192d9
commit fe2b1a0423

View File

@@ -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<string> {
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}`;