JuliusBrussee/caveman · error

replacement text is identical to current memory

Error message

replacement text is identical to current memory

What it means

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.

Solutions

  1. Compare the new text with the current memory first (Remember/History/Recall) and skip the call when unchanged.
  2. If nothing actually changed, treat the operation as already complete rather than an error.
  3. If a change was intended, edit the text before superseding.

Example fix

// before
_, err := store.Supersede(id, newText)
// after
cur, err := store.Recall(id)
if err != nil { return err }
if cur.Text == newText {
	return nil // nothing to change
}
_, err = store.Supersede(id, newText)
Defensive patterns

Strategy: validation

Validate before calling

cur, err := store.Recall(id)
if err != nil { return err }
if cur.Text == newText { return nil }

Try / catch

if _, err := store.Supersede(id, newText); err != nil {
	if strings.Contains(err.Error(), "identical to current") {
		return nil // treat as no-op
	}
	return err
}

Prevention

When it happens

Trigger: 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'.

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/2b26d0cc8bf35afa. Report an issue: GitHub.

Appendix: source

Thrown at mem/store.go:225

	}
	if err := validateMemorySize(newText); err != nil {
		return Memory{}, err
	}
	tx, err := s.db.Begin()
	if err != nil {
		return Memory{}, fmt.Errorf("supersede begin: %w", err)
	}
	defer tx.Rollback()

	var old Memory
	if err := scanMemory(tx.QueryRow(memorySelect+` WHERE id = ? AND valid_until IS NULL`, oldID), &old); err != nil {
		if err == sql.ErrNoRows {
			return Memory{}, fmt.Errorf("memory %s is not current", oldID)
		}
		return Memory{}, fmt.Errorf("read current memory: %w", err)
	}
	if old.Text == newText {
		return Memory{}, fmt.Errorf("replacement text is identical to current memory")
	}
	newID := memID(newText)
	var exists int
	if err := tx.QueryRow(`SELECT COUNT(*) FROM memories WHERE id = ?`, newID).Scan(&exists); err != nil {
		return Memory{}, fmt.Errorf("check replacement memory: %w", err)
	}
	if exists > 0 {
		return Memory{}, fmt.Errorf("replacement memory %s already exists", newID)
	}
	now := time.Now().UTC().Format(time.RFC3339Nano)
	if _, err := tx.Exec(
		`INSERT INTO memories
		   (id, text, created_at, valid_from, supersedes)
		 VALUES (?, ?, ?, ?, ?)`,
		newID, newText, now, now, oldID,
	); err != nil {
		return Memory{}, fmt.Errorf("insert replacement memory: %w", err)
	}

View on GitHub (pinned to 3ee70a1026)