JuliusBrussee/caveman · error

open memories db

Error message

open memories db: %w

What it means

sql.Open for the SQLite memories database failed. With modern drivers sql.Open rarely fails unless the driver name is unregistered or the DSN is malformed. The wrapped error names the cause. The store cannot proceed without a DB handle.

Solutions

  1. Ensure the sqlite driver is imported (blank import of the driver package) in the binary
  2. Inspect ccr.SQLiteDSN output for malformed DSN parameters
  3. Verify the canonical mem.db path is valid
  4. Rebuild with the driver dependency included if using a trimmed module

Example fix

// before: missing driver import
import _ "modernc.org/sqlite" // ensure registered
// after
import (
    _ "modernc.org/sqlite"
)
Defensive patterns

Strategy: try-catch

Try / catch

store, err := mem.Open(opts)
if err != nil && strings.Contains(err.Error(), "open memories db") {
  // driver/DSN problem: verify sqlite driver import and DSN
  return err
}

Prevention

When it happens

Trigger: sql.Open("sqlite", ccr.SQLiteDSN(canonicalMemPath)) fails — driver not registered (blank import missing) or the constructed DSN is invalid.

Common situations: Forgetting the pure-Go sqlite driver import in a custom binary; a bad canonical path producing a malformed DSN; build-tag variations excluding the driver.

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/ce101370e74310ce. Report an issue: GitHub.

Appendix: source

Thrown at mem/store.go:118

		}
		if err := os.MkdirAll(dir, 0o700); err != nil {
			return nil, fmt.Errorf("create %s: %w", dir, err)
		}
		memPath = filepath.Join(dir, "mem.db")
		ccrPath = filepath.Join(dir, "ccr.db")
	}
	canonicalMemPath, err := ccr.PrepareSQLitePathCanonical(memPath)
	if err != nil {
		return nil, fmt.Errorf("secure memories db: %w", err)
	}
	// Same embedded-SQLite-behind-a-multi-process-CLI discipline as the recovery
	// store: a single writer connection plus busy_timeout(5000)+WAL. Several
	// cavemem processes (and the MCP server) share one mem.db, and the JS client
	// fires Promise.all(facts.map(remember)); without this, concurrent writes
	// returned SQLITE_BUSY and were silently dropped. See ccr.SQLiteDSN.
	db, err := sql.Open("sqlite", ccr.SQLiteDSN(canonicalMemPath))
	if err != nil {
		return nil, fmt.Errorf("open memories db: %w", err)
	}
	db.SetMaxOpenConns(1)
	db.SetMaxIdleConns(1)
	// The cold-start migration is multi-statement DDL; under a fan-out of fresh
	// processes it can outlast a single busy_timeout, so retry it on SQLITE_BUSY
	// (runtime writes rely on busy_timeout alone). Both steps are idempotent.
	if err := ccr.RetryOnBusy(func() error { _, e := db.Exec(memSchema); return e }); err != nil {
		_ = db.Close()
		return nil, fmt.Errorf("migrate memories db: %w", err)
	}
	if err := ccr.RetryOnBusy(func() error { return migrateMemorySchema(db) }); err != nil {
		_ = db.Close()
		return nil, fmt.Errorf("migrate memories db: %w", err)
	}
	store, err := ccr.Open(ccrPath)
	if err != nil {
		_ = db.Close()
		return nil, fmt.Errorf("open ccr: %w", err)

View on GitHub (pinned to 3ee70a1026)