Skip to content

fix: compare .gitmem roots by real path, not string (GIT-107) - #45

Merged
2 commits merged into
mainfrom
bugfix/GIT-107-realpath-roots
Sep 22, 2026
Merged

2 commits merged into
mainfrom
bugfix/GIT-107-realpath-roots

Conversation

@nTEG-dev

Copy link
Copy Markdown
Member

What

.gitmem roots are compared by real path, not by string (GIT-107).

  • canonicalPath() resolves a path with fs.realpathSync.native. A path that doesn't exist yet (e.g. a destination before its first write) resolves through its nearest existing ancestor, so /var/x/.gitmem and /private/var/x/.gitmem agree even before .gitmem exists. sameDirectory(a, b) compares two paths that way.
  • findStrandedProjectRoots() uses it. A candidate is also excluded when it's the same directory as an explicit GITMEM_DIR, since that's the root actually being read; before, only the home root was checked.
  • migrate-root's "source and destination are the same" check uses it too.

Why

On macOS /var is a symlink to /private/var. process.cwd() reports /private/var/…, while a home or GITMEM_DIR under $TMPDIR is spelled /var/…. The string comparison saw two stores, and session_start told the user their live store wasn't being read. Reproduced on every main venue run, where the driver's store lives under $TMPDIR:

Memory store found but NOT being read
  /private/var/folders/…/gitmem-venue-baseC-main-flow-QTZRrm/.gitmem
    holds: 3 threads, 1 sessions
  gitmem reads /var/folders/…/gitmem-venue-baseC-main-flow-QTZRrm/.gitmem regardless of directory (1.8.0).

How to test

Venue (v1.8.0 setup.sql, vujndhcumgroztfkkdus; production not touched): flow now fails if session_start shows the notice, since the driver creates no stranded store. main: exit 1 ("reported the store it reads as 'NOT being read'"). This branch: exit 0.

Unit tests: 1279/1279 pass (+5, gitmem-root-symlink.test.ts):

  • home reached through a symlink, cwd spelled resolved → not stranded;
  • a genuinely different live store → still reported;
  • GITMEM_DIR naming the project store → not stranded;
  • sameDirectory with a symlink, a trailing slash, . segments and not-yet-existing leaves;
  • macOS /var vs /private/var (skipped where $TMPDIR has no symlink, e.g. Linux).

4 of 5 fail on origin/main; "a different store is still reported" passes on both, as it should. No existing test encoded the old behaviour.

Checklist

  • npm run test:unit passes (1279)
  • New tests added (symlink, plus the macOS case)
  • No schema change; verified on a v1.8.0 store
  • Docs: n/a

Breaking changes

None.

🤖 Generated with Claude Code

Claude and others added 2 commits September 21, 2026 20:52
findStrandedProjectRoots compared candidate and home as strings. On macOS
/var is a symlink to /private/var: process.cwd() reports /private/var/... and a
home or GITMEM_DIR under $TMPDIR is spelled /var/..., so session_start showed
"Memory store found but NOT being read" about the store it was reading. Any
symlink in either path did the same.

- canonicalPath() resolves with fs.realpathSync.native; a path that does not
  exist yet resolves through its nearest existing ancestor.
- A candidate is not stranded if it is the same directory as the home root or
  an explicit GITMEM_DIR (the root actually being read).
- migrate-root's "source and destination are the same" check uses it too.

+5 tests (symlinked home, a different store still reported, GITMEM_DIR,
sameDirectory spellings, and the macOS /var case); 4 fail on origin/main.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The driver's store lives under $TMPDIR, so 1.10.0 shows the notice on every
macOS run (exit 1); exits 0 with the fix.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@nTEG-dev nTEG-dev closed this pull request by merging all changes into main in f93c3a3 Sep 22, 2026
neoneye pushed a commit to agent-memory-atlas-archive/gitmem-dev--gitmem that referenced this pull request Sep 22, 2026
Conflicts (blank-supabase.mjs): all result fields and all checks kept.
migrate-root.ts auto-merged (gitmem-dev#43's merge + gitmem-dev#45's sameDirectory). tsc clean.
@nTEG-dev
nTEG-dev deleted the bugfix/GIT-107-realpath-roots branch September 23, 2026 05:49
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