JuliusBrussee/caveman · error

read forgotten memory

Error message

read forgotten memory: %w

What it means

Forget() first reads the target row's supersedes/superseded_by lineage inside its transaction. sql.ErrNoRows is handled as a normal not-found (returns false, nil); any other scan/query failure is wrapped as this error. It indicates the SELECT itself failed — I/O error, corrupted page, or an incompatible/corrupt schema rather than a missing row.

Solutions

  1. Verify the path points to a real cavemem store: `sqlite3 <db> ".schema memories"` — if the table is missing or malformed, you have the wrong or a corrupt file.
  2. Run integrity check: `sqlite3 <db> "PRAGMA integrity_check;"`; if it reports corruption, restore from backup or rebuild the store.
  3. Check disk health/space and filesystem errors (`df -h`, `dmesg`) and retry after fixing.
  4. If the file was copied while in use, stop all writers and take a consistent copy (or use sqlite3's .backup) before reopening.

Example fix

// before: wrong file passed as store
s, _ := mem.Open("./notes.db")
// after: ensure it is the cavemem store
sqlite3 notes.db ".schema memories"   // verify table exists
s, _ := mem.Open("/data/cavemem.db")
Defensive patterns

Strategy: validation

Validate before calling

// Go: confirm the file is a cavemem store before opening/forgetting
func isCavememStore(path string) error {
	db, err := sql.Open("sqlite", path)
	if err != nil { return err }
	defer db.Close()
	var n int
	if err := db.QueryRow(`SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='memories'`).Scan(&n); err != nil {
		return fmt.Errorf("not a cavemem store: %w", err)
	}
	if n != 1 { return fmt.Errorf("memories table missing: %s", path) }
	return nil
}

Type guard

null

Try / catch

ok, err := store.Forget(id)
if err != nil && strings.Contains(err.Error(), "read forgotten memory") {
	if strings.Contains(err.Error(), "no such table") {
		return fmt.Errorf("wrong or corrupt store file; verify path and schema")
	}
	// other scan failures: suggest PRAGMA integrity_check and backup restore
	return err
}

Prevention

When it happens

Trigger: Calling Forget(id) when the memories table is unreadable: database file corruption, a schema mismatch from an unrelated DB file passed as the store path, disk I/O errors, or the connection dying mid-query.

Common situations: Pointing cavemem at a non-cavemem SQLite file, a truncated DB after a crash or power loss, read-only filesystem with an unexpected driver behavior, or copying the DB file while a writer was active.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


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

Appendix: source

Thrown at mem/store.go:338

// Forget deletes a memory by id and atomically repairs neighboring lineage
// pointers. Expired predecessors stay expired: deleting a current version means
// forgetting that fact, never silently resurrecting an older one.
func (s *Store) Forget(id string) (bool, error) {
	tx, err := s.db.Begin()
	if err != nil {
		return false, fmt.Errorf("forget begin: %w", err)
	}
	defer tx.Rollback()

	var supersedes, supersededBy sql.NullString
	if err := tx.QueryRow(
		`SELECT supersedes, superseded_by FROM memories WHERE id = ?`, id,
	).Scan(&supersedes, &supersededBy); err != nil {
		if err == sql.ErrNoRows {
			return false, nil
		}
		return false, fmt.Errorf("read forgotten memory: %w", err)
	}
	if supersedes.Valid {
		if _, err := tx.Exec(
			`UPDATE memories SET superseded_by = ? WHERE id = ?`,
			nullableLineageID(supersededBy), supersedes.String,
		); err != nil {
			return false, fmt.Errorf("repair forgotten predecessor: %w", err)
		}
	}
	if supersededBy.Valid {
		if _, err := tx.Exec(
			`UPDATE memories SET supersedes = ? WHERE id = ?`,
			nullableLineageID(supersedes), supersededBy.String,
		); err != nil {
			return false, fmt.Errorf("repair forgotten successor: %w", err)
		}
	}
	if _, err := tx.Exec(`DELETE FROM memories WHERE id = ?`, id); err != nil {

View on GitHub (pinned to 3ee70a1026)