← Home
json-ld infrastructure category-theory pflow activitypub

The pflow ecosystem currently uses three JSON-LD vocabularies. Petri net models reference pflow.xyz/schema. Blog posts carry schema.org metadata. Federation speaks ActivityStreams. Three contexts, authored by three different communities, consumed by different software, and they all share the same envelope. JSON-LD earns its place as infrastructure here because it is purely declarative, because a vocabulary can grow monotonically, and because a document can be canonicalized and hashed — though the second is a discipline we keep rather than something the format hands us, and the third only holds under a context we pin. Both caveats are in the sections below.

Three Contexts, One Discipline

Here is a trimmed snippet from each context as it appears in production.

Petri net model (pflow.xyz editor):

{
  "@context": "https://pflow.xyz/schema",
  "@type": "PetriNet",
  "places": {
    "Idle": { "@type": "Place", "initial": [1], "capacity": [1] }
  },
  "transitions": {
    "Brew": { "@type": "Transition" }
  },
  "arcs": [
    { "@type": "Arrow", "source": "Idle", "target": "Brew", "weight": [1] }
  ]
}

A complete one, carrying its CID as @id, is the parity fixture parity/fixtures/net-a.jsonld.

Blog metadata (generated by tens-city's ToJSONLD from the post's frontmatter):

{
  "@context": "https://schema.org",
  "@type": "Article",
  "headline": "JSON-LD as Declarative Infrastructure",
  "author": { "@type": "Person", "name": "stackdump" },
  "datePublished": "2026-02-15T00:00:00Z"
}

ActivityPub actor (federation profile, pkg/activitypub/actor.go):

{
  "@context": [
    "https://www.w3.org/ns/activitystreams",
    "https://w3id.org/security/v1"
  ],
  "type": "Person",
  "preferredUsername": "myork",
  "inbox": "https://blog.stackdump.com/users/myork/inbox",
  "publicKey": { "id": "...#main-key", "publicKeyPem": "..." }
}

Three JSON-LD Contexts

Each snippet links to a vocabulary that defines its terms, and none of them contains an instruction; they are assertions.

Purely Declarative

A JSON-LD document is a serialized RDF graph: a set of subject-predicate-object triples. It makes statements about the world but never tells you what to do with them. There are no callbacks, no event handlers, no conditionally-included fields.

That matters for interoperability, though not quite in the way the RDF story suggests. The same .jsonld net is read by the pflow.xyz browser editor, which renders and simulates it, by go-pflow's parser.FromJSON for ODE analysis and validation, and by the Rust and Julia ports. None of those readers is a JSON-LD processor. Each reads the compact document by key — places, arcs, initial — and ignores the keys it doesn't use; the ODE solver never looks at the x/y layout coordinates. The only component that expands a net into triples is the sealer, below. So what keeps the readers in agreement is not that each extracts the same triples. It is that the document is plain data with no processing order and no embedded logic, which leaves a new reader nothing to reproduce except the mapping from keys to a net — and a test that holds every reader to that mapping. go-pflow generates editor-shape goldens (parser/testdata/editor-shape/: the input document, go-pflow's parsed net and its color expansion), and pflow-xyz (public/petri-shape_test.ts), pflow-rs (crates/pflow-parser/tests/parity.rs) and pflow-jl (test/test_editor_shape.jl) replay copies of them. The JS test's own comment states the rule: readers may stay plural across the ecosystem; their answers may not.

Monotonic Expansion

The published context at pflow.xyz/schema (the file is public/schema) now defines the core net terms — PetriNet, Place, Transition, Arrow — plus seals and claims (PetriNetSeal, InvariantClaim, Signature, PetriRuntime), firing events (TransitionFireEvent), net types (WorkflowNet, ResourceNet, GameNet, ComputationNet, ClassificationNet, CompositeNet) and typed links (DataLink, EventLink, TokenLink, GuardLink). We have not walked that file's history to confirm the order those terms arrived in, or that none was ever removed or redefined along the way, so what follows is the discipline, stated at the strength it has been checked.

The discipline is monotonic expansion: terms are added, existing ones are not retracted — the same rule that makes append-only logs reliable. For loading, it is enough. A net saved before seals existed still opens in an editor that understands seals, because the readers ignore keys they don't use and a net without seal metadata is a valid state. That part really is structural.

For identity it is not enough, and the first version of this post said otherwise. A term the context does not define still expands, through @vocab; giving it an explicit definition later — a @list container, a type coercion — can change what it expands to, and therefore the N-Quads, and therefore the hash. Adding a term is harmless to a reader that goes by key and not automatically harmless to a CID. That is why pflow-xyz's rule is that adding a context term means updating both sealers' contexts (Go and JS) and public/schema in lockstep, and why CIDs are pinned by golden values instead of trusted to follow from structure. Backwards compatibility of loading comes from structure; backwards compatibility of identity is something we test.

Content Addressing via Canonicalization

If JSON-LD is declarative, its identity should derive from what it says, not from how it was serialized. Two documents that make the same assertions — regardless of key order, whitespace, or field arrangement — should hash to the same value.

The URDNA2015 algorithm (RDF Dataset Normalization) makes this possible. It converts any JSON-LD document into a canonical set of N-Quads — sorted, deterministic, order-independent. From there, a standard hash produces a content identifier.

Canonicalization Pipeline

In pflow-xyz, the sealing pipeline is internal/seal/seal.go. Trimmed, with error handling elided:

delete(m, "@id") // the top-level @id, stripped before canonicalization

proc := ld.NewJsonLdProcessor()
opts := ld.NewJsonLdOptions("")
opts.Format = "application/n-quads"
opts.Algorithm = "URDNA2015"
opts.DocumentLoader = cachedLoader // https://pflow.xyz/schema preloaded, not fetched

normalized, _ := proc.Normalize(doc, opts) // canonical N-Quads
multihash, _ := mh.Sum([]byte(normalized.(string)), mh.SHA2_256, -1)
c := cid.NewCidV1(cid.DagJSON, multihash)
cidStr, _ := c.StringOfBase(multibase.Base58BTC)

Two lines in that excerpt carry more of the argument than the hashing does. The top-level @id is deleted first because the @id is the CID — leaving it in would put the answer inside its own preimage, and re-sealing a stored model would give a different CID. And the context is never fetched: the sealer's document loader is preloaded with its own copy of https://pflow.xyz/schema, and that copy is not the file the server publishes at the URL. The sealer's @vocab is https://pflow.xyz/schema#; the published context's is https://schema.org/. A term neither of them defines explicitly — subnets in a composition, say — expands to a pflow IRI when it is sealed and to a schema.org IRI when a generic JSON-LD processor reads the document from the web. pflow-xyz pins exactly that difference in a test, TestSealerAndPublishedContextExpandBundleTermsDifferently. Content addressing works because identity is computed under a context we hold fixed, not under whatever the URL serves today.

The resulting CID becomes the model's @id. If the model changes, the CID changes, and two independently created documents that describe the same graph get the same CID — URDNA2015's canonical form doesn't depend on key order or blank-node labels. "The same graph" includes the layout: x and y are terms in the sealer's context, so the same net drawn in two positions on the canvas seals to two CIDs. The Go sealer and the browser's public/seal-cid.mjs are held to the same golden CIDs over shared fixtures (parity/golden.json, checked from Go by internal/seal/parity_test.go and from JS by parity/parity_check.mjs; read for this revision, not re-run). The fixtures matter more than the algorithm's name: the original ones never exercised URDNA2015's blank-node tie-breaking, and it took two new fixtures with tied arcs and places to catch two bugs in the Julia port — that story is in Byte-Exact Across Four Languages.

This is what makes seals in Categorical Net Types checkable: the seal is a commitment to a specific graph, and any party holding the same context can verify it by re-canonicalizing and re-hashing.

The Categorical View

There is a categorical reading of what @context does, and it should be stated at the strength it has earned, which is modest. A context maps local terms (Place, Transition) to global IRIs (https://pflow.xyz/schema#Place). Treat the terms and the IRIs as discrete categories and that map is a functor, but only trivially — a function between sets, with no morphisms for it to preserve. Extending a context keeps the old mappings and adds new ones, so the old context is a restriction of the new; a natural transformation would need two functors on the same domain, which these are not, and extension is the accurate word.

The coproduct claim is the one with content: pflow.xyz, schema.org and ActivityStreams contribute terms to one graph without collision because their IRIs are namespace-disjoint. It holds under the sealer's context. Under the published pflow context it is weaker than it looks, because that context falls back to https://schema.org/ for every term it doesn't define, so a net read from the web puts its undefined terms into schema.org's namespace. Content addressing then gives identity — two documents are the same object when their canonical forms are the same, which is what the CID witnesses — always relative to the context it was computed under.

Open question

Should the published context and the sealer's be the same document? Today they are not, and the difference is on record: the sealer does not export its copy, a test transcribes it and proves the transcription against both the Go and the JS sealer, and the schema reference page documents the @vocab difference rather than removing it. Aligning them would let a generic JSON-LD processor see the graph the CID was computed over. But changing the published @vocab changes how every existing model expands from the web, which is the monotonicity rule pointed back at ourselves. The code does not settle which cost is the right one to pay.

What Changed

Revised 2026-11-08 against pflow-xyz, go-pflow, pflow-rs, pflow-jl and tens-city (code and tests read, not re-run):

  1. The readers are not RDF processors. The February version said each consumer "extracts the triples it understands." The editor and go-pflow's parser read the compact JSON by key; only the sealer expands to triples. What keeps the readers in agreement is the editor-shape goldens, now linked.
  2. Schema history. The 2024/2025/2026 list named Seal, Invariant, Guard, TokenSet, NetType, Link, Interface and Person, none of which the published context defines (Person comes in through schema.org). It is replaced with the terms the file does define, and the history is marked as unchecked. The figure that drew the old list is no longer embedded.
  3. Monotonic is not CID-stable. "Not because we tested backwards compatibility" was wrong for identity: adding a context term can change a CID, so pflow-xyz updates both sealer contexts and public/schema together and pins CIDs with goldens.
  4. Two contexts. The sealer pins its own copy of the context (@vocab https://pflow.xyz/schema#); the published one has @vocab https://schema.org/. The coproduct claim holds only under the first. The seal excerpt now shows the @id strip and the pinned loader; layout coordinates are part of the CID.
  5. Categorical gloss hedged. The functor is trivial, and "natural transformation" did not type-check; it is now extension. The summary section and its blockquote are gone, and the post ends on the open question instead.

Related: Byte-Exact Across Four Languages · Categorical Net Types · cdn.stackdump.com Is a Polydocument Host · tens-city v0.8

×

Follow on Mastodon