JuliusBrussee/caveman · error

memory exists only as an expired historical version and…

Error message

memory %s exists only as an expired historical version and cannot be re-remembered as current

What it means

Remember deliberately fails when the computed id exists only as an expired historical version (ValidUntil set). Reporting success would be false: the row is stored, but Recall permanently hides expired versions, so the caller would believe the memory is remembered when it is not recallable. This is a fail-closed design choice.

Solutions

  1. Change the text slightly (or use Supersede from the current memory instead of Remember) to create a new current version.
  2. If the old text should be current again, use Supersede on the current memory with this text rather than Remember.
  3. If replaying history, filter out texts whose ids map to expired versions before calling Remember.
  4. Treat the error as intentional: the memory exists in history but must not be reported as current.

Example fix

// before
_, err := store.Remember(oldText) // fails: expired historical version
// after
if err != nil && strings.Contains(err.Error(), "expired historical version") {
    // replace current memory with oldText instead
    _, err = store.Supersede(currentID, oldText)
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Go: detect an expired historical collision before remembering
// (requires tracking prior ids: id = memID(text); if knownExpired[text] { ... })

Try / catch

_, err := store.Remember(text)
if err != nil && strings.Contains(err.Error(), "expired historical version") {
    // route to Supersede on the current memory instead of failing
    _, err = store.Supersede(currentID, text)
}

Prevention

When it happens

Trigger: Calling Remember with text identical to a memory that was previously expired — via Supersede (old version), Forget/history repair, or an expiry process — so memID(text) collides with the expired row.

Common situations: Re-remembering an old text after it was superseded to something else; a sync/job replaying old memories that were since superseded; users re-entering previously retired notes verbatim.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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

Appendix: source

Thrown at mem/store.go:193

	// INSERT OR IGNORE keeps the original created_at on a repeat remember.
	// RetryOnBusy: under a fan-out of cavemem processes, a queued writer can
	// outlast a single busy_timeout (Windows file locking is the slowest case).
	if err := ccr.RetryOnBusy(func() error {
		_, e := s.db.Exec(
			`INSERT OR IGNORE INTO memories (id, text, created_at, valid_from) VALUES (?, ?, ?, ?)`,
			id, text, created, created,
		)
		return e
	}); err != nil {
		return Memory{}, fmt.Errorf("store memory: %w", err)
	}
	var stored Memory
	row := s.db.QueryRow(memorySelect+` WHERE id = ?`, id)
	if err := scanMemory(row, &stored); err != nil {
		return Memory{}, fmt.Errorf("read back memory: %w", err)
	}
	if stored.ValidUntil != nil {
		return Memory{}, fmt.Errorf("memory %s exists only as an expired historical version and cannot be re-remembered as current", stored.ID)
	}
	return stored, nil
}

// Supersede atomically replaces one current memory with a new current version.
// The old row remains durable for history and byte-exact audit, but normal recall
// excludes it. An already-expired or unknown id fails closed.
func (s *Store) Supersede(oldID, newText string) (Memory, error) {
	if strings.TrimSpace(oldID) == "" {
		return Memory{}, fmt.Errorf("supersede requires old memory id")
	}
	if strings.TrimSpace(newText) == "" {
		return Memory{}, fmt.Errorf("cannot supersede with empty text")
	}
	if err := validateMemorySize(newText); err != nil {
		return Memory{}, err
	}
	tx, err := s.db.Begin()

View on GitHub (pinned to 3ee70a1026)