Skip to content

设计:全局 graph.db 的 asset identity 会在多项目间冲突 #4

Description

@TbusOS

背景

DESIGN §3.2 规定 graph.db 位于 ~/.engram/graph.db,作为跨 scope 的全局索引;同时 assets.id 是主键,path 也要求全局唯一。当前实现已经在 cli/engram/commands/memory.py 注释里临时改成 <project>/.engram/graph.db,并说明存在 cross-project uniqueness 的 schema gap。

问题

同一个用户的多个项目很容易都存在 local/user_profilelocal/feedback_confirm_before_push 这类 asset ID。若按全局 ~/.engram/graph.db + id TEXT PRIMARY KEY 实现,会出现主键冲突。path TEXT UNIQUE 也有类似问题,因为 local/user_profile.md 在不同项目中是合法重复路径。

这不是实现细节,而是 on-disk contract 和索引 contract 的身份模型没有完全定义。

影响

  • references_usage_eventsconsistency_proposals 无法稳定指向跨项目资产。
  • engram graph rebuild 无法从多个项目重建一个无歧义的全局索引。
  • 第三方实现会在“项目本地 graph.db”与“用户全局 graph.db”之间产生分歧。

建议

先在 SPEC/DESIGN 中冻结全局 asset URI。候选模型:

(store_root_id, scope_kind, scope_name, asset_id)

其中 store_root_id 对项目 scope 使用 repo id 或规范化 project path hash;对 user/team/org/pool scope 使用对应全局 scope 标识。assets 表用复合唯一键或新增 canonical_uri 主键,references_usage_events 指向该 canonical URI。

同时明确:

  • local/foo 只在当前 project context 内可解析。
  • 跨项目或 journal 中必须使用 canonical URI。
  • path 只能在 (store_root_id, scope_kind, scope_name) 内唯一,不能全局唯一。

参考

  • DESIGN.md §3.2:~/.engram/graph.dbassets.id TEXT PRIMARY KEYpath TEXT UNIQUE
  • cli/engram/commands/memory.py 顶部注释:当前实现已临时改为 <project>/.engram/graph.db

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions