{"record":{"id":"9d8f083a44377041","repo":"JuliusBrussee/caveman","slug":"history-requires-memory-id","errorCode":null,"errorMessage":"history requires memory id","messagePattern":"history requires memory id","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mem/store.go","lineNumber":279,"sourceCode":"\t\tText:       newText,\n\t\tCreatedAt:  now,\n\t\tValidFrom:  now,\n\t\tSupersedes: oldID,\n\t}, nil\n}\n\nfunc validateMemorySize(text string) error {\n\tif len(text) > MaxMemoryBytes {\n\t\treturn fmt.Errorf(\"%w: memory is %d bytes, over the %d-byte cap\", ErrMemoryTooLarge, len(text), MaxMemoryBytes)\n\t}\n\treturn nil\n}\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)","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/mem/store.go#L261-L297","documentation":"History rejects an empty or whitespace-only memory ID because lineage cannot be looked up without one. The store requires a non-blank id before querying the memories table, failing fast with this message instead of issuing a doomed lookup.","triggerScenarios":"Calling Store.History(\"\") or Store.History(\"   \") — typically when an upstream variable (CLI flag, struct field, parsed ID) was never populated.","commonSituations":"A CLI invocation missing the --id flag so an empty string is passed through; a caller splitting an output string that yielded an empty ID; uninitialized struct field before calling History.","solutions":["Pass the actual memory ID returned by a previous Remember/Supersede call.","Validate/trim the ID at the call site and return a clear user-facing message when blank.","For CLI usage, require the id argument/flag up front (flag wiring or cobra Args validation)."],"exampleFix":"// before\nchain, err := store.History(flagID) // flagID may be \"\"\n// after\nflagID = strings.TrimSpace(flagID)\nif flagID == \"\" {\n\treturn fmt.Errorf(\"--id is required for history\")\n}\nchain, err := store.History(flagID)","handlingStrategy":"validation","validationCode":"id = strings.TrimSpace(id)\nif id == \"\" { return fmt.Errorf(\"memory id required\") }","typeGuard":null,"tryCatchPattern":"chain, err := store.History(id)\nif err != nil && strings.Contains(err.Error(), \"requires memory id\") {\n\treturn fmt.Errorf(\"provide a memory id (from remember/supersede output)\")\n}","preventionTips":["Require the id flag/argument at the CLI or API boundary","Trim and check IDs before any store call","Keep the ID returned by Remember/Supersede with the resource that needs it"],"tags":["validation","empty-argument","lineage"],"backgroundTag":"empty-required-field","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"}