{"record":{"id":"deb9711751e33d24","repo":"abhigyanpatwari/GitNexus","slug":"embed-failed-to-delete-stale-embedding-rows-ab","errorCode":null,"errorMessage":"[embed] Failed to delete stale embedding rows — aborting to prevent vector-index corruption: ${msg}","messagePattern":"\\[embed\\] Failed to delete stale embedding rows — aborting to prevent vector-index corruption: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gitnexus/src/core/embeddings/embedding-pipeline.ts","lineNumber":510,"sourceCode":" * interleaving bounds that window to a single batch.\n */\nconst deleteStaleEmbeddingRows = async (\n  executeWithReusedStatement: (\n    cypher: string,\n    paramsList: Array<Record<string, any>>,\n  ) => Promise<void>,\n  nodeIds: string[],\n): Promise<void> => {\n  if (nodeIds.length === 0) return;\n  try {\n    await executeWithReusedStatement(\n      `MATCH (e:${EMBEDDING_TABLE_NAME} {nodeId: $nodeId}) DELETE e`,\n      nodeIds.map((nodeId) => ({ nodeId })),\n    );\n  } catch (err) {\n    const msg = err instanceof Error ? err.message : String(err);\n    if (!msg.includes('does not exist')) {\n      throw new Error(\n        `[embed] Failed to delete stale embedding rows — aborting to prevent vector-index corruption: ${msg}`,\n      );\n    }\n  }\n};\n\n/**\n * Run the embedding pipeline\n *\n * @param executeQuery - Function to execute Cypher queries against LadybugDB\n * @param executeWithReusedStatement - Function to execute with reused prepared statement\n * @param onProgress - Callback for progress updates\n * @param config - Optional configuration override\n * @param skipNodeIds - Optional set of node IDs that already have embeddings (incremental mode)\n * @param existingEmbeddings - Optional map of nodeId → contentHash for incremental mode.\n *        Nodes whose hash matches are skipped; nodes with a changed hash are DELETE'd\n *        and re-embedded; nodes not in the map are embedded fresh.\n */","sourceCodeStart":492,"sourceCodeEnd":528,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/ac9a4e9abd8fd3058c070b72c23402a4f887929a/gitnexus/src/core/embeddings/embedding-pipeline.ts#L492-L528","documentation":"Thrown by deleteStaleEmbeddingRows() during the incremental re-embed path: nodes whose contentHash changed must have their old Embedding rows DELETEd before re-embedding. Any DELETE failure other than a tolerated 'does not exist' (fresh index, table missing) aborts the pipeline, because leaving stale vectors would make the vector index return embeddings that no longer match node content — corruption by design is worse than stopping.","triggerScenarios":"Running the embedding pipeline in incremental mode (changed files only) while the LadybugDB file is locked by another process (e.g. a concurrent `gitnexus serve` or second analyze), on a disk I/O error, or against a corrupted .gitnexus database during the MATCH (e:Embedding {nodeId}) DELETE e batch.","commonSituations":"Two gitnexus processes sharing one repo index, an editor MCP server holding the DB while the CLI re-embeds, full disk, or a DB left dirty after a killed run.","solutions":["Stop other gitnexus processes using this repo's index (gitnexus serve, MCP server, another analyze) and rerun the embedding pipeline.","Free disk space and verify write permissions on the .gitnexus directory.","If the DB is corrupted, delete the .gitnexus index and re-run analyze --embeddings from scratch.","Rerun the pipeline — the delete/re-embed is designed so a clean rerun converges."],"exampleFix":"# before: serve is running while re-embedding\nnpx gitnexus serve &\nnpx gitnexus analyze --embeddings\n# after: single writer at a time\nkill %1  # stop serve first\nnpx gitnexus analyze --embeddings\nnpx gitnexus serve","handlingStrategy":"retry","validationCode":"// ensure single writer before running the embedding pipeline\nimport { access, constants } from 'node:fs/promises';\nawait access('.gitnexus', constants.W_OK); // fail fast if index dir not writable","typeGuard":"const isStaleDeleteAbort = (e: unknown): boolean =>\n  e instanceof Error && e.message.startsWith('[embed] Failed to delete stale embedding rows');","tryCatchPattern":"try {\n  await runEmbeddingPipeline(executeQuery, executeWithReusedStatement, onProgress, config);\n} catch (e) {\n  if (isStaleDeleteAbort(e)) {\n    // stop other gitnexus processes on this repo, then rerun the pipeline\n  } else throw e;\n}","preventionTips":["Run only one gitnexus process (analyze/serve/MCP) against a repo index at a time.","Monitor free disk space before long embedding runs.","Treat this abort as intentional: never wrap it in a swallow-and-continue handler that would risk stale vectors."],"tags":["embeddings","database","ladybugdb","incremental","corruption-prevention"],"backgroundTag":"database-row-delete-failed","analyzedSha":"ac9a4e9abd8fd3058c070b72c23402a4f887929a","analyzedAt":"2026-08-20T23:29:22.980Z","contentChangedAt":"2026-08-20T23:29:22.980Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}