JuliusBrussee/caveman · error

open ccr

Error message

open ccr: %w

What it means

This error is returned by Store constructor Open() when ccr.Open(ccrPath) fails to open the underlying CCR (content-addressed memory) store after the memories db migration already succeeded. It indicates the auxiliary store backing the engine could not be created or opened; the memories db handle is closed and no Store is returned.

Solutions

  1. Inspect the wrapped %w cause to distinguish creation vs corruption issues.
  2. Ensure the parent directory of ccrPath exists and is writable by the process.
  3. If the ccr store is corrupt, back it up and remove it so it is recreated (memory content will need re-indexing).
  4. Check disk space and quotas.
  5. Run the process with the user that owns the data directory.

Example fix

// before
store, err := mem.Open("/var/lib/app/mem")
if err != nil { log.Fatal(err) }
// after
os.MkdirAll("/var/lib/app/mem", 0o755) // ensure writable home for ccr
store, err := mem.Open("/var/lib/app/mem")
if err != nil { log.Fatalf("open memory store: %v", err) }
Defensive patterns

Strategy: try-catch

Validate before calling

// Go: ensure the store parent directory exists and is writable
if err := os.MkdirAll(dataDir, 0o755); err != nil {
    return fmt.Errorf("cannot prepare memory dir: %w", err)
}
if f, err := os.CreateTemp(dataDir, ".wtest"); err != nil {
    return fmt.Errorf("memory dir not writable: %w", err)
} else { os.Remove(f.Name()); f.Close() }

Try / catch

store, err := mem.Open(dataDir)
if err != nil {
    if strings.Contains(err.Error(), "open ccr") {
        // inspect/repair the ccr store directory before retrying
    }
    return err
}

Prevention

When it happens

Trigger: Calling mem.Open when the ccrPath directory cannot be created or written, the ccr store is corrupt, or the underlying ccr.Open hits a filesystem/lock error.

Common situations: Read-only data directory, path pointing to a file instead of a directory, insufficient disk space, corrupted ccr store left by a previous crash, or conflicting permissions after a deployment change.

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

Appendix: source

Thrown at mem/store.go:136

		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 = cerr
	}
	return err
}

// Memory is one stored memory.
type Memory struct {
	ID           string  `json:"id"`
	Text         string  `json:"text"`
	CreatedAt    string  `json:"created_at"`

View on GitHub (pinned to 3ee70a1026)