JuliusBrussee/caveman · error
migrate memories db
Error message
migrate memories db: %w
What it means
Applying the memories DB schema (or the legacy schema migration) failed after SQLITE_BUSY retries. Both steps are idempotent and retried via RetryOnBusy, so this error means the migration genuinely failed (lock contention beyond retries, disk I/O error, or SQL error). The db handle is closed before returning.
Solutions
- Re-run when contention subsides; stagger process starts on cold start
- Check the wrapped error: SQL/disk errors may require repairing or removing mem.db (after backup)
- Ensure the volume is writable (WAL/journal needs write access alongside the db file)
- Reduce concurrent cold-start fan-out or increase busy timeout/retry budget
Example fix
// before: 50 processes starting at once on fresh mem.db // after: stagger or retry for i in 1 2 3; do cavemem remember ... && break; sleep 2; done
Defensive patterns
Strategy: retry
Try / catch
store, err := mem.Open(opts)
if err != nil && strings.Contains(err.Error(), "migrate memories db") {
// cold-start contention or db problem; back off and retry or inspect db
time.Sleep(2 * time.Second)
return mem.Open(opts)
} Prevention
- Stagger cold starts of many cavemem processes
- Ensure the db volume is writable (WAL/journal side files)
- Back up and repair/replace mem.db if corruption is indicated
- Rely on the built-in RetryOnBusy; add outer backoff for extreme fan-out
When it happens
Trigger: db.Exec(memSchema) or migrateMemorySchema fails and keeps failing through RetryOnBusy — heavy multi-process contention outlasting retries, corrupted db file, or disk errors.
Common situations: Many cavemem processes starting simultaneously against a fresh mem.db; a corrupted or partially-written mem.db; read-only volume where WAL/journal files cannot be created.
Related errors
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/c4a350161f95304d.
Report an issue: GitHub.
Appendix: source
Thrown at mem/store.go:127
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)
}
return &Store{db: db, eng: engine.New(store, nil), ccr: store}, nil
}
// Close releases the databases.
func (s *Store) Close() error {
err := s.db.Close()
if cerr := s.ccr.Close(); cerr != nil && err == nil {
err = cerrView on GitHub (pinned to 3ee70a1026)