community icon indicating copy to clipboard operation
community copied to clipboard

[v0.10.44][bug] Space identifier resolves by name before exact id/key — ghost spaces cannot be merged, deleted, or listed; spaces delete is a footgun

Open Smith-106 opened this issue 4 months ago • 4 comments

Summary

When a space's display name happens to equal another space's internal id/key, every endpoint that accepts a space identifier resolves the value by name first, so it is impossible to address the space whose id equals that string. This blocks spaces merge, spaces delete, spaces update, memories bulk/move, and GET /memories?space_id= from operating on the "id-only" space — they all silently target the name-matched space instead. The only operation that escapes this is PATCH /memories/{memory_id} (it keys on memory id, not space).

Concrete effect: "ghost" space profiles (created with a Chinese display string as both id and name, while a sibling space-N space was later given the same display name) cannot be merged or deleted — every attempt resolves to the sibling and reports 422 Choose a different target space (merge) or would delete the sibling's data (delete dry-run resolves to the wrong space).

Environment

  • nmem CLI + server: v0.10.44 (Windows 11, local mode, http://127.0.0.1:14242)
  • Spaces present (excerpt from GET /spaces):
    • {id:"space-3", key:"space-3", name:"钢之炼金术师", memories:189, ...} ← "real" space, has the Chinese display name
    • {id:"钢之炼金术师", key:"钢之炼金术师", name:"钢之炼金术师", memories:0, ...} ← "ghost" space, id == the other's name

Reproduction

# 1. merge preview — source and target both resolve to space-3 → 422
POST /memories/bulk/move/preview
body: {"selection":{"mode":"space","source_space_id":"钢之炼金术师"},"target_space_id":"space-3"}
→ 422 {"detail":"Choose a different target space."}

# same via CLI
nmem spaces merge 钢之炼金术师 --into space-3 --dry-run
→ 422 Choose a different target space   (both directions 422)

# 2. delete dry-run resolves to the WRONG space (the name-matched sibling, not the id-only ghost)
nmem spaces delete 钢之炼金术师 --dry-run
→ resolves to {id:"space-3", memories:189, ...}   ← would delete 189 real memories!

# 3. listing memories of the ghost space is impossible
GET /memories?space_id=钢之炼金术师
→ 422 {"detail":"Unknown space. Use an existing space name, alias, or internal storage key."}

# 4. show/resolve by the Chinese string always lands on space-3
GET /spaces/钢之炼金术师  →  {id:"space-3", name:"钢之炼金术师"}
nmem spaces show 钢之炼金术师  →  id: space-3

Actual behavior

The space resolver matches name before an exact id/key match. When a string is simultaneously one space's name and another space's id, the name match wins everywhere a space_ref/space_id is accepted, so the id-only space is unreachable through any standard endpoint.

Expected behavior

An exact id/key match should take precedence over a name/alias match (or a separate explicit "by key" mode should exist). Otherwise identical-name spaces are unmanageable, and spaces delete <name> is a footgun that can delete an unrelated space's data.

What I checked / workaround

  • PATCH /memories/{memory_id} body {"space_id":"space-3"} works — it keys on memory id and does not go through the space-name resolver, so I used it to re-assign 279 orphaned memories off the ghost spaces one by one. This is the only viable path today.
  • GET /openapi.json → BulkMemorySelection supports mode:"space" + source_space_id, but the field is documented as "Target space name or storage key" and is resolved name-first, so it cannot target the ghost either.
  • kuzu main DB (nowledge_graph_v2.db) is held with an exclusive lock by the running server, so no external kuzu CLI workaround is available while the server runs.

Smith-106 avatar Jul 29 '26 11:07 Smith-106

收到。resolver 优先级应该是 exact id/key 先于 display name;现在 display name 抢先会让 ghost space 很难被精确寻址,这是删除/修复路径上的 footgun。这个会按解析优先级问题处理。

wey-gu avatar Jul 30 '26 09:07 wey-gu

更新:当前代码已经按这个 issue 的根因修了 resolver 顺序。Space reference 现在先在整个 roster 上匹配 exact id / key,再考虑 normalized id、display name、alias;不会再让另一个 Space 的 display name 抢掉真实 storage id。

已跑相关回归测试:exact_storage_identity_wins_over_another_spaces_name 通过。这个 issue 先保持 open,等带修复 build 在原环境验证后关闭。

wey-gu avatar Jul 30 '26 12:07 wey-gu

@Smith-106, could you verify the fix in your original Windows environment? The maintainer previously confirmed that exact id / key matches now take priority and kept this issue open for validation in that environment: fix explanation.

Please update to the 0.10.96 stable release. Also check the versions of the CLI and the server it connects to. Then test the name and ID collision from your report. If the original test Spaces no longer exist, you can use two test Spaces: the display name of one Space must equal the exact id / key of the other.

  1. nmem spaces show <exact-id> should return the Space with that exact ID, rather than the other Space with the matching display name.
  2. nmem spaces delete <exact-id> --dry-run should show the same exact target Space and its usage.
  3. nmem spaces merge <source-exact-id> --into <target-exact-id> --dry-run should identify the two Spaces correctly. It should no longer report Choose a different target space because both references resolve to the same Space.

Only queries and dry-run commands are needed. Please reply with the App, CLI, and server versions, and whether each step gives the expected result. If a step still fails, please include the command output with sensitive data removed. We can decide whether to close this issue after receiving the results from your original environment.

ThaddeusJiang avatar Oct 07 '26 11:10 ThaddeusJiang

Thanks for reporting this. The Space resolver has been fixed: an exact id or key match takes priority over another Space's display name. The regression test for that collision passed, as recorded in the maintainer's fix report:

https://github.com/nowledge-co/community/issues/874#issuecomment-6626509119

We are closing this issue based on the completed fix. We will not keep it open only to wait for another check in the original environment. This review did not run new Windows tests or check a published build. If the same problem occurs in your current version, please reply here with the App, CLI and server versions and the query or dry-run output with private data removed. We can reopen this issue.

ThaddeusJiang avatar Nov 05 '26 08:11 ThaddeusJiang