fix(grounding): read root grounds_to beside a mex map and consolidate on write (#226) - #242
Merged
Merged
Conversation
… on write (#226) check and wiki for-code read both grounding stores; writes, wiki migrate and set-grounding fold root groundings into the file-level entity's mex.grounds_to, never a section. Report GROUNDING_MIXED_SHAPE (info, warning on a same-node conflict). Setup no longer produces the shape.
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.
Closes #226.
Problem
A file could keep groundings both in a root
grounds_toand undermex.grounds_to, and setup produced that shape itself: population writes root groundings, then Wiki migration gives multi-entity files amex:map without moving them.checkthen read onlymex.grounds_toandwiki for-codedropped the root entries.Change
extractGroundingsreturns both keys, deduplicated by node. On a same-node conflict themex.grounds_toentry is returned. The rule lives insrc/wiki/markdown/grounding-stores.ts, shared bycheckand the Wiki codec.writeGroundingson a mixed file moves root entries undermex.grounds_toand removes the root key in a single edit; the rest of the file is byte-identical and a second write is a no-op. A root entry that was not in effect (a conflict, or one that fails validation) stays at the root rather than being deleted.set-groundingoption,absorbRootGroundings, which moves existing values without re-deriving them from the graph, so oldbodyHashbaselines survive. It is refused on a section entity and if it would change the groundings it moves. An ordinaryset-groundingnow replaces the root key too.checkandwiki validatereportGROUNDING_MIXED_SHAPE: info for a split, warning for a same-node conflict. Thecheckside needs no graph.mex graph groundprompts say to write undermex.grounds_toonce a file has amex:map; the migration change stops setup producing the shape.Survey (real scaffolds, before → after)
checkwiki for-codefor-codewas measured with both CLI builds on copies;checkcounts apply the old and new read rules and are confirmed on Hono by the drift run below. The remaining root groundings are in files with no file-level entity (a decisions log with only section entities, and custom context files migration never adopted).checkreads them; the Wiki can't attach them without guessing a section.CLI reproduction (Hono copy)
Edited the body of
compose()and a comment insideerrorHandler, refreshed, ranmex check:GROUNDING_DRIFTonly inpatterns/debug-request-pipeline.md.context/architecture.mdandcontext/conventions.md, plus infoGROUNDING_MIXED_SHAPEfor both.wiki migratethen moved the 4 split groundings, kept their originalbodyHash(drift still reported),wiki validateno longer reports the shape, and a second migrate changes no bytes.Tests
test/grounding-mixed-shape.test.ts(22 tests) and 4 operation tests: extraction on root-only, mex-only, mixed, duplicate and conflict; consolidating writes (byte-identical, idempotent, CRLF); thecompose()/errorHandlerdrift scenario against a real graph;for-codeattaching to the file-level entity only; migration of adopted files including conflict and malformed entries; setup finalization leaving no mixed file.legacy/grounds-to-single.mdnow expectsGROUNDING_MIXED_SHAPE, and the adversarial tier-3 test now expects a file-level move (the old "left at the root" assertions cover a section-only file).Accepted cost
The first write to a split file moves its root groundings and, on an adopted file, bumps the entity revision, so that file shows a frontmatter diff. A file-level entity now also carries the file's root groundings.