prevent engram corruption: idempotent boot seeding, session-start event cap
Fix 1: mem_boot_count_inc prunes all existing soul:boot_count nodes before
inserting the new one — keeps exactly one boot counter node instead
of accumulating a new node per boot. Also fixes a latent ordering
bug where engram_search_json oldest-first results caused the counter
to read stale (low) values once >3 copies accumulated.
Fix 3: handle_api_node_delete comment clarified — the no-verify exception
is correct for deletes (not a write path); read-back-verify is for
writes only.
Fix 4: emit_session_start_event prunes old session-start InternalStateEvent
nodes after each boot, keeping the 10 most recent and forgetting
older ones. Prevents unbounded accumulation of ~120+ copies.
This commit is contained in:
+6
-5
@@ -196,11 +196,12 @@ fn handle_api_node_create(body: String) -> String {
|
||||
fn handle_api_node_delete(body: String) -> String {
|
||||
let id: String = json_get(body, "id")
|
||||
if str_eq(id, "") { return api_err("id is required") }
|
||||
// engram_forget removes the node + its incident edges from the live graph. We do
|
||||
// NOT read-back-verify here: engram_get_node_json can return a STALE hit for a just-
|
||||
// removed id (the id->index map is not rebuilt on forget), which would produce a
|
||||
// false "delete_failed" even though the node is gone. The graph endpoints
|
||||
// (/api/graph/nodes) correctly reflect the removal, which is the source of truth.
|
||||
// engram_forget removes the node + its incident edges from the live graph.
|
||||
// Delete is NOT read-back-verified: engram_get_node_json can return a stale hit
|
||||
// for a just-forgotten id because the id→index map is not rebuilt on forget.
|
||||
// A stale hit would cause a false "delete_failed" on a successful deletion.
|
||||
// This exception is correct: read-back-verify guards WRITES; for deletes,
|
||||
// the graph endpoints (/api/graph/nodes) reflect the removal and are the source of truth.
|
||||
engram_forget(id)
|
||||
return "{\"ok\":true,\"id\":\"" + id + "\"}"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user