JuliusBrussee/caveman · error

secure memories db

Error message

secure memories db: %w

What it means

Before opening the SQLite memories database, Open canonicalizes/prepares the path via ccr.PrepareSQLitePathCanonical (which applies security/POSIX path handling). Failure here is reported as 'secure memories db'. It means the mem.db path could not be safely prepared, typically due to path resolution problems.

Solutions

  1. Check the wrapped error to see which path failed canonicalization
  2. Use a simple absolute path without symlinks for the store directory
  3. Verify the path exists with expected permissions and is a regular location
  4. Update/verify the ccr path-preparation helper supports your platform

Example fix

// before
mem.Open(mem.Options{Dir: "~/data/../link/cavemem"})
// after
mem.Open(mem.Options{Dir: "/var/lib/cavemem"})
Defensive patterns

Strategy: validation

Validate before calling

path := filepath.Join(dir, "mem.db")
resolved, err := filepath.EvalSymlinks(filepath.Dir(path))
if err != nil || resolved == "" { /* fix dir before Open */ }

Try / catch

store, err := mem.Open(opts)
if err != nil && strings.Contains(err.Error(), "secure memories db") {
  // path preparation failed: simplify/fix the dir path
  return err
}

Prevention

When it happens

Trigger: PrepareSQLitePathCanonical fails on the computed memPath — e.g. invalid or non-canonicalizable path, symlink or path resolution errors, or platform-specific path issues.

Common situations: opts.Dir containing symlinks or irregular path components on strict platforms; running on an unsupported/locked-down filesystem; relative paths resolving oddly under different working directories.

Understand the failure class

Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.

Related errors


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

Appendix: source

Thrown at mem/store.go:109

}

// Open opens (creating if needed) a cavemem store.
func Open(opts Options) (*Store, error) {
	memPath, ccrPath := ":memory:", ":memory:"
	if !opts.InMemory {
		dir := opts.Dir
		if dir == "" {
			dir = defaultDir()
		}
		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)

View on GitHub (pinned to 3ee70a1026)