{"record":{"id":"9f7128920a581e55","repo":"abhigyanpatwari/GitNexus","slug":"ladybugdb-not-initialized-for-repo-repoid-ca","errorCode":null,"errorMessage":"LadybugDB not initialized for repo \"${repoId}\". Call initLbug first.","messagePattern":"LadybugDB not initialized for repo \"(.+?)\"\\. Call initLbug first\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"gitnexus/src/core/lbug/pool-adapter.ts","lineNumber":1033,"sourceCode":"/**\n * Execute a parameterized query on a specific repo's connection pool.\n * Uses prepare/execute pattern to prevent Cypher injection.\n */\nexport const executeParameterized = async (\n  repoId: string,\n  cypher: string,\n  params: Record<string, any>,\n): Promise<any[]> => {\n  // A `.length` compare on text we already hold — runs before the pool lookup so\n  // a query built by splicing a caller-sized list names itself even when the\n  // repo is not initialized. Never throws (#2915).\n  warnIfQueryTextUnbounded(cypher, `pool executeParameterized (repo \"${repoId}\")`, (message) =>\n    poolSidecarLogger.warn(message),\n  );\n\n  const entry = pool.get(repoId);\n  if (!entry) {\n    throw new Error(`LadybugDB not initialized for repo \"${repoId}\". Call initLbug first.`);\n  }\n\n  entry.lastUsed = Date.now();\n\n  const conn = await checkout(entry);\n  silenceStdout();\n  activeQueryCount++;\n  let queryResult: lbug.QueryResult | lbug.QueryResult[] | undefined;\n  try {\n    const stmt = await withTimeout(conn.prepare(cypher), QUERY_TIMEOUT_MS, 'Prepare');\n    if (!stmt.isSuccess()) {\n      const errMsg = await stmt.getErrorMessage();\n      throw new Error(`Prepare failed: ${errMsg}`);\n    }\n    queryResult = await withTimeout(conn.execute(stmt, params), QUERY_TIMEOUT_MS, 'Execute');\n    const result = Array.isArray(queryResult) ? queryResult[0] : queryResult;\n    const rows = await result.getAll();\n    return rows;","sourceCodeStart":1015,"sourceCodeEnd":1051,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/d540b00184d71a896261ee02670da9a92d59d8f7/gitnexus/src/core/lbug/pool-adapter.ts#L1015-L1051","documentation":"Thrown by executeParameterized when the pool has no entry for the given repoId. The pool is populated by doInitLbug → registered LAST (after FTS load, pre-warming) so that concurrent queries see either 'not initialized' or a fully ready pool. This error means initLbug was never called for this repo, or the pool entry was evicted (LRU) or explicitly closed. The error fires after a lightweight query-text warning check (warnIfQueryTextUnbounded) that never throws.","triggerScenarios":"Calling executeParameterized(repoId, cypher, params) for a repoId that hasn't been initialized via initLbug; calling it after the pool entry was evicted by LRU pressure from other repos; calling it after closeLbug was called on that repoId. Typical in MCP/serve contexts where the backend tries to query a repo that the user hasn't analyzed yet.","commonSituations":"MCP server or `gitnexus serve` receives a query for a repository that was never analyzed; the user switched repositories but the server wasn't reconfigured; an LRU eviction dropped the pool entry for a repo that hadn't been queried recently; the repoId doesn't match what was used during analyze (case sensitivity, path normalization).","solutions":["Run `gitnexus analyze` for the repository to create the index, then retry the query","Verify the repoId matches exactly what was used during initialization — check for path/normalization differences","If using `gitnexus serve`, ensure it's pointed at the correct repository storage directory","For MCP, ensure the server has been configured with the correct repo path and that analyze completed successfully"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Verify the pool is initialized for a repoId before querying\nfunction isPoolInitialized(repoId: string): boolean {\n  return pool.has(repoId);\n}\n// Before calling executeParameterized:\nif (!isPoolInitialized(repoId)) {\n  throw new Error(`Repo \"${repoId}\" not initialized — run gitnexus analyze first`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const rows = await executeParameterized(repoId, cypher, params);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('LadybugDB not initialized')) {\n    // Prompt user to analyze, or initialize the pool\n    logger.error(`Repo \"${repoId}\" not indexed — run gitnexus analyze`);\n  }\n  throw e;\n}","preventionTips":["Initialize the pool via initLbug before any query — serve/MCP should lazy-init on first query","Verify repoId normalization (path casing, trailing slashes) matches between analyze and serve","Handle LRU eviction gracefully by re-initializing evicted repos on demand","Log pool state (initialized repoIds) at startup for debugging"],"tags":["ladybugdb","pool-adapter","not-initialized","query","initialization"],"backgroundTag":null,"analyzedSha":"d540b00184d71a896261ee02670da9a92d59d8f7","analyzedAt":"2026-08-12T19:50:25.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}