{"record":{"id":"68fd86489f43d4f7","repo":"JuliusBrussee/caveman","slug":"memory-s-exists-only-as-an-expired-historical-ver","errorCode":null,"errorMessage":"memory %s exists only as an expired historical version and cannot be re-remembered as current","messagePattern":"memory (.+?) exists only as an expired historical version and cannot be re-remembered as current","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mem/store.go","lineNumber":193,"sourceCode":"\t// INSERT OR IGNORE keeps the original created_at on a repeat remember.\n\t// RetryOnBusy: under a fan-out of cavemem processes, a queued writer can\n\t// outlast a single busy_timeout (Windows file locking is the slowest case).\n\tif err := ccr.RetryOnBusy(func() error {\n\t\t_, e := s.db.Exec(\n\t\t\t`INSERT OR IGNORE INTO memories (id, text, created_at, valid_from) VALUES (?, ?, ?, ?)`,\n\t\t\tid, text, created, created,\n\t\t)\n\t\treturn e\n\t}); err != nil {\n\t\treturn Memory{}, fmt.Errorf(\"store memory: %w\", err)\n\t}\n\tvar stored Memory\n\trow := s.db.QueryRow(memorySelect+` WHERE id = ?`, id)\n\tif err := scanMemory(row, &stored); err != nil {\n\t\treturn Memory{}, fmt.Errorf(\"read back memory: %w\", err)\n\t}\n\tif stored.ValidUntil != nil {\n\t\treturn Memory{}, fmt.Errorf(\"memory %s exists only as an expired historical version and cannot be re-remembered as current\", stored.ID)\n\t}\n\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()","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/mem/store.go#L175-L211","documentation":"Remember deliberately fails when the computed id exists only as an expired historical version (ValidUntil set). Reporting success would be false: the row is stored, but Recall permanently hides expired versions, so the caller would believe the memory is remembered when it is not recallable. This is a fail-closed design choice.","triggerScenarios":"Calling Remember with text identical to a memory that was previously expired — via Supersede (old version), Forget/history repair, or an expiry process — so memID(text) collides with the expired row.","commonSituations":"Re-remembering an old text after it was superseded to something else; a sync/job replaying old memories that were since superseded; users re-entering previously retired notes verbatim.","solutions":["Change the text slightly (or use Supersede from the current memory instead of Remember) to create a new current version.","If the old text should be current again, use Supersede on the current memory with this text rather than Remember.","If replaying history, filter out texts whose ids map to expired versions before calling Remember.","Treat the error as intentional: the memory exists in history but must not be reported as current."],"exampleFix":"// before\n_, err := store.Remember(oldText) // fails: expired historical version\n// after\nif err != nil && strings.Contains(err.Error(), \"expired historical version\") {\n    // replace current memory with oldText instead\n    _, err = store.Supersede(currentID, oldText)\n}","handlingStrategy":"try-catch","validationCode":"// Go: detect an expired historical collision before remembering\n// (requires tracking prior ids: id = memID(text); if knownExpired[text] { ... })","typeGuard":null,"tryCatchPattern":"_, err := store.Remember(text)\nif err != nil && strings.Contains(err.Error(), \"expired historical version\") {\n    // route to Supersede on the current memory instead of failing\n    _, err = store.Supersede(currentID, text)\n}","preventionTips":["Never re-remember previously superseded/expired texts verbatim","Use Supersede to change a current memory rather than delete+Remember","Filter replayed histories against expired ids before import","Treat this error as intentional fail-closed behavior, not a bug"],"tags":["state-conflict","expired","idempotency"],"backgroundTag":"invalid-state-transition","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"}