fix(sf): drop embedding row when memory is superseded

supersedeMemory soft-deleted via superseded_by but left the
memory_embeddings row in place. loadAllEmbeddings already filters
by superseded_by IS NULL, so the orphaned row is harmless functionally
— but it wastes storage, complicates manual SQL audits, and is
inconsistent with updateMemoryContent (which already invalidates the
embedding via 7bec2dc2d).

Best-effort delete; supersede still succeeds even if the embedding
delete raises. Symmetric with the update path.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Mikael Hugo 2026-05-02 23:21:57 +02:00
parent aa60821ec3
commit 1b71ddd178

View file

@ -343,12 +343,22 @@ export function reinforceMemory(id: string): boolean {
/**
* Mark a memory as superseded by another.
*
* Drops the superseded memory's embedding row too: loadAllEmbeddings()
* already filters by superseded_by IS NULL, so the row was dead weight
* keeping it would just waste storage and confuse manual SQL audits.
* Best-effort: a missing/failed delete doesn't block the supersede.
*/
export function supersedeMemory(oldId: string, newId: string): boolean {
if (!isDbAvailable()) return false;
try {
supersedeMemoryRow(oldId, newId, new Date().toISOString());
try {
deleteMemoryEmbedding(oldId);
} catch {
// Orphaned embedding rows are harmless; supersede still succeeded.
}
return true;
} catch {
return false;