{"record":{"id":"6aebe54eb4e21743","repo":"abhigyanpatwari/GitNexus","slug":"ladybugdb-not-found-at-dbpath-run-gitnexus-an","errorCode":null,"errorMessage":"LadybugDB not found at ${dbPath}. Run: gitnexus analyze","messagePattern":"LadybugDB not found at (.+?)\\. Run: gitnexus analyze","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gitnexus/src/core/lbug/pool-adapter.ts","lineNumber":718,"sourceCode":"  try {\n    await promise;\n  } finally {\n    initPromises.delete(repoId);\n  }\n  return true;\n};\n\n/**\n * Internal init — creates DB, pre-warms connections, loads FTS, then registers pool.\n * Pool entry is registered LAST so concurrent executeQuery calls see either\n * \"not initialized\" (and throw) or a fully ready pool — never a half-built one.\n */\nasync function doInitLbug(repoId: string, dbPath: string): Promise<void> {\n  // Check if database exists\n  try {\n    await fs.stat(dbPath);\n  } catch {\n    throw new Error(`LadybugDB not found at ${dbPath}. Run: gitnexus analyze`);\n  }\n\n  evictLRU();\n\n  // Reuse an existing native Database if another repoId already opened this path.\n  // This prevents buffer manager exhaustion from multiple mmap regions on the same file.\n  let shared = dbCache.get(dbPath);\n  if (shared && !shared.external && shared.dbIdentity) {\n    // #2614 F2: a cached read-only Database is keyed by dbPath and shared across\n    // pool consumers. If the on-disk index was rebuilt/swapped (new inode) while\n    // ANOTHER consumer still holds this handle (refCount kept it alive), reusing\n    // it serves a superseded index. Unreachable via the MCP backend (one\n    // consumer per lbugPath ⇒ refCount hits 0 ⇒ closeOne reopens fresh); a\n    // complete fix needs per-inode handles rather than a dbPath-keyed cache.\n    // Surface it so the corner is observable instead of silently stale.\n    const current = await statDbIdentity(dbPath);\n    if (dbIdentityChanged(shared.dbIdentity, current)) {\n      realStderrWrite(","sourceCodeStart":700,"sourceCodeEnd":736,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/d540b00184d71a896261ee02670da9a92d59d8f7/gitnexus/src/core/lbug/pool-adapter.ts#L700-L736","documentation":"Thrown by doInitLbug when fs.stat(dbPath) fails — the LadybugDB database file does not exist at the expected storage path. The pool adapter's initialization path checks for the DB file before attempting to open it; if the file isn't there, the repo was never analyzed (or the storage directory was deleted/corrupted). The dbPath is constructed from the repo's storage paths (typically .gitnexus/<repo-hash>/graph.db under the repo root or a configured storage root).","triggerScenarios":"Calling initLbug (or any pool-backed query) for a repoId whose analyze has never been run; calling it after the .gitnexus/ storage directory was manually deleted; a misconfigured storage root pointing to a path where the DB doesn't exist; the repoId hashing changed between versions so the old DB is at a different path.","commonSituations":"Fresh clone of a repo where the user tries to run `gitnexus serve` or MCP tools before running `gitnexus analyze`; a CI pipeline that cleans the workspace between runs; a corrupted or partially-deleted .gitnexus/ directory after a failed wipe; a storage path configuration change.","solutions":["Run `gitnexus analyze` to create the initial index — this builds the LadybugDB database at the expected path","Verify the storage path is correct: check that .gitnexus/ exists under the repo root after analyze completes","If the DB was at a different path (version migration), run `gitnexus analyze --force` to rebuild at the current version's expected path","Check that the GitNexus process has write permissions to the storage directory"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Verify the DB file exists before initializing the pool\nimport { stat } from 'fs/promises';\nasync function dbExists(dbPath: string): Promise<boolean> {\n  try {\n    const s = await stat(dbPath);\n    return s.isFile();\n  } catch {\n    return false;\n  }\n}\n// Before calling initLbug:\nif (!(await dbExists(dbPath))) {\n  throw new Error('Index not found — run `gitnexus analyze` first');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await doInitLbug(repoId, dbPath);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('LadybugDB not found')) {\n    logger.error('Index missing — run `gitnexus analyze` to create it');\n  }\n  throw e;\n}","preventionTips":["Always run `gitnexus analyze` before starting `gitnexus serve` or MCP","Verify the .gitnexus/ directory exists and contains a graph.db file after analyze","In CI, run analyze as a prerequisite step before serving queries","Don't manually delete .gitnexus/ contents without re-running analyze"],"tags":["ladybugdb","missing-database","pool-adapter","analyze","initialization"],"backgroundTag":null,"analyzedSha":"d540b00184d71a896261ee02670da9a92d59d8f7","analyzedAt":"2026-08-12T19:50:25.132Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}