#2289·R2R

Entity UUID Mismatch After Graph Pul

Author: ninjamlCreated May 11, 2026Updated May 11, 2026

Root Cause

When pull syncs document entities/relationships into the collection graph, the entity INSERT SQL omits the id column, causing PostgreSQL to auto-generate new UUIDs. Meanwhile, relationships retain the original document-layer subject_id / object_id . The two UUID sets never intersect.

-- Current: id not copied → new UUID generated
INSERT INTO graphs_entities (name, category, ...)
SELECT name, category, ... FROM documents_entities

-- Relationships keep original UUIDs
INSERT INTO graphs_relationships (subject_id, object_id, ...)
SELECT subject_id, object_id, ... FROM documents_relationships

Impact

  • Zero match between relationship subject_id / object_id and entity id (verified: 153 entities, 189 relationship IDs, intersection = 0)
  • Impossible to cascade-delete relationships when deleting an entity by UUID alone
  • 3D knowledge graph cannot link entities to relationships by ID Fix (Source-level)

Add id to the entity copy query in py/core/providers/database/graphs.py :

-- Fixed: preserve original document-level id
INSERT INTO graphs_entities (id, name, category, ...)
SELECT id, name, category, ... FROM documents_entities

Tables are independent ( documents_entities vs graphs_entities ), so no PK conflicts. Git-like versioning is unaffected — reset + pull still works.