Skip to content

feat(export): serialize all supported ledger surfaces - #834

Closed
ansonnmm wants to merge 3 commits into
deeplethe:devfrom
ansonnmm:upstream-pr-whole-ledger-serializer
Closed

ansonnmm wants to merge 3 commits into
deeplethe:devfrom
ansonnmm:upstream-pr-whole-ledger-serializer

Conversation

@ansonnmm

Copy link
Copy Markdown
Contributor

PROBLEM

Rules, attribute rules, document versions, chunks and evidence are read from the export snapshot but never serialized — their facts' prov:wasGeneratedBy, prov:wasDerivedFrom and locator references dangle in the finished file. Newer ledger surfaces are absent too: class/relation updatedAt, entity descriptions, document reader/time context, chunk origin metadata, evidence quote offsets, open-statement layer/phrase/qualifiers/time mentions, typed-fact fromStatement provenance, validFromGrade, and evidenceOrigin.

WHY THIS IS A GENERIC UTOPIA BUG OR CONTRACT GAP

The serializer was never extended as the ledger schema grew, so the export contract silently covers only a subset of what the read model returns — a file that claims to be the ledger but omits whole families and leaves references pointing at nodes that were never written.

FIX

Serialize every family in snapshot order: vocabulary (classes, relations), rules and attribute rules with their conditions and expression-predicate references, documents and document versions, chunks, entities, facts with qualifiers / time mentions / lifecycle anchors, evidence, and derivations with ordered premises. Emission fails closed — an unresolvable reference aborts the export rather than minting an IRI for a node that was never written.

REGRESSION EVIDENCE

New in-memory unit tests cover each emission family in both Turtle and JSON-LD: rule conclusions and conditions, expression predicates, document-version locators, chunk/evidence links, open-statement ledgers, qualifiers (literal and entity), lifecycle marks, imported vocabularies, and fail-closed paths (unresolvable qualifier type, merged entity reference, foreign IRI minting). 32/32 rdf:: tests pass.

COMPATIBILITY RISK

Additive only: exports grow by the previously missing families; no existing triple is removed or renamed.


Stacked on #832#833 — this PR's diff includes those commits until they merge.

南慶麟 added 3 commits September 20, 2026 21:46
Install a schema-level invariant: every reference an export can resolve
must join rows that live in the same knowledge base. A column foreign
key proves the target exists, not that it is the same KB's — the
exporter would otherwise mint local IRIs naming foreign rows, or
silently drop vocabulary references that resolve to nothing.

Three layers: a precondition scan that refuses the migration on a
dirty ledger, row triggers on every edge (deferred constraint triggers
on same-table self-references so COPY and multi-row inserts are judged
at commit), and kb-ownership immutability on every owned table.
The export read model moves from "open a pool connection per page" to a
caller-provided transaction: a route can now pin one REPEATABLE READ
snapshot across the preflight check, the vocabulary reads, and every
page. A mid-stream commit can no longer leak half a rule or a dangling
wasGeneratedBy into a finished file.

Integrity is checked on the rows that survive, not on a second look.
Every page query selects the referenced row's kb atomically with the
row itself; a foreign, dangling, or merged-out reference refuses the
whole export rather than minting a local IRI that names another KB's
row or silently dropping a vocabulary link. The scan covers the
provenance chain, derivation premises, edge qualifiers, vocabulary
references, and the open-statement / time-mention / binding edges the
schema has grown since — the same families migration 0070 guards on
the write side.

Read-model additions carried by the same pages: statement qualifiers,
time mentions, typed-fact sources, fact layer/phrase/validity grade,
evidence quote offsets, chunk origin metadata, entity descriptions,
document reader/time-context fields, and vocabulary updated_at.
Rules, attribute rules, document versions, chunks and evidence were
read from the same snapshot but never serialized; their facts'
prov:wasGeneratedBy, prov:wasDerivedFrom and locator references
dangled in the file. Serialize them in snapshot order so every
emitted reference resolves.

New upstream ledger surfaces serialize too: class/relation updatedAt,
entity descriptions, document reader/time-context, chunk origin
metadata, evidence quote offsets, open-statement layer/phrase/
qualifiers/time mentions, typed-fact fromStatement provenance,
validFromGrade, and evidenceOrigin.
@ansonnmm

Copy link
Copy Markdown
Contributor Author

Closing pending author's final review of the PR set — will reopen once the series is finalized.

@ansonnmm ansonnmm closed this Sep 20, 2026
@ansonnmm ansonnmm changed the title The whole ledger reaches the export feat(export): serialize all supported ledger surfaces Sep 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant