Add memory project/path consistency: doctor check + shared-replace guard#50
Merged
Conversation
Recall scopes and boosts by the project segment in a memory's storage path, so a memory whose frontmatter project disagrees with that path ranks under the wrong project. Item 8 of the recall relevancy audit. - storeSharedMemoryReplacement keeps project/topic from the storage path on an in-place shared update (the file stays at targetUri) and warns when a caller requested different ones. This was the drift source: the frontmatter took the caller's project while the file stayed at the old path. - new "memory project consistency" doctor check walks the on-disk memories tree and reports any memory whose frontmatter project differs from its path project segment. Read-only; the fix is to re-store under the correct project. - pure helpers memoryUriProjectSegment / memoryFrontmatterField in utils.
…walk - storeSharedMemoryReplacement makes only the project path-authoritative; topic keeps caller-wins to avoid persisting a raw multi-segment (a/b) path or firing a spurious drift warning (warnOnSharedMetadataDrift -> warnOnSharedProjectDrift). - memoryProjectConsistencyCheck wraps the per-file read in its own try/catch so a file removed mid-walk (concurrent forget/compact/archive) no longer aborts the whole check; simplify the '+N more' arithmetic. - memoryFrontmatterField restricts the value to [ \t] so a bare "project:" line cannot swallow the next header field. - tests: drift-warning suppression, frontmatter empty/prefix/trailing-ws boundaries, doctor skip of non-.md/sidecar/unreadable entries, incidents kind, and the '+N more' truncation branch.
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.
Summary
Recall scopes and boosts by the project segment in a memory's storage path, so a memory whose frontmatter
projectdisagrees with that path ranks under the wrong project (or misses a project-scoped pass). Item 8 from the recall relevancy audit: prevent the drift at its source and detect any that already exists.Detail
Root cause of the drift:
storeSharedMemoryReplacementupdates a shared memory in place at its existingtargetUribut built the frontmatter fromoptions.metadata.project ?? inferred.project— so a caller passing a differentprojectproduced a file that stays under the old path while its frontmatter claims the new project. That is exactly how.../shared/docs-desktop/durable/projects/coda/docs-desktop-pagerduty-onboarding.mdended up taggedproject: mobile-native.storeSharedMemoryReplacementnow takes project/topic from the storage path (inferredwins over a differing caller value) and warns, since the file stays put. Changing a shared memory's project means relocating it (forget + store anew), not editing frontmatter at the old path.memory project consistencydoctor check walks the on-disk memories tree and reports any memory whose frontmatterprojectdiffers from its path project segment. Read-only. Compares viauriSegmentso case/slug normalization is not a false positive; skips project-less kinds (preferences, smoke), absent-projectmemories (thegeneraldefault), directory nodes, and summary sidecars.utils.ts:memoryUriProjectSegment(de-scopes shared team paths, handles durable/handoffs/incidents) andmemoryFrontmatterField.Test plan
Ran
threadnote doctoragainst the live corpus — the check found exactly the one real divergence and nothing else: