Repository navigation
Description
Summary
When two entities share a title / base permalink (e.g. an original note plus a -1 duplicate), passing a non-exact identifier (a title, or a file-path-like/fuzzy string) to read_note / edit_note / move_note resolves to the wrong entity — typically the one with the shorter/alphabetically-earlier file_path, regardless of which file physically exists. An exact permalink always resolves correctly.
This is a latent resolver bug that surfaces whenever duplicates exist (see the cloud move_note ghost-duplicate report, basicmachines-co/basic-memory-cloud, which reliably creates such duplicates).
Root cause
All three tools funnel through LinkResolver (src/basic_memory/services/link_resolver.py:242-427). For a non-exact identifier the order is: external-id/UUID → exact permalink candidates → exact title → file_path → file_path+.md → fuzzy (strict-gated).
When the exact-permalink step misses and it falls to the title step, the winner among same-title rows is chosen by EntityRepository.get_by_title (src/basic_memory/repository/entity_repository.py:149-155):
.where(Entity.title == title)
.order_by(func.length(Entity.file_path), Entity.file_path)resolve_link then returns found[0] (link_resolver.py:373-374). There is no LIMIT, no tie-break on recency, and no check that the file physically exists — selection is purely (len(file_path), file_path). So when an original + a -1 duplicate coexist, a non-exact identifier deterministically resolves to whichever has the shorter/earlier path (often a stale/archived original), not the note the caller means.
Exact permalinks work because the permalink step (link_resolver.py:356-364) short-circuits before the title tie-break is reached.
Related: file_path-based resolution (link_resolver.py:378-398 → entity_repository.py:157-166) matches on the stored file_path column by exact equality, so a stale file_path row is also a resolution target for a path-like identifier — again with no physical-existence check.
Impact
Unattended agents (and users) that address notes by title or path can silently read/edit/move the wrong entity once any duplicate exists. Corrupts automated archival/ingest flows.
Suggested direction (not prescriptive)
Make resolution deterministic and existence-aware when multiple same-title/same-permalink-base candidates exist: prefer the entity whose file currently exists (or whose file_path is current), and/or apply a stable, documented tie-break rather than shortest-file_path-wins. Consider surfacing ambiguity instead of silently picking one.
Evidence (file:line)
- Resolution order:
src/basic_memory/services/link_resolver.py:242-427(permalink356-364; title→found[0]367-376; file_path378-398; strict/fuzzy gate400-424). - Title tie-break query:
src/basic_memory/repository/entity_repository.py:149-155. - Exact file_path match:
src/basic_memory/repository/entity_repository.py:157-166. - Where
-1duplicates come from (permalink collision):src/basic_memory/services/entity_service.py:456-465.
Workaround
Address notes by exact permalink or external_id/UUID only.
Activity
claude commentedon Jul 24, 2026
Claude finished @jope-bm's task in 1m 41s —— View job
Triage complete
Code verification: Confirmed accurate against current
main.link_resolver.py:367-376— non-exact resolution falls through permalink → exact title, and returnsfound[0]with no existence check or tie-break beyond ordering.entity_repository.py:149-155—get_by_titleorders candidates byfunc.length(Entity.file_path), Entity.file_path(shortest-path-wins), noLIMIT, no recency/existence signal.entity_repository.py:157-166—get_by_file_pathdoes exact-equality lookup on the stored column, same lack of existence check.entity_service.py:456-465— confirms-1suffixing on permalink collision as the duplicate source.This is a real, reproducible latent bug: any time two entities share a title/base permalink, a non-exact identifier passed to
read_note/edit_note/move_notedeterministically resolves via shortest/alphabetically-firstfile_path, independent of which file currently exists or was intended. Exact permalink/UUID lookups are unaffected, which matches the documented workaround.Duplicate check: No existing open or closed issues in this repo cover this resolver behavior (searched for "resolve wrong entity duplicate permalink", "link_resolver duplicate", "get_by_title" — no hits). The related cloud "ghost duplicate" report lives in
basicmachines-co/basic-memory-cloud, a different repo, so not a duplicate here — this issue captures the underlying core-repo root cause.Classification:
link_resolver.py,entity_repository.py) — spans MCP tools (read_note,edit_note,move_note) and the repository/database layerLabels: Applied
bug.enhancement,documentation,question,cloud, andduplicateto this issue before confirming they didn't fit — none of those apply here. The labeling tool available to me only supports adding labels, not removing them, and I don't have permission to run rawghlabel-removal commands. Could a maintainer manually removeenhancement,documentation,question,cloud, andduplicatefrom this issue, leaving onlybug? Apologies for the noise.Per triage scope, I'm stopping here without implementing a fix, per the scope boundary in my instructions.
fix(core): address Codex review — exact path wins, relation repair su…
fix(core): reject ambiguous title before its slugified permalink can …
test(api): cover the ambiguous-identifier 409 transport (#1148)