No supported way for external tooling to edit registry.json under the registry lock
Area
gitnexus (CLI / core / indexing / MCP server)
Problem or opportunity
Summary
~/.gitnexus/registry.json is a machine-global file that gitnexus now guards properly for its own writes — withRegistryLock around read/merge/write, writeFileAtomic, a hard registry is corrupt error instead of a silent fallback. That part is solid, and this issue isn't about a bug in it.
The gap is that there is no supported way for anything outside gitnexus to participate in that lock. External tooling that needs to edit the registry — git hooks, cleanup scripts, CI steps — has only two options, and both are bad:
- Reimplement the lock protocol by hand (
registry-lockdirectory,O_EXCLpidfile, holder metadata, stale-holder reclaim). Getting stale reclaim subtly wrong is worse than not locking, because it can steal a live holder's lock. - Write the registry unlocked and accept a lost-update race against a concurrent
analyze.
Neither is something a hook author should be choosing between.
Context
The concrete case is a post-merge hook that reclaims dead per-branch index slots (companion issue). It has to remove entries from branches[], so it does a read-modify-write of registry.json from Python with an atomic os.replace — correct in isolation, invisible to withRegistryLock. With several repositories on one machine analyzing concurrently (a hook in each), that write races gitnexus's own registry transaction.
The lock lives in dist/storage/index-lock.js and is internal, so the protocol isn't something external code can depend on staying stable across releases.
Proposed solution
Asks
Either would resolve it, roughly in preference order:
- A CLI verb that performs the mutation under the lock. For the case above that's something like
gitnexus registry prune-branches --repo ., but the general shape — any registry edit going through gitnexus rather than through a third-party file write — is the point. This is the version that keeps the protocol private. - Document the lock protocol as a supported contract: the lock directory's location, the pidfile format, the holder fields, the staleness rule, and the timeout semantics. Enough that a shell or Python hook can take the lock correctly and stay correct across releases.
If the companion branch-slot pruning issue is implemented, this stops being a problem for that particular hook — nothing external would need to write the registry at all. Filing it separately because the general question (how should third-party tooling mutate the registry safely?) outlives that one use case.
Environment
gitnexus 1.6.12, Node v24.18.0, Linux x86_64.
Alternatives considered
No response
Acceptance criteria
No response
Constraints
No response
Contribution
- I am willing to open a PR for this (may need design discussion first).
Source: abhigyanpatwari/GitNexus