{"record":{"id":"2b26d0cc8bf35afa","repo":"JuliusBrussee/caveman","slug":"replacement-text-is-identical-to-current-memory","errorCode":null,"errorMessage":"replacement text is identical to current memory","messagePattern":"replacement text is identical to current memory","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mem/store.go","lineNumber":225,"sourceCode":"\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)\n\t\t VALUES (?, ?, ?, ?, ?)`,\n\t\tnewID, newText, now, now, oldID,\n\t); err != nil {\n\t\treturn Memory{}, fmt.Errorf(\"insert replacement memory: %w\", err)\n\t}","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/mem/store.go#L207-L243","documentation":"Supersede rejects the call when the replacement text is byte-identical to the current memory's text. A supersede that produced the same content would create a no-op lineage entry, so the store treats it as a caller mistake and aborts before writing anything.","triggerScenarios":"Calling Store.Supersede(oldID, newText) where memID(newText) equals the text stored on the current version of oldID — i.e. the user submits the same text as a 'replacement'.","commonSituations":"A CLI user re-runs `supersede <id> <same text>` (idempotent retry of an earlier successful command); an editor/automation echoes existing content back; a form resubmits unchanged text.","solutions":["Compare the new text with the current memory first (Remember/History/Recall) and skip the call when unchanged.","If nothing actually changed, treat the operation as already complete rather than an error.","If a change was intended, edit the text before superseding."],"exampleFix":"// before\n_, err := store.Supersede(id, newText)\n// after\ncur, err := store.Recall(id)\nif err != nil { return err }\nif cur.Text == newText {\n\treturn nil // nothing to change\n}\n_, err = store.Supersede(id, newText)","handlingStrategy":"validation","validationCode":"cur, err := store.Recall(id)\nif err != nil { return err }\nif cur.Text == newText { return nil }","typeGuard":null,"tryCatchPattern":"if _, err := store.Supersede(id, newText); err != nil {\n\tif strings.Contains(err.Error(), \"identical to current\") {\n\t\treturn nil // treat as no-op\n\t}\n\treturn err\n}","preventionTips":["Compare new text against current memory before superseding","Design CLI/automation flows to be idempotent on unchanged input","Avoid echoing existing content back as a replacement"],"tags":["validation","duplicate","idempotency"],"backgroundTag":"invalid-argument-value","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"}