{"record":{"id":"ce101370e74310ce","repo":"JuliusBrussee/caveman","slug":"open-memories-db-w","errorCode":null,"errorMessage":"open memories db: %w","messagePattern":"open memories db: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mem/store.go","lineNumber":118,"sourceCode":"\t\t}\n\t\tif err := os.MkdirAll(dir, 0o700); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"create %s: %w\", dir, err)\n\t\t}\n\t\tmemPath = filepath.Join(dir, \"mem.db\")\n\t\tccrPath = filepath.Join(dir, \"ccr.db\")\n\t}\n\tcanonicalMemPath, err := ccr.PrepareSQLitePathCanonical(memPath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"secure memories db: %w\", err)\n\t}\n\t// Same embedded-SQLite-behind-a-multi-process-CLI discipline as the recovery\n\t// store: a single writer connection plus busy_timeout(5000)+WAL. Several\n\t// cavemem processes (and the MCP server) share one mem.db, and the JS client\n\t// fires Promise.all(facts.map(remember)); without this, concurrent writes\n\t// returned SQLITE_BUSY and were silently dropped. See ccr.SQLiteDSN.\n\tdb, err := sql.Open(\"sqlite\", ccr.SQLiteDSN(canonicalMemPath))\n\tif err != nil {\n\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)","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/mem/store.go#L100-L136","documentation":"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.","triggerScenarios":"sql.Open(\"sqlite\", ccr.SQLiteDSN(canonicalMemPath)) fails — driver not registered (blank import missing) or the constructed DSN is invalid.","commonSituations":"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.","solutions":["Ensure the sqlite driver is imported (blank import of the driver package) in the binary","Inspect ccr.SQLiteDSN output for malformed DSN parameters","Verify the canonical mem.db path is valid","Rebuild with the driver dependency included if using a trimmed module"],"exampleFix":"// before: missing driver import\nimport _ \"modernc.org/sqlite\" // ensure registered\n// after\nimport (\n    _ \"modernc.org/sqlite\"\n)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"store, err := mem.Open(opts)\nif err != nil && strings.Contains(err.Error(), \"open memories db\") {\n  // driver/DSN problem: verify sqlite driver import and DSN\n  return err\n}","preventionTips":["Blank-import the sqlite driver in every binary that opens the store","Do not alter the DSN produced by ccr.SQLiteDSN","Keep the driver dependency in go.mod for trimmed builds"],"tags":["sqlite","database","open","dsn"],"backgroundTag":"database-query-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"}