{"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":"Error","httpStatus":null,"severity":"critical","filePath":"gitnexus/src/core/embeddings/embedding-pipeline.ts","lineNumber":509,"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":491,"sourceCodeEnd":527,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/d540b00184d71a896261ee02670da9a92d59d8f7/gitnexus/src/core/embeddings/embedding-pipeline.ts#L491-L527","documentation":"Thrown by deleteStaleEmbeddingRows() when a Cypher DELETE against the embedding table fails with an error that is NOT a benign 'does not exist' (which means the rows were already gone). Kuzu forbids SET on vector-indexed properties, so re-embedding uses DELETE-then-INSERT; a failed DELETE that isn't the already-gone case risks leaving the vector index in a corrupted half-state, so the pipeline aborts rather than continuing to INSERT over potentially-stale or dangling rows. Called per-batch to bound the re-embed window.","triggerScenarios":"Any error from executeWithReusedStatement during the per-batch stale-row cleanup whose message lacks 'does not exist': a LadybugDB/Kuzu connection drop, a transaction conflict, a schema mismatch, a vector extension in a bad state, or a concurrent writer.","commonSituations":"A LadybugDB file lock contention (known container issue per AGENTS.md); the vector index in an inconsistent state after a crashed previous run; concurrent analyze processes against one index; a Kuzu version upgrade changing error wording.","solutions":["Run `gitnexus clean` to reset the index and re-run analyze --embeddings from a clean state.","Ensure no other analyze/serve process is writing to the same .gitnexus index concurrently.","If running in a container, check for the known LadybugDB file-locking issue and use a volume that supports flock.","Capture the full underlying error (the ${msg}) — if it indicates a schema/extension problem, address that before retrying."],"exampleFix":"# before — corrupt/half-deleted vector index blocks re-embed\n$ npx gitnexus analyze --embeddings\n# after — reset and re-embed cleanly\n$ npx gitnexus clean\n$ npx gitnexus analyze --embeddings","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"const isVectorIndexCorruptionRisk = (msg: string): boolean =>\n  msg.includes('Failed to delete stale embedding rows');","tryCatchPattern":"try {\n  await runEmbeddingPipeline(executeQuery, executeWithReusedStatement, onProgress);\n} catch (err) {\n  const msg = err instanceof Error ? err.message : String(err);\n  if (msg.includes('Failed to delete stale embedding rows')) {\n    console.error('Vector index at risk of corruption. Run `gitnexus clean` then re-analyze.');\n    process.exit(1);\n  }\n  throw err;\n}","preventionTips":["Do not run two analyze processes against the same .gitnexus index concurrently.","Run `gitnexus clean` after a crashed analysis before re-running.","In containers, use a volume that supports flock to avoid LadybugDB file-lock failures."],"tags":["embeddings","vector-index","data-integrity","ladybugdb","pipeline"],"backgroundTag":null,"analyzedSha":"d540b00184d71a896261ee02670da9a92d59d8f7","analyzedAt":"2026-08-12T19:50:25.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}