GitNexus/gitnexus/scripts
Void Freud 7ee0df9e55
fix: serialize global registry transactions across processes (#2716)
* fix: serialize global registry mutations

* fix: serialize global registry mutations

* fix: keep registry reads lock-free

* test(registry): document cross-platform lock coverage

* fix(registry): isolate the registry lock's namespace, timeout and diagnostics

Review follow-ups on the global registry lock (#2716):

- The lock took `getGlobalDir()` itself, which is byte-identical to a repo's
  index slot when that repo is rooted at the user's home directory (a real
  dotfiles layout). `runFullAnalysis` holds the per-repo lock across its whole
  pipeline and `acquireIndexLock` is not reentrant, so `registerRepo` /
  `adoptFlatBranchLabel` self-deadlocked until the wait ceiling and then failed
  the analyze. The registry now locks a private `<globalDir>/registry-lock`
  namespace no index slot can ever resolve to.

- The lock inherited the index lock's 10-minute default timeout, sized for
  multi-minute analyze runs. `gitnexus augment` — documented to cold-start in
  under 500ms and shelled out from editor tool-use hooks — reaches it through
  `listRegisteredRepos({ validate: true })`. Registry transactions are
  sub-second, so they now get their own 5s ceiling.

- Contention was silent: no `log`/`onWaitStart` was wired, and the primitive's
  own texts attribute a wait to "another gitnexus analyze", which misnames a
  registry holder. A registry-specific line is emitted on wait start instead.

- On timeout the transaction now proceeds unlocked with a warning rather than
  throwing. The lost-update race it guards was unguarded before this branch, so
  degrading to the old best-effort behaviour beats failing `analyze`/`list`/
  `index` outright — none of which wrap these calls in a handler — on a wedged
  lock.

- `adoptFlatBranchLabel`'s recursive `fs.rm` no longer runs inside the lock;
  only the closing re-read/mutate/write does, mirroring `clean.ts`, which
  deletes the branch directory before calling the locked `removeBranchIndex`.
  A slow delete no longer blocks every registry operation on the machine.

* test(registry): cover the remaining locked mutators and the colliding layout

Three of the five functions the registry lock wraps had no overlap coverage, so
a future narrowing of the lock would go unnoticed. Adds:

- overlapping `removeBranchIndex` calls on two branches of one entry,
- an overlapping `unregisterRepo` / `registerRepo` pair on distinct repos,
- a registration issued while an index lock is held on the global directory,
  which reproduces the home-rooted self-contention the lock namespace fix
  addresses.

Each fails without the corresponding fix: the two overlap tests lose an update
when `withRegistryLock` is bypassed, and the collision test sees the wait
announcement and the degraded-write warning once the lock namespace is reverted
to `getGlobalDir()`. The collision test asserts on those log records rather
than on elapsed time, so it stays deterministic on a slow runner.

* perf(registry): keep the validation walk out of the registry lock

`listRegisteredRepos({ validate: true })` held the global lock across its
read-only validation walk — an `fs.access` per entry, slow on a network mount
or a large registry — even though the common case prunes nothing and writes
nothing. That is the same lock `gitnexus augment` takes on every editor tool
call, so unrelated registry work serialized behind a walk that never touched
the file.

The walk now runs unlocked; the lock is taken only when an entry is provably
gone, and the prune is applied to a snapshot re-read inside it, so a
registration that lands during the walk is no longer clobbered by a stale
write. Same shape as the `adoptFlatBranchLabel` split.

---------

Co-authored-by: Gergő Magyar <gergomagyar@icloud.com>
Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com>
2026-08-01 08:47:14 +01:00
..
bench fix: batch query enrichment, bake FTS extension into CLI image, add FTS memory repro (#2108) 2026-06-09 08:46:46 +01:00
spikes feat(ingestion): M0 — taint/PDG substrate (schema + seams + spikes) (#2080) (#2092) 2026-06-08 18:56:10 +01:00
assert-publish-grammar-coverage.cjs fix(grammars): load vendored tree-sitter grammars from vendor/ by absolute path (#2111) (#2144) 2026-06-10 14:20:42 +01:00
bench-scope-resolution.ts refactor(ingestion): delete legacy call-resolution DAG + heritage processor (RING4-1, #942) (#2023) 2026-06-04 11:07:37 +01:00
build-tree-sitter-grammars.cjs fix(grammars): load vendored tree-sitter grammars from vendor/ by absolute path (#2111) (#2144) 2026-06-10 14:20:42 +01:00
build.js fix(build): skip build.js when running outside the monorepo (#1795) (#1816) 2026-05-25 15:31:11 +01:00
cross-platform-tests.ts fix: serialize global registry transactions across processes (#2716) 2026-08-01 08:47:14 +01:00
ensure-fts.ts fix(analyze): load VECTOR before the incremental writeback touches embedding rows (#2623) (#2624) 2026-07-22 12:27:00 +01:00
install-duckdb-extension.mjs fix(fts): diagnose Windows FTS missing-dependency load failures (#2374, Phase 1) (#2383) 2026-07-06 21:27:37 +01:00
run-cross-platform.ts ci(tests): widen the Windows shard watchdog and keep exit diagnostics (#2449) 2026-07-16 12:29:01 +01:00
shard-arg.ts fix(ci): shard platform-sensitive matrix + spawn built CLI to fix Windows cross-platform timeout (#2394) 2026-07-08 09:09:11 +01:00
sync-plugin-manifests.mjs feat(skills): GitNexus Engineering Tool Kits (#2566) 2026-07-19 15:07:24 +01:00