Skip to content

Add memory project/path consistency: doctor check + shared-replace guard#50

Merged
Kashkovsky merged 2 commits into
mainfrom
memory-project-path-hygiene
Jul 1, 2026
Merged

Add memory project/path consistency: doctor check + shared-replace guard#50
Kashkovsky merged 2 commits into
mainfrom
memory-project-path-hygiene

Conversation

@Kashkovsky

Copy link
Copy Markdown
Owner

Summary

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 (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: storeSharedMemoryReplacement updates a shared memory in place at its existing targetUri but built the frontmatter from options.metadata.project ?? inferred.project — so a caller passing a different project produced 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.md ended up tagged project: mobile-native.

  • storeSharedMemoryReplacement now takes project/topic from the storage path (inferred wins 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.
  • 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. Compares via uriSegment so case/slug normalization is not a false positive; skips project-less kinds (preferences, smoke), absent-project memories (the general default), directory nodes, and summary sidecars.
  • New pure helpers in utils.ts: memoryUriProjectSegment (de-scopes shared team paths, handles durable/handoffs/incidents) and memoryFrontmatterField.

Test plan

npm run test        # 315 pass (25 files); +10 covering the URI/frontmatter
                    # helpers, the shared-replace path-wins guard + warning,
                    # and the doctor check (clean / drift / no-dir cases)
npm run typecheck   # clean (root + test/tsconfig.json)
npm run lint        # clean

Ran threadnote doctor against the live corpus — the check found exactly the one real divergence and nothing else:

WARN memory project consistency: 1 memory(ies) whose frontmatter project differs
from their storage path; re-store under the correct project to fix:
.../shared/docs-desktop/durable/projects/coda/docs-desktop-pagerduty-onboarding.md
(frontmatter "mobile-native" vs path "coda")

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.
@Kashkovsky Kashkovsky merged commit c4cdd44 into main Jul 1, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant