{"record":{"id":"3148c53f1ae4cadc","repo":"JuliusBrussee/caveman","slug":"open-ccr-w","errorCode":null,"errorMessage":"open ccr: %w","messagePattern":"open ccr: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mem/store.go","lineNumber":136,"sourceCode":"\t\treturn nil, fmt.Errorf(\"open memories db: %w\", err)\n\t}\n\tdb.SetMaxOpenConns(1)\n\tdb.SetMaxIdleConns(1)\n\t// The cold-start migration is multi-statement DDL; under a fan-out of fresh\n\t// processes it can outlast a single busy_timeout, so retry it on SQLITE_BUSY\n\t// (runtime writes rely on busy_timeout alone). Both steps are idempotent.\n\tif err := ccr.RetryOnBusy(func() error { _, e := db.Exec(memSchema); return e }); err != nil {\n\t\t_ = db.Close()\n\t\treturn nil, fmt.Errorf(\"migrate memories db: %w\", err)\n\t}\n\tif err := ccr.RetryOnBusy(func() error { return migrateMemorySchema(db) }); err != nil {\n\t\t_ = db.Close()\n\t\treturn nil, fmt.Errorf(\"migrate memories db: %w\", err)\n\t}\n\tstore, err := ccr.Open(ccrPath)\n\tif err != nil {\n\t\t_ = db.Close()\n\t\treturn nil, fmt.Errorf(\"open ccr: %w\", err)\n\t}\n\treturn &Store{db: db, eng: engine.New(store, nil), ccr: store}, nil\n}\n\n// Close releases the databases.\nfunc (s *Store) Close() error {\n\terr := s.db.Close()\n\tif cerr := s.ccr.Close(); cerr != nil && err == nil {\n\t\terr = cerr\n\t}\n\treturn err\n}\n\n// Memory is one stored memory.\ntype Memory struct {\n\tID           string  `json:\"id\"`\n\tText         string  `json:\"text\"`\n\tCreatedAt    string  `json:\"created_at\"`","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/mem/store.go#L118-L154","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect the wrapped %w cause to distinguish creation vs corruption issues.","Ensure the parent directory of ccrPath exists and is writable by the process.","If the ccr store is corrupt, back it up and remove it so it is recreated (memory content will need re-indexing).","Check disk space and quotas.","Run the process with the user that owns the data directory."],"exampleFix":"// before\nstore, err := mem.Open(\"/var/lib/app/mem\")\nif err != nil { log.Fatal(err) }\n// after\nos.MkdirAll(\"/var/lib/app/mem\", 0o755) // ensure writable home for ccr\nstore, err := mem.Open(\"/var/lib/app/mem\")\nif err != nil { log.Fatalf(\"open memory store: %v\", err) }","handlingStrategy":"try-catch","validationCode":"// Go: ensure the store parent directory exists and is writable\nif err := os.MkdirAll(dataDir, 0o755); err != nil {\n    return fmt.Errorf(\"cannot prepare memory dir: %w\", err)\n}\nif f, err := os.CreateTemp(dataDir, \".wtest\"); err != nil {\n    return fmt.Errorf(\"memory dir not writable: %w\", err)\n} else { os.Remove(f.Name()); f.Close() }","typeGuard":null,"tryCatchPattern":"store, err := mem.Open(dataDir)\nif err != nil {\n    if strings.Contains(err.Error(), \"open ccr\") {\n        // inspect/repair the ccr store directory before retrying\n    }\n    return err\n}","preventionTips":["Provision the data directory with correct ownership before startup","Never point ccrPath at a regular file","Watch for disk-full conditions that corrupt partially written stores","Run all instances under the same user to avoid permission drift"],"tags":["database","initialization","filesystem"],"backgroundTag":"file-open-failed","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}