{"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":803,"sourceCode":"    if (existing.checkedOut > 0) return { status: 'done', reopened: false };\n    // Awaited: see the rationale on the evictLRU call site in doInitLbug below.\n    await closeOne(repoId); // idle & changed → evict, then fall through to reopen the new file\n  }\n\n  return doInitLbug(repoId, dbPath);\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<InitLbugAttempt> {\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  // Awaited: without this, the connection opened just below could race the\n  // checkpoint from the LRU victim's still-in-flight close (see evictLRU /\n  // closeOne). The caller holds withPoolLock for this attempt, so this await\n  // only covers this call's own evict-then-reopen — not other callers.\n  // Lock-retry re-enters this function after sleeping *outside* the mutex.\n  // evictLRU is a no-op unless the pool is full again (another repo may have\n  // taken the slot we freed on a prior attempt). Skipping it on retry would\n  // let a 6th native open race a still-resident victim's checkpoint.\n  await 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","sourceCodeStart":785,"sourceCodeEnd":821,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/ac9a4e9abd8fd3058c070b72c23402a4f887929a/gitnexus/src/core/lbug/pool-adapter.ts#L785-L821","documentation":"doInitLbug (gitnexus/src/core/lbug/pool-adapter.ts:718) stat'd the database file before opening and it is not there: the pool has no index to serve. The pool is read-only by design — only `gitnexus analyze` creates the database, so the fix is to build the index first.","triggerScenarios":"Calling initLbug(repoId, dbPath) — directly or via MCP/serve startup — for a repository that was never analyzed, whose storage directory was deleted or moved, or whose repoId-to-path mapping resolves to the wrong location.","commonSituations":"Fresh clone with serve started before the first analyze; storage dir wiped by a cleanup script or CI; a config or mapping regression pointing at a non-existent path.","solutions":["Run `gitnexus analyze` on the repository to build the index, then retry","Verify the resolved dbPath actually exists on disk and fix the storage/repo mapping if it points elsewhere","If the index was deliberately removed, restore it from backup or re-analyze"],"exampleFix":"// before — init throws when the index was never built\nawait initLbug(repoId, dbPath);\n\n// after — build the index first, then open the pool\nif (!(await fs.stat(dbPath).then(() => true, () => false))) {\n  await runAnalyze(repoPath); // creates the database\n}\nawait initLbug(repoId, dbPath);","handlingStrategy":"validation","validationCode":"// check the index exists before opening the pool\nimport { stat } from 'node:fs/promises';\nconst exists = await stat(dbPath).then(\n  () => true,\n  () => false,\n);\nif (!exists) {\n  throw new Error(`no index at ${dbPath} — run gitnexus analyze first`);\n}","typeGuard":"const isLbugNotFound = (e: unknown): boolean =>\n  e instanceof Error && e.message.startsWith('LadybugDB not found at');","tryCatchPattern":"try {\n  await initLbug(repoId, dbPath);\n} catch (e) {\n  if (isLbugNotFound(e)) {\n    // build the index, then retry the open\n    await runAnalyze(repoPath);\n    await initLbug(repoId, dbPath);\n  } else {\n    throw e;\n  }\n}","preventionTips":["Make `gitnexus analyze` a provisioning step that runs before serve/MCP startup","Pin the storage directory location in config so cleanup scripts cannot silently remove it","Log the resolved dbPath at startup to catch mapping regressions early"],"tags":["gitnexus","ladybugdb","index-missing","init","not-found"],"backgroundTag":"database-file-not-found","analyzedSha":"ac9a4e9abd8fd3058c070b72c23402a4f887929a","analyzedAt":"2026-09-15T23:29:44.066Z","contentChangedAt":"2026-09-15T23:29:44.066Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}