fix: Validate session_id exists before memory insert (CF-194)
- Added session existence check before INSERT - Graceful degradation: sets session_id to null if invalid - Prevents FK constraint violation - Memory still stored without session link
This commit is contained in:
@@ -45,7 +45,18 @@ interface MemoryListArgs {
|
||||
* Add a new memory/learning (enhanced with session_id and task_id)
|
||||
*/
|
||||
export async function memoryAdd(args: MemoryAddArgs): Promise<string> {
|
||||
const { category, title, content, context, project, session_id, task_id } = args;
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
// Generate embedding for semantic search
|
||||
const embedText = `${title}. ${content}`;
|
||||
|
||||
Reference in New Issue
Block a user