{"record":{"id":"ada75b10f6787fec","repo":"JuliusBrussee/caveman","slug":"supersede-requires-old-memory-id","errorCode":null,"errorMessage":"supersede requires old memory id","messagePattern":"supersede requires old memory id","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"mem/store.go","lineNumber":203,"sourceCode":"\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()\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}","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/mem/store.go#L185-L221","documentation":"Supersede requires the id of the current memory to replace. An empty/whitespace-only oldID is rejected up front because no target can be identified, and proceeding would either corrupt lineage or fail confusingly later in the transaction.","triggerScenarios":"Calling Store.Supersede(\"\", newText), passing an unset variable/flag as oldID (e.g. cmdSupersede with a missing id argument), or a caller that never captured the id returned by Remember.","commonSituations":"CLI `mem supersede \"\" new text`, scripting where the id variable was never assigned, or copying code that dropped the id parameter.","solutions":["Pass the exact id returned by a previous Remember/Recall call as oldID.","Check CLI argument order/flags so the id argument is actually populated.","Trim whitespace from your input before calling if it may be padded.","Look up the current memory via Recall to obtain its id first."],"exampleFix":"// before\nmem, err := store.Supersede(id, newText) // id == \"\"\n// after\nif strings.TrimSpace(id) == \"\" {\n    return fmt.Errorf(\"need the id of the memory to replace\")\n}\nmem, err := store.Supersede(id, newText)","handlingStrategy":"validation","validationCode":"// Go\nfunc validID(id string) bool { return strings.TrimSpace(id) != \"\" }","typeGuard":null,"tryCatchPattern":"if strings.TrimSpace(oldID) == \"\" { return fmt.Errorf(\"old memory id required\") }\nm, err := store.Supersede(oldID, newText)\nif err != nil { return err }","preventionTips":["Always carry the id from Remember/Recall into Supersede","Validate CLI flags so the id argument cannot be empty","Trim user-supplied ids before calling","Fail fast in scripts when the id variable is unset (set -u)"],"tags":["validation","argument","missing-value"],"backgroundTag":"missing-required-argument","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"}