Incremental writeback with streamed graph emit produces corrupted Class rows (reproduced)
Incremental writeback with streamed graph emit produces corrupted Class rows (reproduced)
Summary
While stress-testing GitNexus on a large Java monorepo (25k files, ~605k nodes, 3.6GB-RAM box), we locally enabled streamed structural graph emit for incremental runs via an env-gated patch modeled on #2680. The upstream code deliberately refuses streamGraphEmit on incremental runs — the test suite calls this "a soundness boundary, not a preference" (test/unit/stream-graph-emit-config.test.ts:4). We reproduced the corruption it guards against, deterministically, and are documenting the failure mode since it is subtle and silent (exit 0, no warnings about the corruption itself).
Reproduction (deterministic)
- Clean full rebuild (healthy index, verified: 0 corrupted rows out of 21,163 Class rows).
- Modify ONE Java file (append a comment line — content is irrelevant).
- Run incremental analyze with
GITNEXUS_STREAM_GRAPH_EMIT_INCREMENTAL=1. - Result: 18,257 of 21,163 Class rows corrupted — identity columns (id, name, filePath) empty, startLine/endLine populated. Exit code 0. No error or warning about the corruption.
Corollary: the next (non-streamed) incremental run self-heals — drift detection matches fresh nodes against persisted ids, finds every corrupted row "drifted", and rewrites them. In our first incident this masqueraded as a mysterious 2,710-file annotation-drift storm.
Observations that narrow the root cause
We did not root-cause to the exact line, but three pinned facts may help a maintainer do so quickly:
- The node CSV on disk is HEALTHY. After the corrupted incremental run,
.gitnexus/csv/class.csvcontained 3,693 rows with zero empty ids. The corruption therefore happens after CSV emit — during COPY into the database, or in a later phase that rewrites rows (FTS / embedding-restore). The CSV generator and the subgraph extraction (nodes ride the real graph, never the sink) are exonerated. - Both corruption incidents coincided with an FTS index build failure ("full-text/BM25 search is disabled — the search index build failed this run"). The repair run that had no FTS failure also had no corruption. We cannot yet prove causation, but the correlation is exact across both incidents.
- The incremental writeback path never passes the streamed manifests (
run-analyze.tsincremental branch callsloadGraphToLbug(subgraph, repoPath, storagePath, cb)with 4 args). The full-rebuild branch's comment states the assumption outright: "Only ever set on a full rebuild (streaming is force-gated), so the incremental branch above never carries it." Our env flag breaks exactly that premise. Relatedly,StreamedRelationship.reasonis the constant'streamed'on in-memory reads, justified by "the persisted CSV row keeps the real value" — an invariant that only holds when the manifest CSVs are the ones being COPY'd.
What we'd suggest
- If combining the sink with
extractChangedSubgraph/incremental COPY is fundamentally unsound, a runtime hard-fail (rather than relying on the config gate alone) would have saved us a week of forensic archaeology — the corruption is silent and its downstream symptom (annotation drift) points elsewhere. - We're happy to share the corrupted DB artifacts or the exact env/versions for a regression test. Repro is cheap if you have any multi-module Java repo: full rebuild → touch one file → flip the incremental-streaming env → count empty
namerows in Class. - If maintainers already know the mechanism, a comment near the incremental gate explaining it would be valuable — the current one says "soundness boundary" without saying what breaks.
Environment
- GitNexus 1.6.9 (local build; patched
resolveStreamGraphEmitonly — env gateGITNEXUS_STREAM_GRAPH_EMIT_INCREMENTALdefaulting off, exactly as upstream ships) - Node v22.22.3, Linux x64, 4GB RAM + zram
- Repo: 25k-file Java/Spring monorepo (multi-module Maven),
GITNEXUS_MAX_PACKAGE_FILES=5000,MAX_INJECTED_SIBLINGS=200,WORKER_POOL_SIZE=1
Source: abhigyanpatwari/GitNexus