Skip to content

A blank external id value counts as an identity: unrelated entities with {"crm": ""} merge at confidence 1.0 #524

Backlog

Description

@saurav-shakya

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 when candidate.external_ids.get(key) == value for any pair, so "" == "" matches, and the candidate index keys the pair as well. typescript/src/resolution.ts does the same.
  • No check rejects a blank or whitespace value: _require_str_mapping (entities.create / update) and EntityInput (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

I would like to work on this.

Activity

  1. added
    bug
    approved-for-pr
    area: write
    area: parity
    P2
    effort: S
    on Nov 26, 2026
  2. arrry-hydraDB commented on Nov 26, 2026

    @arrry-hydraDB
    Collaborator

    /approved

    Reproduced on main with embedded Kuzu: two Person entities that both carry external_ids {"crm": ""} merge with reason external_id at 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_id value on every write path (entities.create, entities.update, and insert.facts via EntityInput) 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.

  3. github-actions commented on Nov 26, 2026

    @github-actions

    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 /take on this issue to be assigned.

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

    P2approved-for-prarea: parityarea: writebugeffort: S

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions