Derived ids change with the Python or Node Unicode version

Abierto
#367 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
node.js, python, typescript

Línea de trabajo

Read src/selfgraph/ids.py, src/selfgraph/retrieval.py, typescript/src/ids.ts, and typescript/src/internal/casefold.ts, then inspect the conformance suite. The issue proposes pinning letter and digit classes plus lowercase and casefold tables to one Unicode version shared by both SDKs. Done means derived IDs, relation types, and retrieval tokens no longer vary with Python or Node Unicode versions, with conformance coverage for the reported cases.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

approved-for-pr area: parity area: write bug effort: M P2

docs/resources.md says combining marks come "from one fixed list, the marks of Unicode 15.0, so an id does not depend on the Python or Node version." Only the marks are pinned. Letters, digits, and case still come from the runtime: \w and str.lower() in Python, \p{L}/\p{N} and toLowerCase() in TypeScript. A character the runtime does not know yet is treated as punctuation and dropped from the id. So the same name derives a different id depending on the Python minor version, and Python and Node disagree whenever their Unicode versions differ.

Tested at 5a277c9 (current main), using the ids.py from that commit under each interpreter, and the TypeScript entityId from the same commit on Node 26.12.

Reproduce
from selfgraph import entity_id

for name in ["王\U0002EBF0", "王\U0002EBF1", "王\U000323B0", "Таня \u1C89а"]:
    print(ascii(entity_id("Person", name)))

The first two names use CJK Extension I ideographs (Unicode 15.1), the third an Extension J ideograph (Unicode 17.0), and the fourth Cyrillic capital TJE (Unicode 16.0).

runtime Unicode 王 + U+2EBF0 王 + U+2EBF1 王 + U+323B0 Таня + U+1C89 а
Python 3.11 14.0 person:王 person:王 person:王 person:таня-а
Python 3.12 15.0 person:王 person:王 person:王 person:таня-а
Python 3.13 15.1 person:王𮯰 person:王𮯱 person:王 person:таня-а
Python 3.14 16.0 person:王𮯰 person:王𮯱 person:王 person:таня-ᲊа
Python 3.15 17.0 person:王𮯰 person:王𮯱 person:王𲎰 person:таня-ᲊа
Node 26 (ICU 78) 17.0 person:王𮯰 person:王𮯱 person:王𲎰 person:таня-ᲊа

Two things go wrong:

  • On an older runtime, different names merge. On Python 3.12, 王𮯰 and 王𮯱 are one entity, person:王, and so is a plain 王.
  • Upgrading Python changes ids. A graph built on Python 3.12 holds person:王. After moving to 3.13, inserting the same name derives person:王𮯰, which no longer matches the stored entity, so a duplicate appears and lookups by the derived id miss the old one. Relation ids derived from those entity ids change with them.

Scanning every code point with entity_id("Person", "Ann " + c + "x"), the number that derive a different id between consecutive Python versions is:

upgrade code points
3.10 to 3.11 525
3.11 to 3.12 4,388
3.12 to 3.13 622
3.13 to 3.14 4,382
3.14 to 3.15 4,657

That is 14,574 between 3.10 and 3.15. normalize_rel_type and the retrieval tokens are built from the same classes and case mappings, so they shift with the runtime too.

The two SDKs also disagree today on the same machine. Python 3.14 (Unicode 16.0) and Node 26 (Unicode 17.0) derive different entity_id, normalize_rel_type, and retrieval tokens for 4,657 code points. That breaks the byte-for-byte id agreement between the SDKs, and the conformance suite does not catch it.

TypeScript is also inconsistent with itself. casefold in typescript/src/internal/casefold.ts is pinned to the Unicode 15.0 tables, while entityId uses the runtime's toLowerCase. On Node 26, entityId("Person", "Ɤama") gives person:ɤama (U+A7CB, Unicode 16.0, lowercased by ICU), but tokenList("Ɤama") gives ["Ɤama"], so a query for "ɤama" does not seed it. Python 3.14 folds both.

Cause
  • Python: _PUNCT and _NON_IDENT (src/selfgraph/ids.py:208-209) use \w, and slug and _canonical_name use str.lower() (src/selfgraph/ids.py:309, :311). Both follow unicodedata.unidata_version, which is 13.0 on Python 3.10 and 17.0 on 3.15. Retrieval's _fold (src/selfgraph/retrieval.py:161) uses str.casefold(), which follows it too.
  • TypeScript: PUNCT and NON_IDENT (typescript/src/ids.ts:27-28) use PY_WORD_CLASS = "\p{L}\p{N}_" (typescript/src/internal/py.ts:6), and slug, canonicalName, and normalizeRelType use toLowerCase()/toUpperCase() (typescript/src/ids.ts:126, :131, :202). All of these follow the ICU bundled with Node.

MARK_CLASS and the TypeScript casefold table are pinned to Unicode 15.0. The letter and digit classes and the case mappings are not.

Pinning those too would make ids independent of the runtime, in line with the docs: a fixed letter/digit class (like MARK_CLASS) and fixed lowercase and casefold tables from one Unicode version, shared by both SDKs. Changing the pinned version later would then be an explicit, migrated change rather than a side effect of upgrading Python or Node.

Related: #312 and #337 are other cases where case mapping in the id and token code produces keys that do not match.

Lenguaje dominante
TypeScript
Estrellas
173
Forks
58
Merge medio
6 h
PR fusionados (30 d)
120

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de hydra-db/selfgraph

Todos los issues de hydra-db/selfgraph

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.