memorix icon indicating copy to clipboard operation
memorix copied to clipboard

Observations from alias-merged projects are invisible to search: canReadObservation ignores the alias fan-out

Open chenshuangci opened this issue 1 month ago • 2 comments

Environment

  • memorix 1.9.9 (npm CLI + background control plane), Windows 11
  • Store with ~40k observations; project registry has alias groups (one canonical project id with many local-clone / git-worktree aliases in .project-aliases.json)

What happens

After folding many local clones and git worktrees of the same repo into one alias group (canonical media/x-spider + 29 aliases such as local/x-spider-master, local/t583, ...), searchObservations still cannot return any row that was stored under an old alias projectId:

  • resolveAliases correctly expands the canonical into the full alias set, and the fan-out reaches the lexical layer — the exact SQL that searchObservationLexically builds (quoted phrase + projectId IN (<all 29 aliases>) + active status) returns the expected rows, with the migrated record as top hit.
  • The final visibility filter then kills every cross-alias row. With a temporary probe (console.error patched into canReadObservation, reverted afterwards):
reader.projectId  = 'media/x-spider'         // canonical, derived from cwd
record.projectId  = 'local/x-spider-master'  // old alias, stored on the row
sameProject       = false
if (visibility === "project") return !reader.projectId || sameProject;   // → false

15 fan-out hits → 0 results returned.

Expected

The visibility check should resolve the reader's alias group (or compare against the same resolved projectId set the fan-out used), so rows stored under merged aliases become readable after a registry merge.

Impact

Registry-level merging alone never restores searchability of rows stored under old projectIds. Combined with the startup auto-migration being a no-op on large corpora (companion report), those rows are permanently unreachable without a manual SQLite rewrite — which is what I ended up doing (17,670 observations rewritten across 19 tables, after which the same query returns the record as top hit).

Workaround

Manual SQL migration rewriting projectId to the canonical across all tables (mind the unique keys that include projectId, e.g. code_files(projectId, path)).

chenshuangci avatar Oct 08 '26 04:10 chenshuangci

Companion report (the second half of the same failure mode): #323 - startup migrateProjectIds never runs on large corpora, so rows keep their old projectIds in the first place.

chenshuangci avatar Oct 08 '26 04:10 chenshuangci

The alias visibility regression is fixed in PR #331.

Persistent and in-memory search now pass the resolved alias set to the project visibility check, so observations stored under merged legacy project IDs remain readable within that alias group. The branch includes a focused visibility regression and large-store search coverage.

AVIDS2 avatar Oct 12 '26 15:10 AVIDS2