GitNexus/gitnexus/bench/incremental-write-integrity
Gergő Magyar 1b8fa72332
fix(lbug): make FTS COPY failures actionable (#3977)
Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com>
2026-11-18 07:45:18 +00:00
..
baseline.json fix(index): guard graph integrity and fail closed on incomplete risk (#3442) 2026-10-02 15:34:26 +01:00
measure-compact-writes.mjs fix: compact incremental graphs adaptively (#3854) 2026-11-09 20:57:07 +00:00
measure.cjs perf: reduce lookup allocations and stream identity checks (#3805) 2026-11-04 10:15:24 +00:00
memory.mjs perf: reduce lookup allocations and stream identity checks (#3805) 2026-11-04 10:15:24 +00:00
README.md fix: compact incremental graphs adaptively (#3854) 2026-11-09 20:57:07 +00:00
reproduce-fts-copy.cjs fix(lbug): make FTS COPY failures actionable (#3977) 2026-11-18 07:45:18 +00:00
reproduce-growth.cjs fix: compact incremental graphs adaptively (#3854) 2026-11-09 20:57:07 +00:00
reproduce-search.cjs test(embeddings): cover CodeEmbedding scans after delete and re-create (#3569, #3474) (#3623) 2026-10-18 11:01:04 +01:00
reproduce.cjs fix(index): guard graph integrity and fail closed on incomplete risk (#3442) 2026-10-02 15:34:26 +01:00
search-root-cause.md test(embeddings): cover CodeEmbedding scans after delete and re-create (#3569, #3474) (#3623) 2026-10-18 11:01:04 +01:00

Incremental node identity reconciliation

Hybrid graph writes (#3852)

Small edits replace only affected rows. A fresh bulk COPY compacts the graph when any of these conditions applies:

  • 16 successful incremental writes have accumulated.
  • Physical growth exceeds the larger of 50% of the compact baseline or 16 MiB.
  • The effective write set touches the larger of 2,000 nodes and relationships or 5% of the graph. The threshold scales with monorepo size and also catches large mutations contained in a single source file.
  • Existing file-fraction or extension safety gates require a rebuild.

The footprint uses the larger old/new source-file estimate. Capped native reads measure removed symbols and deleted files; small deletions and renames remain selective. This is a source-footprint heuristic, not a total DML-operation budget.

Each index records its own compact size and update counter after a durable, verified publication. Missing or malformed metadata establishes a fresh baseline once. An unchanged source snapshot can still compact when its storage deadline is due. Parse-cache reuse, compatible vectors, identity checks, dirty recovery and the existing platform-specific publication policy apply to both write paths.

Run from gitnexus/:

node bench/incremental-write-integrity/reproduce-growth.cjs
node bench/incremental-write-integrity/reproduce-growth.cjs --large
npm run build
node bench/incremental-write-integrity/measure-compact-writes.mjs --profile --output /tmp/hybrid-writes.json
node bench/incremental-write-integrity/measure-compact-writes.mjs --repos 3 --files 8 --functions 4 --output /tmp/hybrid-small-repos.json

Both harnesses create isolated temporary fixtures and remove them by default; --keep retains them. The analyzer harness accepts --runtime /path/to/repo for another compiled checkout and --files, --functions, --edits, and --repos for different workload shapes. Defaults are 128 files, 32 functions per file, 18 edits, and one repository. --profile records analyzer phase timings. It checks no-op inode stability, compaction receipts, and exact node/edge identity fingerprints against a forced rebuild of each repository's final source state. Timing and file sizes are measurements, not machine-specific CI thresholds.

The native reduction uses serial uncompressed COPY, a Function node table and three relationships per node, with no parser, FTS or GitNexus adapter. It measures individual DELETE/CREATE/SET operations and twelve identical one-file rewrites. Every rewrite and fresh reload must preserve an exact node/edge tuple fingerprint. The default fixture has 32,768 nodes, 98,304 edges and repeated 1 KiB content; --large doubles the graph and uses distinct content. It reports checkpointed, reopened sizes, free-page counts and warm scan medians. These isolate native storage amplification without establishing a particular C++ allocation defect.

On Linux x64, Node 22.23.3 and @ladybugdb/core 0.22.0, the default fixture grew from 18.93 MiB to 32.07 MiB after one rewrite (1.69×), then plateaued over the remaining cycles. A fresh COPY returned it to 18.92 MiB with identical tuples. The larger fixture grew from 98.64 MiB to 123.36 MiB (1.25×). The smaller fixture used a 256 MiB native pool; the larger required 1 GiB.

FTS creation skips tables proven empty by fresh native counts. Incomplete or failed count reads retain the normal index checks. No table counts are cached across requests or mutations. Native tests compare core and pooled ranked search with an independent all-indexes control, including empty-to-populated transitions.

For the native cause of #3421/#3423 and regressions covering both missing context results and Unicode Property FTS, see search-root-cause.md.

From gitnexus/:

node --import tsx bench/incremental-write-integrity/measure.cjs --check
node bench/incremental-write-integrity/reproduce.cjs

The first command measures the production reconciliation, including every single-label scan and comparison of ID, name, path and source range. Construction, CSV loading, checkpoints and correctness controls are outside the timed region. Two warm-ups precede seven measured samples. Exact counts and SHA-256 fixture fingerprints reject empty or incomplete work. --check gates normalized scaling against the committed budget, rather than a machine-specific time limit.

On Node v24.19.0, Linux x64, Xeon Platinum 8370C, the initial measurement was 583 ms for 16,384 nodes and 2,810 ms for 65,536 nodes per reconciliation. The normalized scaling was 1.206 (budget 2). Analyze performs two reconciliations: after graph COPY/checkpoint and after FTS/embedding work plus a final checkpoint, before registration, freshness metadata or staging publication.

The verifier covers retained nodes as well as the write set. A path/range filter would let a corrupted field hide its own row; a count would miss swapped fields or blank IDs. Folder lifecycle, preserved Community/Process layers and streamed BasicBlock rows require other oracles and are excluded. Relationships and source content are outside this identity check.

Native-only reduction

reproduce.cjs uses only @ladybugdb/core, its native schema/query/COPY API, and synthetic ASCII CSV files. There is no parser, parse cache, graph adapter, FTS, relationship table, periodic checkpoint driver or concurrent writer. Compression is disabled and COPY is serial, matching the production settings.

It loads 8,192 Function rows, checkpoints, deletes 64 rows belonging to the first and last owners, then copies back those same 64 tuples. An independent tuple-set oracle validates the complete single-label scan before and after each operation. It also compares affected scan rows with primary-key lookups after reopening. Use --keep to retain the synthetic database and CSV files; the JSON output gives their directory. --require-corruption is a diagnostic assertion, deliberately not a CI requirement: it should fail when the native defect is fixed.

With the original @ladybugdb/core 0.18.3, this reduction produced:

Phase Rows Incorrect tuples
Initial COPY + checkpoint 8,192 0
DELETE 8,128 0
Incremental COPY 8,192 3,936
Explicit checkpoint 8,192 3,936
Read-only reopen 8,192 3,936

With @ladybugdb/core 0.21.1, the same reduction returns zero incorrect tuples in every phase. The production reconciliation and negative controls remain required; this result covers the reduced fixture, not a replay of the original incident.

For example, the scan returned an empty id at native offset 64, while a primary-key lookup at that same offset returned Function:src/owner2.ts:fn64 with the correct name/path/range. Smaller 1,024, 2,048 and 4,096-row fixtures remained healthy in the same three-cycle adapter probe. The affected tuple count varies with fixture size and scan shape.

This isolates a native scan/lookup discrepancy introduced by incremental COPY into a previously populated table. It survives checkpoint and reopen, but does not establish physical byte loss or the precise C++ defect. The reported Unicode change and FTS build are unnecessary for this reduction; this does not prove that the original incident has exactly the same native cause.

The measurement harness runs selective native writes too. An independent oracle requires the production verifier to reject any inconsistent scan, both before and after checkpoint/reopen; healthy scans must certify their complete identity set. It does not quietly treat the native discrepancy as a successful graph.

Missing-row and swapped-range negative controls separately verify that the check fails closed. Publication tests inject damage after COPY and after FTS, assert unchanged registry/freshness, preserve the live staged baseline, and exercise automatic dirty-index recovery followed by a no-op run. An in-place verification failure keeps a non-FTS dirty phase: an FTS-only repair cannot clear the marker and recertify the inconsistent graph. The same protection applies when FTS returns but analyzer finalization fails before the final identity scan: recovery still rebuilds the graph.

Memory scaling

memory.mjs measures the compiled production reader in a fresh process, without forcing GC between reads. It records full identity verification, elapsed time, sampled heap/RSS, the process RSS high-water mark, and initial/final retained heap. The native pool is 512 MiB for measurements and 1 GiB for fixture creation.

Build the runtime with npm run build. Save this configuration outside the repo:

{
  "runtime": "/absolute/path/to/GitNexus",
  "storage": "/tmp/gnx-identity-memory",
  "output": "/tmp/gnx-identity-memory/seed.json",
  "count": 1048576,
  "width": 0,
  "mode": "seed",
  "reader": "stream",
  "iterations": 40
}

Run from gitnexus/:

node --expose-gc --max-old-space-size=4096 bench/incremental-write-integrity/memory.mjs /tmp/config.json

Then change mode to measure and choose a new output file. Run each measurement in a new process and use one process per database at a time. To compare the original array-based implementation, set runtime to its separately built checkout and reader to baseline; keep the same fixture and memory limits.

Vary count with separate fixtures to measure node scaling. width adds that many ASCII bytes to each of ID, name and path, so it measures identity size independently of node count. Repeat each point and hold the largest size out of the fitted curve. A finite RSS fit is evidence over that range, not a guarantee about every native allocator or the rest of the indexing pipeline.

The streaming verifier retains expected-node maps and one decoded row rather than a full table of JavaScript rows. The expected maps grow linearly with graph size; the native query result and the original graph still consume memory.