{"record":{"id":"dab95a2459cadab3","repo":"abhigyanpatwari/GitNexus","slug":"gitnexus-bm25-index-js-import-failed-falling-ba","errorCode":null,"errorMessage":"GitNexus: bm25-index.js import failed — falling back to semantic-only","messagePattern":"GitNexus: bm25-index\\.js import failed — falling back to semantic-only","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"gitnexus/src/mcp/local/local-backend.ts","lineNumber":3080,"sourceCode":"      ...(warnings.length > 0 && { warning: warnings.join(' ') }),\n      ...((enrichmentDegraded || ftsPartial) && { partial: true }),\n    };\n  }\n\n  /**\n   * BM25 keyword search helper - uses LadybugDB FTS for always-fresh results\n   */\n  private async bm25Search(\n    repo: RepoHandle,\n    query: string,\n    limit: number,\n  ): Promise<{ results: any[]; ftsUsed: boolean; nonBenignErrors?: string[] }> {\n    let searchFTSFromLbug;\n    try {\n      ({ searchFTSFromLbug } = await import('../../core/search/bm25-index.js'));\n    } catch (err: any) {\n      // Module import can fail in sandboxed MCP contexts (#1489)\n      logger.warn(\n        { err: err?.message },\n        'GitNexus: bm25-index.js import failed — falling back to semantic-only',\n      );\n      return { results: [], ftsUsed: false };\n    }\n    let ftsResponse;\n    try {\n      ftsResponse = await searchFTSFromLbug(query, limit, repo.lbugPath);\n    } catch (err: any) {\n      // Swallowed, gracefully-degraded failure: the search falls back to\n      // semantic-only (a valid result), and the most common cause is simply an\n      // un-indexed FTS extension — a normal configuration, not an operation\n      // error. Logged at warn (matching the sibling import-failure fallback\n      // above), never error, so it does not raise a false alarm.\n      logger.warn(\n        { err: err.message },\n        'GitNexus: BM25/FTS search failed (FTS indexes may not exist) — falling back to semantic-only',\n      );","sourceCodeStart":3062,"sourceCodeEnd":3098,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/aac7515d2a8c50a1f8f923c6fb77218b333560d6/gitnexus/src/mcp/local/local-backend.ts#L3062-L3098","documentation":"The dynamic import of ../../core/search/bm25-index.js inside bm25Search failed (module resolution, sandboxed MCP contexts per #1489, broken install). The helper returns { results: [], ftsUsed: false } and the overall search degrades to semantic-only — a valid result, not an operation error.","triggerScenarios":"A `query`/search MCP call enters bm25Search; `await import('../../core/search/bm25-index.js')` throws in restricted MCP sandboxes (file-read policies, ESM loader restrictions) or when the package install is incomplete. Only err?.message is captured in the log.","commonSituations":"MCP servers run under sandbox policies (seatbelt/bubblewrap profiles) that block reading module files inside the package; partially-installed node_modules after an interrupted npm install; bundlers that break the relative ESM path.","solutions":["Loosen the MCP sandbox to allow reading files under the installed gitnexus package directory.","Reinstall cleanly: `rm -rf node_modules && npm install gitnexus@latest`.","Verify the file exists: check node_modules/gitnexus/dist/core/search/bm25-index.js (or the source path in dev).","Accept semantic-only results temporarily — search still works without BM25."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// Pre-flight the module once at server startup instead of per query\nlet bm25: typeof import('../../core/search/bm25-index.js') | undefined;\ntry { bm25 = await import('../../core/search/bm25-index.js'); }\ncatch { bm25 = undefined; } // search config now knows FTS is unavailable","typeGuard":null,"tryCatchPattern":"let searchFTSFromLbug;\ntry {\n  ({ searchFTSFromLbug } = await import('../../core/search/bm25-index.js'));\n} catch {\n  return { results: [], ftsUsed: false }; // semantic-only is a valid result\n}","preventionTips":["Sandbox policies for the MCP server must allow reads under the installed gitnexus package.","Verify installs with `node -e \"import('gitnexus/dist/core/search/bm25-index.js')\"`.","Watch ftsUsed in responses — false persistent means BM25 is silently out of the mix."],"tags":["mcp","module-import","sandbox","bm25","degraded"],"backgroundTag":"module-import-failed","analyzedSha":"aac7515d2a8c50a1f8f923c6fb77218b333560d6","analyzedAt":"2026-08-20T23:29:22.980Z","schemaVersion":2},"datasetVersion":"2026-08-31T04:17:50.494Z"}