agentmemory icon indicating copy to clipboard operation
agentmemory copied to clipboard

`infer-memory-projects` permanently unfixable after a project directory move — path-keyed project identity marks every memory ambiguous

Open tr3lane opened this issue 4 months ago • 0 comments

Package: @agentmemory/agentmemory 0.9.28 (current latest on npm) Deployment: Docker, image agentmemory-combined, network_mode: host Store: file-based KV (iii-state, store_method: file_based)

Summary

Project identity appears to be keyed on the raw session cwd string. If a project directory is ever moved — or accessed via a git worktree — the same logical project fragments into multiple identities. Memories whose sessionIds span the move then look like they belong to several projects at once, and infer-memory-projects marks every one of them ambiguous, forever.

There is no override, so the condition is permanently unfixable through the public API, yet memory_diagnose reports it as fixable: true and directs the operator to run a command that provably cannot change anything.

Reproduction / evidence

My instance has 832 sessions and exactly one logical project. Distinct project values across those sessions:

  656  'V:\MyProject'                                       <- current location
  172  'D:\Dropbox\MyProject'                               <- previous location
    1  'C:\Users\<user>\Dropbox\MyProject'                  <- older location
    1  'V:\MyProject\.claude\worktrees\interesting-sanderson-6cfa2d'
    1  'V:\MyProject\.claude\worktrees\nostalgic-williams-0dfa48'
    1  'V:\MyProject\.claude\worktrees\wonderful-antonelli-4080c3'

Six spellings, one project. Two causes: the directory was relocated twice, and git worktrees register as separate projects.

The migration therefore resolves nothing:

$ curl -s -X POST http://127.0.0.1:3111/agentmemory/migrate \
    -H 'Content-Type: application/json' \
    -d '{"step":"infer-memory-projects","dryRun":true}'

{"ambiguous":379,"skipped":0,"step":"infer-memory-projects","success":true,"updated":0}

379 of 379 ambiguous, 0 updated. Running it for real would be identical — nothing can be inferred, because every memory spanning the move sees ≥2 distinct project strings.

For context, the affected memory objects carry no project key at all (they predate the field):

FIELDS: concepts, content, createdAt, files, id, isLatest, sessionIds,
        sourceObservationIds, strength, supersedes, title, type, updatedAt, version

They do carry sessionIds, and the sessions carry project — so the join data exists. It's the identity model, not missing data, that blocks the backfill.

Secondary issue: fixable: true on an unfixable check

memory_diagnose reports:

{
  "category": "memories",
  "name": "memory-project-coverage",
  "status": "fail",
  "fixable": true,
  "message": "372 of 372 latest memories have no project scope — run POST /agentmemory/migrate {\"step\":\"infer-memory-projects\"} to backfill"
}

The suggested remedy is a guaranteed no-op in this state. memory_heal doesn't address it either ({"fixed":0,"skipped":0,"details":[]}), so an operator following the guidance runs a command, sees nothing change, and has no indication why. A check that can't be fixed by its own stated fix shouldn't advertise fixable: true.

Suggested fixes

  1. Normalize project identity rather than keying on the raw path — e.g. canonical basename, a stable project id recorded at first use, or an explicit alias/registry mapping several paths to one project.
  2. Treat <project>/.claude/worktrees/* as the parent project, since worktrees are the same codebase by definition.
  3. Give infer-memory-projects an override, e.g. {"step":"infer-memory-projects","defaultProject":"..."} or resolveAmbiguousTo. In cases like mine the correct answer is unambiguous to the operator even though the heuristic can't derive it — there's currently no way to say so.
  4. Make the diagnostic honest: only set fixable: true when the fix would actually change something; otherwise downgrade to warn with an explanation, or have the migration report why entries were ambiguous (e.g. "spans projects: A, B").

Impact

Low for single-project users like me — with only one project, unscoped memories appearing in "every project's context" is harmless in practice. It becomes real as soon as a second project shares the instance: memories that should be scoped never will be, and there's no supported path to correct them.

Happy to supply more detail or test a patch.

tr3lane avatar Jul 21 '26 09:07 tr3lane