{"record":{"id":"82c16c0fa38164bb","repo":"JuliusBrussee/caveman","slug":"broken-supersession-history-at-s-w","errorCode":null,"errorMessage":"broken supersession history at %s: %w","messagePattern":"broken supersession history at (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mem/store.go","lineNumber":291,"sourceCode":"}\n\n// History returns the complete oldest-to-newest supersession chain containing\n// id. Broken/cyclic lineage is rejected rather than returning partial history.\nfunc (s *Store) History(id string) ([]Memory, error) {\n\tif strings.TrimSpace(id) == \"\" {\n\t\treturn nil, fmt.Errorf(\"history requires memory id\")\n\t}\n\tcurrent, err := s.memoryByID(id)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tseen := map[string]bool{current.ID: true}\n\tvar before []Memory\n\tcursor := current\n\tfor cursor.Supersedes != \"\" {\n\t\tprev, err := s.memoryByID(cursor.Supersedes)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"broken supersession history at %s: %w\", cursor.ID, err)\n\t\t}\n\t\tif seen[prev.ID] {\n\t\t\treturn nil, fmt.Errorf(\"cyclic supersession history at %s\", prev.ID)\n\t\t}\n\t\tseen[prev.ID] = true\n\t\tbefore = append(before, prev)\n\t\tcursor = prev\n\t}\n\thistory := make([]Memory, 0, len(before)+1)\n\tfor i := len(before) - 1; i >= 0; i-- {\n\t\thistory = append(history, before[i])\n\t}\n\thistory = append(history, current)\n\tcursor = current\n\tfor cursor.SupersededBy != \"\" {\n\t\tnext, err := s.memoryByID(cursor.SupersededBy)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"broken supersession history at %s: %w\", cursor.ID, err)","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/766dce6b1394ebb56a3090748d5a0240a5aefb36/mem/store.go#L273-L309","documentation":"While walking the supersession chain backwards, the predecessor id pointed at a row that could not be read (missing or unreadable). History refuses to return partial lineage, since a broken chain would misrepresent audit history.","triggerScenarios":"Thrown at mem/store.go:291 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the named memory id and its Supersedes pointer in the db","Repair or Forget the broken chain entries","Restore from backup if lineage rows were deleted"],"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"}