{"record":{"id":"feca9642c923096b","repo":"abhigyanpatwari/GitNexus","slug":"structural-relationship-count-failed-the-graph-wr","errorCode":null,"errorMessage":"Structural relationship count failed; the graph-write-collapse check will have no structural measurement from this run.","messagePattern":"Structural relationship count failed; the graph-write-collapse check will have no structural measurement from this run\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"gitnexus/src/core/lbug/lbug-adapter.ts","lineNumber":1948,"sourceCode":"  let structuralEdges: number | undefined;\n  let structuralEdgesError: string | undefined;\n  try {\n    const excluded = [...PDG_EDGE_TYPES].map((t) => `'${t}'`).join(', ');\n    structuralEdges = await withConnLock(async () => {\n      const queryResult = await c.query(\n        `MATCH ()-[r:${REL_TABLE_NAME}]->() WHERE NOT r.type IN [${excluded}] RETURN count(r) AS cnt`,\n      );\n      const rows = await readQueryRows(queryResult);\n      return rows.length > 0 ? Number(rows[0]?.cnt ?? rows[0]?.[0] ?? 0) : 0;\n    });\n  } catch (err) {\n    // Same contract as `edges`: leave undefined rather than report a zero the\n    // collapse check would read as a total wipeout. But NOT silent — the reason\n    // travels back on the result and is logged by the caller, so \"the guard\n    // declined because it could not measure\" is visible instead of looking\n    // identical to \"the guard ran and found nothing wrong\".\n    structuralEdgesError = err instanceof Error ? err.message : String(err);\n    logger.warn(\n      { err },\n      'Structural relationship count failed; the graph-write-collapse check will have no ' +\n        'structural measurement from this run.',\n    );\n  }\n\n  return { nodes: totalNodes, edges: totalEdges, structuralEdges, structuralEdgesError };\n};\n\n/**\n * Load cached embeddings from LadybugDB before a rebuild.\n * Returns all embedding vectors so they can be re-inserted after the graph is reloaded,\n * avoiding expensive re-embedding of unchanged nodes.\n *\n * Detects old schema (no chunkIndex column) and returns empty cache to trigger rebuild.\n */\nexport const loadCachedEmbeddings = async (): Promise<{\n  embeddingNodeIds: Set<string>;","sourceCodeStart":1930,"sourceCodeEnd":1966,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/aac7515d2a8c50a1f8f923c6fb77218b333560d6/gitnexus/src/core/lbug/lbug-adapter.ts#L1930-L1966","documentation":"Post-load validation could not count structural relationships (the MATCH ()-[r:REL]->() WHERE NOT r.type IN [excluded] count over the rel table failed). By contract the count stays undefined rather than becoming a misleading 0 — a zero would read as a total wipeout to the graph-write-collapse guard. The failure reason is carried on the result as structuralEdgesError and logged here, so 'guard could not measure' is distinguishable from 'guard ran and found nothing'.","triggerScenarios":"The structural count query inside the validation helper throws: connection trouble, query timeout on a huge rel table, missing/corrupt rel table after a bad load. Only the count degrades — nodes/edges totals may still be returned.","commonSituations":"Very large indexes where COUNT times out; DB contention with a concurrent serve; a load that half-failed earlier (pairs with the lbug-load warn above); LadybugDB extension faults.","solutions":["Re-run the analyze — transient timeouts/locks usually clear and the guard gets its measurement next time.","Check the structuralEdgesError string on the load result (it names the exact engine message) before assuming data loss.","Avoid running serve queries against the DB during the load/validation window.","If it persists, rebuild from scratch (`rm -rf .gitnexus && analyze`) to rule out a corrupt rel table."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// After load: branch on the structured result, not the log line\nconst stats = await getGraphStats(dbPath);\nif (stats.structuralEdges === undefined) {\n  // guard could not measure — do NOT interpret anything about collapse\n  console.warn('collapse guard unmeasured:', stats.structuralEdgesError);\n}","typeGuard":"function hasStructuralMeasurement(s: GraphStats): s is GraphStats & { structuralEdges: number } {\n  return typeof s.structuralEdges === 'number';\n}","tryCatchPattern":null,"preventionTips":["Always read structuralEdgesError off the result object rather than grepping logs.","Keep long-running readers off the DB during load so the count query doesn't time out.","Re-run analyze once before concluding graph corruption from a missing measurement."],"tags":["ladybugdb","validation","graph-integrity","count-query","degraded"],"backgroundTag":"post-load-validation-failed","analyzedSha":"aac7515d2a8c50a1f8f923c6fb77218b333560d6","analyzedAt":"2026-08-20T23:29:22.980Z","schemaVersion":2},"datasetVersion":"2026-08-31T04:17:50.494Z"}