Repository navigation
Description
Summary
Entity resolution treats an external id pair as an exact identity, and it compares blank values too. Two unrelated entities that both carry {"crm": ""} therefore merge with reason external_id and confidence 1.0: the second one is never stored, its relations, preferences, and decisions move to the first, and its name becomes the first one's alias. Nothing on the write side rejects a blank value. Both SDKs behave the same.
Reproduce
Embedded Kuzu, current main:
import asyncio, os, tempfile
from selfgraph import SelfGraph
from selfgraph.stores.kuzu import KuzuStore
async def main():
g = SelfGraph(KuzuStore(os.path.join(tempfile.mkdtemp(), "db")))
await g.entities.create("Ann Lee", "Person", external_ids={"crm": ""})
r = await g.insert.facts({"entities": [{"name": "Bob Stone", "type": "Person", "external_ids": {"crm": ""}}]})
print([(m.absorbed_id, m.survivor_id, m.reason, m.confidence) for m in r.merges])
print([(e.id, e.name, e.aliases) for e in (await g.entities.list()).items])
asyncio.run(main())Actual (Python and TypeScript)
[('person:bob-stone', 'person:ann-lee', 'external_id', 1.0)]
[('person:ann-lee', 'Ann Lee', ['Bob Stone'])]
The same happens after entities.update(..., external_ids={"crm": ""}) and through insert.facts alone.
Expected
A blank external id identifies nothing, so Ann Lee and Bob Stone stay two entities. A blank alias is already dropped on write for the same reason (docs/resources.md).
Root cause
src/selfgraph/resolution.py,DefaultResolver: the scorer merges whencandidate.external_ids.get(key) == valuefor any pair, so"" == ""matches, and the candidate index keys the pair as well.typescript/src/resolution.tsdoes the same.- No check rejects a blank or whitespace value:
_require_str_mapping(entities.create/update) andEntityInput(insert.facts) accept it, and the TypeScript validators mirror that.
Proposed fix
Reject an empty or whitespace external id value on every write path in both SDKs, with the same error text, the way blank keys are now handled. A blank value then can never be stored or matched. Add tests on both sides and a conformance case.
Not a duplicate of
- external_ids accepts empty and whitespace keys that properties rejects #391 / fix(write): reject empty external_id keys like properties keys #406: blank external id keys and validation symmetry with properties. This is about blank values, and the harm is a silent wrong merge.
I would like to work on this.
Activity
arrry-hydraDB commentedon Nov 26, 2026
/approved
Reproduced on main with embedded Kuzu: two Person entities that both carry
external_ids {"crm": ""}merge with reasonexternal_idat confidence 1.0, so the second is absorbed and its name becomes an alias. Same in both SDKs.Scope: reject an empty or whitespace
external_idvalue on every write path (entities.create,entities.update, andinsert.factsviaEntityInput) in both SDKs with identical error text, the way blank keys are rejected (#406) and a blank alias is already dropped. Once writes reject the value it never reaches the resolver, so no scorer change is needed. Add tests on both sides and a conformance case.Priority P2, effort S: a silent wrong merge with data loss, and a bulk import with a missing id (every record carrying
{"crm": ""}) would collapse unrelated entities into one.github-actions commentedon Nov 26, 2026
Approved by @arrry-hydraDB. @saurav-shakya or an assignee of this issue can now open a PR that links it with
Closes #524(max 10 open PRs at a time). Anyone else can comment/takeon this issue to be assigned.