{"record":{"id":"30dab7344e88b64c","repo":"JuliusBrussee/caveman","slug":"memory-s-is-not-current","errorCode":null,"errorMessage":"memory %s is not current","messagePattern":"memory (.+?) is not current","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mem/store.go","lineNumber":220,"sourceCode":"\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}\n\tif exists > 0 {\n\t\treturn Memory{}, fmt.Errorf(\"replacement memory %s already exists\", newID)\n\t}\n\tnow := time.Now().UTC().Format(time.RFC3339Nano)\n\tif _, err := tx.Exec(\n\t\t`INSERT INTO memories\n\t\t   (id, text, created_at, valid_from, supersedes)","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/mem/store.go#L202-L238","documentation":"Supersede looks up the target with `WHERE id = ? AND valid_until IS NULL`; when no current row matches (sql.ErrNoRows), it fails closed with 'memory %s is not current'. This covers both unknown ids and ids whose only versions are already expired/superseded, guaranteeing lineage is never corrupted.","triggerScenarios":"Calling Supersede with an id that was never stored, a typo'd/truncated id, an id whose memory was already superseded or expired, or an id from a different database file.","commonSituations":"Replaying a script a second time (the first run already superseded the id); using an id captured from an old Recalled snapshot that has since been replaced; environment mixups pointing at another store.","solutions":["Recall the current memories first and use a live id (valid_until IS NULL) as oldID.","Make supersede scripts idempotent: skip if the current text already equals newText, or handle 'is not current' as already-done.","Verify you are connected to the same store the id came from.","Check the id for typos/truncation against the value returned by Remember."],"exampleFix":"// before\n_, err := store.Supersede(oldID, newText) // fails if already superseded\n// after\n_, err := store.Supersede(oldID, newText)\nif err != nil && strings.Contains(err.Error(), \"is not current\") {\n    return nil // idempotent: already superseded\n}","handlingStrategy":"try-catch","validationCode":"// Go: confirm the id is still current via Recall before superseding\ncur, _ := store.Recall(oldID) // or your lookup helper\nif cur.ID != oldID || cur.ValidUntil != nil { skip }","typeGuard":null,"tryCatchPattern":"_, err := store.Supersede(oldID, newText)\nif err != nil && strings.Contains(err.Error(), \"is not current\") {\n    return nil // idempotent: unknown or already superseded\n}","preventionTips":["Fetch a fresh id via Recall rather than caching old snapshots","Write idempotent scripts that tolerate 'is not current'","Never truncate or reformat ids when storing them","Point all callers at the same store file to avoid cross-db ids"],"tags":["not-found","state-conflict","idempotency"],"backgroundTag":"record-not-found","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"}