memorix icon indicating copy to clipboard operation
memorix copied to clipboard

fix(session): don't hijack projectRoot binding to a nested git subdirectory

Open Tom-Ma-Ming opened this issue 5 months ago • 0 comments

fix(session): don't hijack projectRoot binding to a nested git subdirectory

Problem

When two clients share the same Memorix store but connect over different transports, they can resolve the same directory to different projects, so they silently stop sharing memory.

Concretely:

  • A stdio memorix serve (e.g. Claude Code) starts already resolved to a project from its launch cwd.
  • A later memorix_session_start({ projectRoot: <that same repo> }) then binds the session to a nested/vendored git repo under the project root (e.g. local/<subdir>) instead of the project itself.
  • An HTTP-daemon client (which starts __unresolved__) binds the very same projectRoot correctly to the parent repo.

Result: the two agents think they're in different projects and never see each other's memories.

Root cause

In the memorix_session_start handler, switchProject(projectRoot) returns false in two distinct situations that were conflated:

  1. projectRoot is a valid git repo, but it's the already-bound project — a same-project no-op. This is success.
  2. projectRoot is not a git repo — only here should the workspace root be scanned for a git project in a subdirectory.

The handler treated both false cases as "not bound" and fell through to the findGitInSubdirs fallback, which bound the session to the first nested git repo it found. The same-project no-op (case 1) therefore got hijacked to a subdirectory whenever the resolved project root happened to contain a vendored git repo.

The HTTP path avoided this only incidentally: it starts unresolved, so the first switchProject performs a real switch (returns true) and never reaches the fallback.

Fix

Only fall back to the subdirectory scan when projectRoot itself is not a git repo. When it is a real repo, a false from switchProject means a same-project no-op (success) — never scan subdirs. The diagnostic resolution of projectRoot is done first to tell the two cases apart.

Test

Adds tests/integration/session-nested-subdir-binding.test.ts, which reproduces the hijack: a server started resolved to a parent repo (with remote) that contains a nested git repo (no remote). memorix_session_start({ projectRoot: <parent> }) must keep the parent bound and must not switch to local/<nested>.

Red before the fix, green after. Existing serve-http, tool-profile, and project-detector suites continue to pass.

Tom-Ma-Ming avatar Jun 11 '26 02:06 Tom-Ma-Ming