Added validation to check if session_id exists in sessions table before inserting memories. Falls back to NULL if session not found, preventing foreign key constraint violations while preserving memory content. Logs warning when invalid session_id provided for debugging. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>