Repository navigation
fix(wiki): give the Wiki CLI the code graph, and fix the drift verdicts it exposed (#232) - #263
Merged
theyashasvipandey merged 6 commits intoOct 3, 2026
Conversation
…graph (mex-memory#232) wikiRebuildIndex dropped the graph it was handed, and the post-write index refreshes of apply, regenerate-views and migration never received a resolver, so every row they wrote stored NULL health even when a graph was available. Thread one resolver from the supplied graph through rebuild, refresh and every post-write refresh, and add a two-phase wikiPrepareRebuildIndex for callers that must prove a graph snapshot fresh before publishing.
A declared id answered through a compatibility alias (ids re-minted by mex-memory#240) or rebound by reconciliation was always judged by fingerprint. The re-mint renumbers neighbour ids inside the fingerprint, so groundings whose code had not changed by one byte resolved changed, while mex check, comparing bodies, called them fresh. A body equal to the committed hash now resolves fresh; a body that differs is still judged by structure, so a rename stays fresh.
…ring migration Migration's bodyHash backfill took the current node's hash for any legacy grounding whose node still resolved. It never ran from the CLI, which gave it no graph; once it does, that rule would make every drift since grounding permanently invisible. Take the baseline mex ground cached for that scaffold file when its fingerprint is the committed one, otherwise the current body only for the declared node whose fingerprint still matches, and otherwise write none, the same evidence the capture path's legacy backfill uses.
…ex-memory#232) The Wiki CLI built its service options without a graph, so wiki validate always reported codeGraphAvailable: false, wiki rebuild-index stored no health, migrate never backfilled a bodyHash and apply could not ground. validate, rebuild-index, migrate, apply and regenerate-views now reach the graph through the repository graph port, as the Project Hub does: one revocable snapshot per command, re-proved fresh before anything derived from it is reported. rebuild-index publishes through the two-phase publication, so it never stores health from a graph that changed under it. A stale, incompatible, corrupt or moving graph falls back to the no-graph path and says so with a CODE_GRAPH_UNAVAILABLE notice; a checkout with no graph stays quiet, and a caller that supplied no bridge is never reported as a checkout without one.
…eighbours Without a committed bodyHash the Wiki compares fingerprints, and it compared the whole value, neighbour ids included. Those change when a caller elsewhere is added or ids are re-minted (mex-memory#240), so groundings whose every token was unchanged resolved changed. On a populated scaffold built before mex-memory#240, three entities read changed with identical MinHash signatures and token counts. Compare the sketch and token count alone for the change verdict; identity checks keep the full fingerprint.
7 of 8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The Wiki commands that resolve groundings now use the code graph. Before this, they ran without one, even in a checkout with a fresh
graph.db:wiki validatealways reportedcodeGraphAvailable: false.wiki rebuild-indexstored NULL health for every entity, so--health changedmatched nothing.wiki migratenever backfilledbodyHash.wiki applycould not ground.validate,rebuild-index,migrate,applyandregenerate-viewsnow reach the graph the way the Project Hub does: through the repository graph port, with one revocable snapshot per command. The snapshot is proved fresh again before anything derived from it is reported.rebuild-indexuses the port's two-phase publication, so it never stores health from a graph that changed while it was being built.CODE_GRAPH_UNAVAILABLE, which says why and namesmex graph.Once the graph was wired in, four faults it had been hiding surfaced. Each has its own commit:
5435b8a).wikiRebuildIndexdropped the graph it was given, and the post-write refreshes of apply, migrate and regenerate-views had no resolver. One resolver now goes through rebuild, refresh and every post-write refresh.dcecd99). It wrote the current body hash for any legacy grounding whose node resolved, which permanently hides any drift since grounding. It now uses the same evidence order as capture's legacy backfill:mex groundcached, when its fingerprint is the committed one;33abbbe). A grounding reached through a compatibility alias (TypeScript node ids change with the checkout directory: groundings and mex:// anchors don't survive a clone to another path #240), or rebound by reconciliation, was judged by fingerprint, and the re-mint renumbers neighbour ids. A body byte-identical to the committed hash now resolves fresh. A body that differs is still judged by structure, so a rename stays fresh.4802782). A grounding with nobodyHashwas compared on the whole fingerprint, neighbour ids included. Those change when a caller elsewhere is added or ids are re-minted. The change verdict now compares only the MinHash sketch and token count, via the newsameFingerprintCode. Identity checks keep the full fingerprint.Why
Closes #232.
Type of change
How to test
mex graph, thenmex wiki validate --json. ExpectcodeGraphAvailable: true,groundingsUnverified: false, andGROUNDING_STALEfor any drifted grounding.mex wiki rebuild-indexand thenmex wiki list --health changed. The drifted entities are listed.mex graph, then runmex wiki validate. ExpectCODE_GRAPH_UNAVAILABLE("out of date with the source") and no verdicts.mex graph, thenmex wiki validateagain. The edited grounding reportsGROUNDING_STALE, andmex checkreportsGROUNDING_DRIFTfor the same node.Measured on two populated scaffolds:
mex check: 7 groundings fresh. After editing#dispatch, both groundings on it were flagged by validate, the index and check. Before fix 3, 2 entities there read changed with byte-identical bodies.mex check.New tests:
src/wiki/service/__tests__/grounding-health.test.ts: rebuild, prepared rebuild (commit and discard), and refresh health.src/wiki/cli/__tests__/grounding.test.ts: fresh, stale, missing and moving graphs for validate and rebuild-index; a write is never run twice; a read is re-run without the graph; unexpected bridge errors are rethrown.src/wiki/migration/__tests__/grounding.test.ts: historical-baseline backfill, and no backfill without evidence.src/wiki/grounding/__tests__/resolve.test.ts: alias with an identical body, and a neighbour-only fingerprint change.src/graph/__tests__/fingerprint-encoding.test.ts:sameFingerprintCode.diagnostic-coverage.test.ts: emitsCODE_GRAPH_UNAVAILABLE.Checklist
npm test), apart from failures that also occur on stockmainon this Windows machine. Full suite: 4,345 passed, 31 failed.maind0d402b, same results:wiki-sweep.test.ts(script import);cli-agent.test.ts(EPERM).migrate.test.ts30 s timeouts;concurrency.test.ts"answers reads correctly while a refresh is in flight".main: the remaining failures are in Team, setup and release-benchmark, which this PR doesn't touch.Compatibility.
CODE_GRAPH_UNAVAILABLEis a new Wiki diagnostic code, at info severity.wiki validatecan now reportGROUNDING_STALE,GROUNDING_MISSINGandGROUNDING_UNRESOLVEDon scaffolds where it reported none. All are warnings, so its exit status is unchanged. Index and graph schemas are unchanged. Runmex wiki rebuild-indexonce to record health in an existing index.Not in this PR.
wiki build/prepare/propose(synthesis) still opengraph.dbdirectly, without the freshness proof. This is recorded in the scaffold ROUTER.Code-graph changes
mainLanguageExtractororFrameworkResolverinterfacecore / discuss-firstissue is linked aboveNo extractor, resolver, identity, reconciliation or schema change. The only graph-side addition is the read-only helper
sameFingerprintCodeinsrc/graph/fingerprint.ts. The drift-semantics changes are on the Wiki side (fixes 3 and 4), and each makes the Wiki agree withmex checkwhere the two disagreed. They are linked to #232 here rather than to a separate discuss-first issue.