{"record":{"id":"ff7b2748813654ce","repo":"JuliusBrussee/caveman","slug":"supersede-begin-w","errorCode":null,"errorMessage":"supersede begin: %w","messagePattern":"supersede begin: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mem/store.go","lineNumber":213,"sourceCode":"\treturn stored, nil\n}\n\n// Supersede atomically replaces one current memory with a new current version.\n// The old row remains durable for history and byte-exact audit, but normal recall\n// excludes it. An already-expired or unknown id fails closed.\nfunc (s *Store) Supersede(oldID, newText string) (Memory, error) {\n\tif strings.TrimSpace(oldID) == \"\" {\n\t\treturn Memory{}, fmt.Errorf(\"supersede requires old memory id\")\n\t}\n\tif strings.TrimSpace(newText) == \"\" {\n\t\treturn Memory{}, fmt.Errorf(\"cannot supersede with empty text\")\n\t}\n\tif err := validateMemorySize(newText); err != nil {\n\t\treturn Memory{}, err\n\t}\n\ttx, err := s.db.Begin()\n\tif err != nil {\n\t\treturn Memory{}, fmt.Errorf(\"supersede begin: %w\", err)\n\t}\n\tdefer tx.Rollback()\n\n\tvar old Memory\n\tif err := scanMemory(tx.QueryRow(memorySelect+` WHERE id = ? AND valid_until IS NULL`, oldID), &old); err != nil {\n\t\tif err == sql.ErrNoRows {\n\t\t\treturn Memory{}, fmt.Errorf(\"memory %s is not current\", oldID)\n\t\t}\n\t\treturn Memory{}, fmt.Errorf(\"read current memory: %w\", err)\n\t}\n\tif old.Text == newText {\n\t\treturn Memory{}, fmt.Errorf(\"replacement text is identical to current memory\")\n\t}\n\tnewID := memID(newText)\n\tvar exists int\n\tif err := tx.QueryRow(`SELECT COUNT(*) FROM memories WHERE id = ?`, newID).Scan(&exists); err != nil {\n\t\treturn Memory{}, fmt.Errorf(\"check replacement memory: %w\", err)\n\t}","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/766dce6b1394ebb56a3090748d5a0240a5aefb36/mem/store.go#L195-L231","documentation":"The SQLite transaction that implements atomic supersession could not be started (db.Begin failed). The wrapped error is the underlying database failure; no memory state was modified.","triggerScenarios":"Thrown at mem/store.go:213 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry the supersede","Check mem.db is writable and not exclusively locked","Inspect the wrapped driver error"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"766dce6b1394ebb56a3090748d5a0240a5aefb36","analyzedAt":"2026-08-18T03:14:35.516Z","contentChangedAt":"2026-08-18T03:14:35.516Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}