From b46a9f56f4bc7fcf23d37cacc4ec24f46e0e66cd Mon Sep 17 00:00:00 2001 From: saurav-shakya Date: Thu, 26 Nov 2026 19:20:32 +0000 Subject: [PATCH 1/3] Read stored merge rewrites and their evidence in model field order in TypeScript --- typescript/src/resolution.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/typescript/src/resolution.ts b/typescript/src/resolution.ts index 12fd6eaf..2a4357b8 100644 --- a/typescript/src/resolution.ts +++ b/typescript/src/resolution.ts @@ -1196,9 +1196,13 @@ function decodeMerge(props: Props, entries: readonly Props[] = []): MergeRecord added_external_ids: loads(props.added_external_ids_json, []), added_properties: loads(props.added_properties_json, []), rewrites: (listed.rewrite as MergeRewrite[]).map((rw) => ({ - ...rw, + kind: rw.kind, + id: rw.id, + original: rw.original, + rewritten: rw.rewritten, + existed: rw.existed, dropped: rw.dropped ?? false, - evidence: rw.evidence ?? [], + evidence: (rw.evidence ?? []).map((ev) => decodeEvidence(ev as unknown as Props)), })), created_at: fromIso(props.created_at)!, reverted_at: fromIso(props.reverted_at), From 34862646f6af008a22a785e39baa45cab6f4fb97 Mon Sep 17 00:00:00 2001 From: saurav-shakya Date: Thu, 26 Nov 2026 19:21:21 +0000 Subject: [PATCH 2/3] Check the key order of stored merge rewrites in the TypeScript tests --- typescript/test/resolution.test.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/typescript/test/resolution.test.ts b/typescript/test/resolution.test.ts index af5a2dc2..5a30d2ab 100644 --- a/typescript/test/resolution.test.ts +++ b/typescript/test/resolution.test.ts @@ -337,6 +337,22 @@ function suite(spec: StoreSpec) { const ids = async (g: SelfGraph) => (await g.entities.list({ limit: 1000 })).items.map((e) => e.id).sort(); const seed = (g: SelfGraph, ...entities: Extraction["entities"] & object[]) => g.insert.facts({ entities }); + it("reads stored merge rewrites and their evidence in model field order", async () => { + const g = open({ resolver: "default" }); + await seed(g, { type: "Person", name: "Ann Lee", aliases: ["Annie"] }); + const quote = { source_id: "memo", quote: "Annie knows Ann Lee", confidence: 0.9 }; + await g.insert.facts({ + entities: [{ type: "Person", name: "Annie" }], + relations: [{ from_entity: "person:annie", type: "KNOWS", to_entity: "person:ann-lee", evidence: [quote] }], + }); + const [record] = (await g.entities.merges("person:ann-lee")).items; + const [rewrite] = record!.rewrites; + expect(Object.keys(rewrite!)).toEqual(["kind", "id", "original", "rewritten", "existed", "dropped", "evidence"]); + expect(rewrite!.evidence.map((ev) => Object.keys(ev))).toEqual([ + ["source_id", "source_version", "chunk_id", "quote", "start_offset", "end_offset", "confidence"], + ]); + }); + it.each([ ["insert", 1], ["insert", 2], From 0b88c8c2a87125ede70f46c6e163a94b8c2cd4f8 Mon Sep 17 00:00:00 2001 From: saurav-shakya Date: Thu, 26 Nov 2026 19:24:34 +0000 Subject: [PATCH 3/3] Compare the key order of stored merge rewrites across both SDKs in conformance --- typescript/test/conformance/py_side.py | 18 ++++++++++++++++++ typescript/test/conformance/ts_side.ts | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/typescript/test/conformance/py_side.py b/typescript/test/conformance/py_side.py index a5d561b6..a13292ef 100644 --- a/typescript/test/conformance/py_side.py +++ b/typescript/test/conformance/py_side.py @@ -1198,6 +1198,23 @@ def iso_times(): ] +async def merge_key_order(graph): + """Read back a merge whose rewrite carries evidence and list the keys in the order each SDK prints them. + + @param graph (SelfGraph): the conformance graph, whose store holds a separate namespace for this case. + @return (list): the keys of each stored rewrite and of each of its evidence records. + """ + g = SelfGraph(store=graph.store, namespace=f"{graph.namespace}_merge_keys", resolver="default") + await g.insert.facts({"entities": [{"type": "Person", "name": "Ann Lee", "aliases": ["Annie"]}]}) + quote = {"source_id": "memo", "quote": "Annie knows Ann Lee", "confidence": 0.9} + relation = {"from_entity": "person:annie", "type": "KNOWS", "to_entity": "person:ann-lee", "evidence": [quote]} + await g.insert.facts({"entities": [{"type": "Person", "name": "Annie"}], "relations": [relation]}) + rewrites = [ + to_jsonable(rw) for record in (await g.entities.merges("person:ann-lee")).items for rw in record.rewrites + ] + return [[list(rw), [list(ev) for ev in rw["evidence"]]] for rw in rewrites] + + async def mcp_argument_errors(): """Check MCP tool arguments that both servers must reject, with the pydantic rules the Python server applies. @@ -1770,6 +1787,7 @@ async def write(graph): except ValidationError as exc: out["facts_none"] = str(exc) out["mcp_arguments"] = await mcp_argument_errors() + out["merge_key_order"] = await merge_key_order(graph) out["flag_errors"] = [] for flag in ("false", 0): for call in ( diff --git a/typescript/test/conformance/ts_side.ts b/typescript/test/conformance/ts_side.ts index bcf8f1cc..3fc94635 100644 --- a/typescript/test/conformance/ts_side.ts +++ b/typescript/test/conformance/ts_side.ts @@ -1676,6 +1676,23 @@ export async function kuzuReadOnly(): Promise { } } +/** + * Read back a merge whose rewrite carries evidence and list the keys in the order each SDK prints them. + * + * @param graph (SelfGraph): the conformance graph, whose store holds a separate namespace for this case. + * @return (Promise): the keys of each stored rewrite and of each of its evidence records. + */ +async function mergeKeyOrder(graph: SelfGraph): Promise { + const g = new SelfGraph(graph.store, { namespace: `${graph.namespace}_merge_keys`, resolver: "default" }); + await g.insert.facts({ entities: [{ type: "Person", name: "Ann Lee", aliases: ["Annie"] }] }); + const quote = { source_id: "memo", quote: "Annie knows Ann Lee", confidence: 0.9 }; + const relation = { from_entity: "person:annie", type: "KNOWS", to_entity: "person:ann-lee", evidence: [quote] }; + await g.insert.facts({ entities: [{ type: "Person", name: "Annie" }], relations: [relation] }); + const records = (await g.entities.merges("person:ann-lee")).items; + const rewrites = records.flatMap((record) => toJsonable(record.rewrites) as Array>); + return rewrites.map((rw) => [Object.keys(rw), (rw.evidence as Array>).map(Object.keys)]); +} + /** * Call MCP tools with text, boolean, and null arguments the servers must reject before running the tool. * @@ -2132,6 +2149,7 @@ export async function write(graph: SelfGraph): Promise> out.facts_none = exc.message; } out.mcp_arguments = await mcpArgumentErrors(); + out.merge_key_order = await mergeKeyOrder(graph); const flagErrors: string[] = []; for (const flag of ["false", 0]) { for (const call of [