Integer-like property keys render in a different order in TypeScript

Aperta
#390 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
74/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, typescript
Ambito
backend, testing

Direzione di ricerca

Start with formatProps in typescript/src/retrieval.ts and line in typescript/src/contradiction.ts, then compare them with Python’s _format_props and _line and the Obsidian export’s key sorting. Add integer-like property keys to the retrieve conformance cases and check that rendered properties follow the same order in both SDKs; verify the contradiction facts use consistent ordering as well.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

When a relation has a property key that looks like an integer ("2", "10"), the two SDKs render its properties in a different order. This changes the retrieve context text and the facts sent to the contradiction="llm" judge, which should match across SDKs.

Tested at 5a277c9 (current main), Kuzu.

Reproduce

Python:

await g.entities.create("Ada Lovelace", "Person")
await g.entities.create("Analytical Engine", "Machine")
await g.relations.create("person:ada-lovelace", "WORKED_ON", "machine:analytical-engine",
                         properties={"role": "author", "2": "b", "10": "c"})
(await g.retrieve("Ada Lovelace")).context
GRAPH | Ada Lovelace -[WORKED_ON]-> Analytical Engine {10=c, 2=b, role=author}

TypeScript, same calls:

GRAPH | Ada Lovelace -[WORKED_ON]-> Analytical Engine {2=b, 10=c, role=author}
Cause

Both SDKs store properties as key-sorted JSON. Python reads them back in that order. JavaScript objects always enumerate integer-like keys first, in numeric order, whatever the JSON order, so Object.entries gives a different order:

  • formatProps in typescript/src/retrieval.ts:135 (Python _format_props, src/selfgraph/retrieval.py:202) renders the GRAPH lines of the retrieve context.
  • line in typescript/src/contradiction.ts:28 (Python _line, src/selfgraph/contradiction.py:29) renders the facts in the judge prompt. Here Python also uses the caller's insertion order for the relation just written, so the prompt order depends on how the properties were passed.

The Obsidian export is not affected because both sides sort its keys explicitly.

Suggested fix

Sort property keys explicitly with the shared Python-order comparison (comparePy / plain sorted) in both renderers in both SDKs, as the Obsidian export already does, and add a relation with integer-like keys to the conformance cases for retrieve.

Lingua principale
TypeScript
Stelle
173
Fork
58
Merge medio
6h
PR unite (30g)
120

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di hydra-db/selfgraph

Tutte le issue di hydra-db/selfgraph

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.