Derived ids change with the Python or Node Unicode version

オープン
#367 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
node.js, python, typescript
領域
backend, databases

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
TypeScript
スター
173
フォーク
58
平均マージ
6時間
マージ済み PR(30日)
120

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

hydra-db/selfgraph のほかの issue

hydra-db/selfgraph の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。