{"record":{"id":"308c506f3073a649","repo":"JuliusBrussee/caveman","slug":"read-forgotten-memory-w","errorCode":null,"errorMessage":"read forgotten memory: %w","messagePattern":"read forgotten memory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mem/store.go","lineNumber":338,"sourceCode":"\n// Forget deletes a memory by id and atomically repairs neighboring lineage\n// pointers. Expired predecessors stay expired: deleting a current version means\n// forgetting that fact, never silently resurrecting an older one.\nfunc (s *Store) Forget(id string) (bool, error) {\n\ttx, err := s.db.Begin()\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"forget begin: %w\", err)\n\t}\n\tdefer tx.Rollback()\n\n\tvar supersedes, supersededBy sql.NullString\n\tif err := tx.QueryRow(\n\t\t`SELECT supersedes, superseded_by FROM memories WHERE id = ?`, id,\n\t).Scan(&supersedes, &supersededBy); err != nil {\n\t\tif err == sql.ErrNoRows {\n\t\t\treturn false, nil\n\t\t}\n\t\treturn false, fmt.Errorf(\"read forgotten memory: %w\", err)\n\t}\n\tif supersedes.Valid {\n\t\tif _, err := tx.Exec(\n\t\t\t`UPDATE memories SET superseded_by = ? WHERE id = ?`,\n\t\t\tnullableLineageID(supersededBy), supersedes.String,\n\t\t); err != nil {\n\t\t\treturn false, fmt.Errorf(\"repair forgotten predecessor: %w\", err)\n\t\t}\n\t}\n\tif supersededBy.Valid {\n\t\tif _, err := tx.Exec(\n\t\t\t`UPDATE memories SET supersedes = ? WHERE id = ?`,\n\t\t\tnullableLineageID(supersedes), supersededBy.String,\n\t\t); err != nil {\n\t\t\treturn false, fmt.Errorf(\"repair forgotten successor: %w\", err)\n\t\t}\n\t}\n\tif _, err := tx.Exec(`DELETE FROM memories WHERE id = ?`, id); err != nil {","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/mem/store.go#L320-L356","documentation":"Forget() first reads the target row's supersedes/superseded_by lineage inside its transaction. sql.ErrNoRows is handled as a normal not-found (returns false, nil); any other scan/query failure is wrapped as this error. It indicates the SELECT itself failed — I/O error, corrupted page, or an incompatible/corrupt schema rather than a missing row.","triggerScenarios":"Calling Forget(id) when the memories table is unreadable: database file corruption, a schema mismatch from an unrelated DB file passed as the store path, disk I/O errors, or the connection dying mid-query.","commonSituations":"Pointing cavemem at a non-cavemem SQLite file, a truncated DB after a crash or power loss, read-only filesystem with an unexpected driver behavior, or copying the DB file while a writer was active.","solutions":["Verify the path points to a real cavemem store: `sqlite3 <db> \".schema memories\"` — if the table is missing or malformed, you have the wrong or a corrupt file.","Run integrity check: `sqlite3 <db> \"PRAGMA integrity_check;\"`; if it reports corruption, restore from backup or rebuild the store.","Check disk health/space and filesystem errors (`df -h`, `dmesg`) and retry after fixing.","If the file was copied while in use, stop all writers and take a consistent copy (or use sqlite3's .backup) before reopening."],"exampleFix":"// before: wrong file passed as store\ns, _ := mem.Open(\"./notes.db\")\n// after: ensure it is the cavemem store\nsqlite3 notes.db \".schema memories\"   // verify table exists\ns, _ := mem.Open(\"/data/cavemem.db\")","handlingStrategy":"validation","validationCode":"// Go: confirm the file is a cavemem store before opening/forgetting\nfunc isCavememStore(path string) error {\n\tdb, err := sql.Open(\"sqlite\", path)\n\tif err != nil { return err }\n\tdefer db.Close()\n\tvar n int\n\tif err := db.QueryRow(`SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='memories'`).Scan(&n); err != nil {\n\t\treturn fmt.Errorf(\"not a cavemem store: %w\", err)\n\t}\n\tif n != 1 { return fmt.Errorf(\"memories table missing: %s\", path) }\n\treturn nil\n}","typeGuard":"null","tryCatchPattern":"ok, err := store.Forget(id)\nif err != nil && strings.Contains(err.Error(), \"read forgotten memory\") {\n\tif strings.Contains(err.Error(), \"no such table\") {\n\t\treturn fmt.Errorf(\"wrong or corrupt store file; verify path and schema\")\n\t}\n\t// other scan failures: suggest PRAGMA integrity_check and backup restore\n\treturn err\n}","preventionTips":["Verify the path passed to the store constructor is the real cavemem DB (check `.schema memories`).","Never copy or move the DB file while writers are active; use sqlite3's .backup or VACUUM INTO.","Schedule `PRAGMA integrity_check;` and keep backups for restore after disk failures.","Guard against power-loss corruption with journal_mode=WAL and a UPSD/fsync-safe storage volume."],"tags":["sqlite","corruption","schema","forget"],"backgroundTag":"database-query-failed","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}