Skip to content

#1 Persistent memory for AI coding agents based on real-world benchmarks

Merge main into fix/semantic-memory-eviction

Rohit Ghumare8207502328e8
diff --cc src/functions/retention.ts
index 2da09f87,765b48be..3262c15d
--- a/src/functions/retention.ts
+++ b/src/functions/retention.ts
@@@ -216,38 -322,45 +322,53 @@@ export function registerRetentionFuncti
};
}
+ // Branch on source (#124). Pre-0.8.10 rows have no `source` field,
+ // and that includes semantic retention rows that were written by
+ // the old scorer — so we can't just default to episodic, that
+ // would silently no-op the delete and leave the stranded semantic
+ // memory alive (the exact bug #124 is about). When `source` is
+ // missing, probe both namespaces to find where the memoryId
+ // actually lives and route the delete there. After one re-score
+ // (mem::retention-score) every row will have the correct tag.
let evicted = 0;
+ let evictedEpisodic = 0;
+ let evictedSemantic = 0;
+ const evictedIds: string[] = [];
for (const candidate of candidates) {
try {
- let deletedScope: "semantic" | "episodic" | null = null;
-
- let scope: string;
- let resolvedSource: "episodic" | "semantic";
++ let scope: string | null = null;
++ let resolvedSource: "episodic" | "semantic" | null = null;
if (candidate.source === "semantic") {
- await kv.delete(KV.semantic, candidate.memoryId);
- deletedScope = "semantic";
+ scope = KV.semantic;
+ resolvedSource = "semantic";
} else if (candidate.source === "episodic") {
- await kv.delete(KV.memories, candidate.memoryId);
- deletedScope = "episodic";
+ scope = KV.memories;
+ resolvedSource = "episodic";
} else {
- const mem = await kv.get<Memory>(KV.memories, candidate.memoryId);
- if (mem) {
- await kv.delete(KV.memories, candidate.memoryId);
- deletedScope = "episodic";
+ const episodic = await kv.get(KV.memories, candidate.memoryId);
+ if (episodic !== null) {
+ scope = KV.memories;
+ resolvedSource = "episodic";
} else {
- const semMem = await kv.get<SemanticMemory>(KV.semantic, candidate.memoryId);
- if (semMem) {
- await kv.delete(KV.semantic, candidate.memoryId);
- deletedScope = "semantic";
- scope = KV.semantic;
- resolvedSource = "semantic";
++ const semantic = await kv.get(KV.semantic, candidate.memoryId);
++ if (semantic !== null) {
++ scope = KV.semantic;
++ resolvedSource = "semantic";
+ }
}
}
+
- if (deletedScope) {
- await recordAudit(kv, "delete", "mem::retention-evict", [candidate.memoryId], { scope: deletedScope });
++ if (!scope || !resolvedSource) {
++ continue;
+ }
+
+ await kv.delete(scope, candidate.memoryId);
await kv.delete(KV.retentionScores, candidate.memoryId);
+ await deleteAccessLog(kv, candidate.memoryId);
evicted++;
-
+ evictedIds.push(candidate.memoryId);
+ if (resolvedSource === "semantic") evictedSemantic++;
+ else evictedEpisodic++;
} catch {
continue;
}
diff --cc src/types.ts
index 27ba680d,883697ba..9a8fae99
--- a/src/types.ts
+++ b/src/types.ts
@@@ -435,39 -450,47 +450,46 @@@ export interface AuditEntry
id: string;
timestamp: string;
operation:
- | "observe"
- | "compress"
- | "remember"
- | "forget"
- | "evolve"
- | "consolidate"
- | "share"
- | "delete"
- | "import"
- | "export"
- | "action_create"
- | "action_update"
- | "lease_acquire"
- | "lease_release"
- | "routine_run"
- | "signal_send"
- | "checkpoint_resolve"
- | "mesh_sync"
- | "sentinel_create"
- | "sentinel_trigger"
- | "sketch_create"
- | "sketch_promote"
- | "sketch_discard"
- | "crystallize"
- | "diagnose"
- | "heal"
- | "facet_tag"
- | "lesson_save"
- | "lesson_recall"
- | "lesson_strengthen"
- | "obsidian_export"
- | "reflect"
- | "insight_search";
+ | "observe"
+ | "compress"
+ | "remember"
+ | "forget"
+ | "evolve"
+ | "consolidate"
+ | "share"
+ | "delete"
+ | "import"
+ | "export"
+ | "action_create"
+ | "action_update"
+ | "lease_acquire"
+ | "lease_release"
+ | "routine_run"
+ | "signal_send"
+ | "checkpoint_resolve"
+ | "mesh_sync"
+ | "relation_create"
+ | "relation_update"
+ | "sentinel_create"
+ | "sentinel_trigger"
+ | "sketch_create"
+ | "sketch_promote"
+ | "retention_score"
+ | "sketch_discard"
+ | "crystallize"
+ | "diagnose"
+ | "heal"
+ | "facet_tag"
+ | "lesson_save"
+ | "lesson_recall"
+ | "lesson_strengthen"
+ | "obsidian_export"
+ | "reflect"
+ | "insight_search"
+ | "skill_extract"
+ | "core_add"
+ | "core_remove"
- | "auto_page"
- | "relation_create";
++ | "auto_page";
userId?: string;
functionId: string;
targetIds: string[];