Dialect binding#

Cross-format provenance binding: the rules and dialect under which a DS artifact was produced are recorded inside the artifact, and artifacts that must agree are checked against each other at load time. Mismatch is fatal.

This document defines the shared binding tuple carried by every versioned DS artifact (DSC, event trace, DAP trace, RT profile) and the fail-closed contract that ties them together.

Prefix RBND.

Parents this spec inherits:

  • [RARC.4] format version discipline — the version side of the same fail-closed stance.

  • [LDIA] — the dialect mechanism whose resolved settings this spec hashes.


Why an artifact is bound to its dialect [RBND.1]#

[RBND.1.1] DS artifacts encode behavior. A DSC file encodes "these rules, compiled under these settings." An event trace encodes "this sequence of facts as the engine saw them." An RT profile encodes "these high-water marks under that workload." A DAP trace encodes "this debugged session."

[RBND.1.2] Each of those four artifacts only has forensic or operational meaning paired with the exact rules and dialect it came from. Loading a profile produced under one DSC into an engine that loaded a different DSC produces undefined RT behavior. Replaying a trace against rules other than the rules that produced it produces an incorrect debugging picture. The "right" pairings are checkable; this spec defines the check.

[RBND.1.3] The dialect binding tuple. Every DS artifact governed by this spec carries the same three fields, each container under the names [RBND.2.2] gives:

  • dsc_sha256, the SHA-256 of the compiled DSC bytes that were active when the artifact was produced ([RBND.3.1]);

  • capabilities, the program's resolved settings: every capability set true, in ascending Capability order ([LDIA.1.3]);

  • dialect_def_sha256, the SHA-256 of the canonical serialization of those settings ([RBND.4]).

The dialect's name is not part of the tuple: two programs whose settings resolve alike are bound alike, whatever dialect each named.

A malformed capabilities list is refused. The list is strictly ascending, and each entry is a member of proto/capabilities.proto#Capability other than CAPABILITY_UNSPECIFIED. So no capability appears twice, and the list is never longer than the enum has members. A reader must refuse a list that breaks either rule: at load, with DS_ERR_DSC_SEMANTIC; in a recording's header, with DS_ERR_PARSE. It must not cut, sort or de-duplicate the list, because a list repaired that way would compare as a different tuple.

The load refusal stays although a .dsc is trusted input ([RDSC.9.9]). It is a cheap structural need of the loader: the engine copies the list into the header of every recording it writes ([RBND.3.1]), and a recording's reader refuses a malformed one.

Together these answer the question "is this artifact talking about the same rules-and-behavior-system as that artifact?" without consulting any external registry.

ratified — see also: LDIA.1.3, RBND.2.2, RBND.3.1, RBND.4, RDSC.9.9

[RBND.1.4] The RT-config binding tuple. Artifacts that emerge from a configured live engine (event traces, DAP traces) carry a second binding describing the runtime pool sizes, budgets, and policy under which the engine was operating:

rt_config_sha256    — SHA-256 of the canonical serialization
                      of the resolved RT configuration the
                      engine ran with (per RBND.4b)

The engine's strategy is not part of this binding: it follows from the resolved settings ([RDSC.16.2.1]), which the dialect binding already carries.

Compile-time and pre-RT artifacts (DSC, RT profile) do not carry this binding — a DSC predates engine sizing, and a profile is the input to RT config, not an output. The full list of which containers carry which binding is [RBND.2].

Deferred: not binding in this edition.

see also: RBND.2, RBND.4b, RDSC.16.2.1

[RBND.1.5] The two bindings are the only artifact-to-artifact comparators this spec defines. Comparators that consume a subset of either tuple (e.g. "DSC hash only") are not permitted as fail-closed gates; they may appear in informational diagnostics. The two bindings are checked independently — a mismatch in either is fatal per [RBND.5].


see also: RBND.5

Where the tuples live in each artifact [RBND.2]#

Artifact

Container

Dialect

RT-config

DSC

the DscHeader atom

✓

—

Event trace

the StreamHeader atom

✓

✓

DAP trace

first-line meta object in .dsr

✓

✓

Realtime contract

.dsrt (compile input) / RealtimeContract atom (in .dsc)

✓

yes — IS the contract

Profile measurement

.profile TOML (informational; never read by runtime)

✓

—

Specifications: [RDSC], [RFCS.4], [NDBG], [RTCT].

see also: RFCS.4

[RBND.2.1] Every container must hold the bindings indicated for it. A loader must reject a container missing any required field with DS_ERR_BND_INCOMPLETE.

A repeated field such as capabilities is never missing: absent and empty are one state on the wire, and an empty list is a value. The rule binds the singular fields, dsc_sha256 and dialect_def_sha256.

An event trace that carries no tuple is unverifiable, not incomplete. The engine must replay a trace whose header holds neither singular field without a binding check, whether or not it has loaded a DSC. It must refuse a trace that holds one of the two and not the other with DS_ERR_BND_INCOMPLETE, whether or not it has loaded a DSC: the trace is incomplete before anything is compared. An engine that has loaded no DSC has no tuple to compare a complete trace against, and checks none ([RBND.5.4]).

see also: RBND.5.4

[RBND.2.2] A writer names the binding's fields as the container's format does. In a container a .proto message defines — the DSC's DscHeader and an event trace's StreamHeader — the fields are the message's ([STYL.2.14.2]). The event trace's dsc_hash is the DSC's dsc_sha256 ([RBND.3.1]).

A writer of any other container — a DAP trace's .dsr meta object, a profile's TOML — must name them dsc_sha256, capabilities, dialect_def_sha256 and, where the container carries the RT-config binding ([RBND.2]), rt_config_sha256, verbatim and with no alias, whatever naming convention its format otherwise follows.

defined in: proto/header.proto#DscHeader, proto/stream_header.proto#StreamHeader — see also: RBND.2, RBND.3.1

[RBND.2.3] Forensic inline values. Containers that carry the RT-config binding MUST also carry the resolved RT configuration values inline alongside the hash. The hash is the binding comparator; the inline values are for human/forensic readability when the producing profile is no longer available. The inline values MUST exactly equal the values used to compute rt_config_sha256 per [RBND.4b]; a mismatch between inline values and recomputed hash is DS_ERR_BND_INCOMPLETE.


Deferred: not binding in this edition.

see also: RBND.4b

Hashing rules [RBND.3]#

[RBND.3.1] dsc_sha256 is the hash [RDSC.3.6] defines, which the DSC's own header carries. Every other artefact's dsc_sha256 is that value, copied from the header of the DSC that was active when the artefact was produced; a runtime must not hash the DSC some other way to fill it. Nothing outside the .dsc file is hashed: a container's framing is not part of the DSC byte sequence.

see also: RDSC.3.6

[RBND.3.2] The hash is encoded as a lowercase hex string of 64 characters (no 0x prefix, no separators) in text-based containers (TOML, JSON), and as the raw 32 bytes in protobuf-based containers (bytes field type).

[RBND.3.3] dialect_def_sha256 is SHA-256 of the canonical serialization of the resolved dialect, per [RBND.4]. Same encoding rules as dsc_sha256.


see also: RBND.4

Canonical dialect serialization [RBND.4]#

[RBND.4.1] The "resolved dialect" is the program's resolved settings ([LDIA.1.3]): the named dialect's settings with the use block's overrides applied.

see also: LDIA.1.3

[RBND.4.2] The canonical serialization of the program's resolved settings ([RBND.4.1]) is the byte sequence serialization derives:

serialization = magic , enabled_line ;
magic         = "ds.dialect.v2" , lf ;
enabled_line  = "enabled=" , [ name , { "," , name } ] , lf ;
name          = ? a capability's stable name ? ;
lf            = %x0A ;

Residue the grammar cannot carry ([STYL.2.15.4]): enabled_line names exactly the capabilities whose setting is true, each once, in ascending number of their Capability member, and name is that member's stable name ([LCAP.1]). With no setting true, the line is enabled= and its line feed.

The compiler must write dialect_def_sha256 ([RBND.1.3]) as the SHA-256 of exactly these bytes.

ratified — see also: LCAP.1, RBND.1.3, RBND.4.1

[RBND.4.3] A stable name is taken from a protobuf enum member's name ([LCAP.1]), so it is ASCII and holds neither , nor a line feed. The serialization ([RBND.4.2]) therefore defines no escaping.

see also: LCAP.1, RBND.4.2

[RBND.4.5] Forward compatibility. A revision of the serialization ([RBND.4.2]) takes a different magic line, so a hash written under one revision never equals a hash written under another. Two artefacts whose hashes were written under different revisions therefore fail the dialect-binding check ([RBND.5.1]) with DS_ERR_BND_DIALECT_MISMATCH ([RBND.5.2]): there is no version field to negotiate ([RARC.4]).


see also: RARC.4, RBND.4.2, RBND.5.1, RBND.5.2

Canonical contract serialization [RBND.4b]#

Deferred: not binding in this edition.

[RBND.4b.1] The "resolved RT configuration" is the realtime contract the engine is operating under: cap values supplied by the author in a .dsrt file ([RTCT]) and embedded in the .dsc as a RealtimeContract atom. The canonical byte serialization defined here is the input to SHA-256, producing the rt_config_sha256 field of [RBND.1.4] and the RealtimeContract.rt_config_sha256 proto field of [RTCT.6.2].

see also: RBND.1.4, RTCT.6.2

[RBND.4b.2] The serialization is the byte sequence produced by writing, in order:

1. The literal ASCII bytes "ds.contract.v1\n"
2. "wm_max="              + <int>  + "\n"
3. "agenda_cap="          + <int>  + "\n"
4. "max_fires_per_pump="  + <int>  + "\n"
5. "token_pool_cap="      + <int>  + "\n"
6. "intern_cap="          + <int>  + "\n"
7. "intern_bytes_cap="    + <int>  + "\n"
8. "pump_wcet_ns="        + <int>  + "\n"
9. "nodes="            followed by each (node_id, kind,
   capacity) triple in ascending node_id order, joined by
   ",", each formatted as "<node_id>:<kind>:<capacity>"
   where kind ∈ {"alpha", "beta", "term"}; then "\n"
10. "series="          followed by each (series_id, capacity)
    pair in ascending series_id order, joined by ",", each
    formatted as "<series_id>:<capacity>"; then "\n"

[RBND.4b.3] Integers are formatted in base-10 ASCII with no leading zeros and no thousands separator.

[RBND.4b.4] Strategy is not part of the contract. The engine's strategy follows from the artefact's resolved settings ([RDSC.16.2.1]), which the dialect binding carries; no integrator configuration selects it. The contract hash covers the contract's values and nothing about how the engine was configured to run them.

see also: RDSC.16.2.1

[RBND.4b.5] Stability requirement. Identical contracts produce byte-identical serializations. Adding a new field to a future contract schema requires bumping the magic line to ds.contract.v2; per [RARC.4] a v1 hash and a v2 hash will differ and a v2 binary refuses v1 artifacts.

see also: RARC.4

[RBND.4b.6] Producer responsibility. The compiler computes rt_config_sha256 from the author's .dsrt per [RTCT.4.4] and embeds it in both the RealtimeContract atom body and the DscHeader.rt_config_sha256 field. The runtime never recomputes the hash from contract values at load time — it loads the hash directly from the atom. Per-load consistency-check obligations are in [RTCT.6.5].

see also: RTCT.4.4, RTCT.6.5

[RBND.4b.7] Debugging aid. The runtime MUST be able to emit the canonical serialization text on demand, through some diagnostic affordance, so that an RT_CONFIG_MISMATCH can be investigated by comparing the two texts rather than two hashes.

[RBND.4b.8] Encoding independence. The canonical serialization of [RBND.4b.2] is defined over the logical contract — the fully expanded, ascending (node_id, kind, capacity) list — regardless of whether the RealtimeContract atom stores that list in the legacy nodes form or the compact form of [RTCT.6.7]. A producer or runtime computing or verifying rt_config_sha256 MUST first materialize the logical list: enumerate covered nodes in ascending node_id order ([RTCT.6.7.2]), take each node's kind from its AlphaNode/BetaNode/TerminalNode atom ("alpha"/"beta"/"term"), and its capacity from the resolved encoding ([RTCT.6.7.3] / [RTCT.6.7.4]); then serialize and hash per [RBND.4b.2]. Consequently a legacy and a compact encoding of the same contract produce the same rt_config_sha256, and the DscHeader binding ([RDSC.3.8]) holds across both. The compact encoding therefore requires no re-hash or migration of existing artifacts, and a recompiled bundle that switches encodings keeps an identical hash.


see also: RBND.4b.2, RDSC.3.8, RTCT.6.7, RTCT.6.7.2, RTCT.6.7.3, RTCT.6.7.4

The fail-closed check [RBND.5]#

[RBND.5.1] Dialect-binding check. When two artifacts are loaded together — a profile against a DSC, an event trace against a DSC + engine, a trace against a DSC + engine — the dialect tuple from the secondary artifact MUST equal the dialect tuple from the primary artifact (the DSC). Element-wise equality across all three fields. An event trace that carries no tuple at all is the one exception, replayed without the check ([RBND.2.1]).

checks: alloy×6 — see also: RBND.2.1

[RBND.5.1b] RT-config-binding check. Additionally, for artifacts carrying the RT-config binding ([RBND.2] column 3), the rt_config_sha256 from the secondary artifact MUST equal the corresponding value from the loaded engine (replay paths) or from a designated reference artifact (forensic-correlation paths).

Deferred: not binding in this edition.

see also: RBND.2

[RBND.5.2] Mismatch is fatal. A mismatch on any field produces one of:

  • DS_ERR_BND_DSC_MISMATCH — dsc_sha256 differs.

  • DS_ERR_BND_DIALECT_MISMATCH — capabilities or dialect_def_sha256 differs.

  • DS_ERR_BND_RT_CONFIG_MISMATCH — rt_config_sha256 differs.

The detail string MUST name the field that disagreed and include both observed values truncated to 16 hex characters where applicable; for capabilities, it names the capabilities in one tuple and not the other.

DS_ERR_BND_DIALECT_MISMATCH is also the refusal of an artefact whose settings an integration's admission policy does not admit ([NLFC.10]).

checks: alloy×2 — see also: NLFC.10

[RBND.5.3] No tolerated mismatches. There is no "advisory" mode, no "warn-and-continue", no "best-effort load". This applies to every load path that pairs two artifacts:

  • DSC load ([RTCT.6.5]) — establishes the RT-config binding from the loaded DSC's RealtimeContract atom; the load itself has nothing to compare against, but every subsequent pairing does.

  • event-trace replay ([RFCS]) — both checks.

  • DAP trace replay ([NDBG]) — both checks.

checks: alloy×3 — see also: RTCT.6.5

[RBND.5.4] Single-artifact loads. Loading just a DSC, just a event trace (for offline dump without engine attachment), or just a profile, does not invoke a binding check — there is nothing to compare against. Such loaders MAY surface the in-artifact tuples as diagnostic output but MUST NOT cross-check against an unsupplied reference.

Single-sourcing the check [RBND.6]#

[RBND.6.1] Two comparators, not many. A runtime provides exactly two binding comparisons, and each of its load paths that checks a binding uses one of them ([RBND.6.3]):

  • the dialect-binding comparison, over the tuple of [RBND.1.3], per the rules of [RBND.5.1];

  • the RT-config binding comparison, over the tuple of [RBND.1.4], per [RBND.5.1b].

Both take an expected tuple and an actual tuple and yield either agreement or one of the mismatch outcomes of [RBND.5.2]. Nothing else about their shape is fixed here: the tuples are defined in [RBND.1], the comparison in [RBND.5], and the spelling belongs to whatever language the runtime is written in.

see also: RBND.1, RBND.1.3, RBND.1.4, RBND.5, RBND.5.1, RBND.5.1b, RBND.5.2, RBND.6.3

[RBND.6.2] The dialect-binding comparison succeeds (DS_OK) iff all three fields compare equal under [RBND.5.1]. Otherwise it reports DS_ERR_BND_DSC_MISMATCH or DS_ERR_BND_DIALECT_MISMATCH, carrying a detail string per [RBND.5.2].

see also: RBND.5.1, RBND.5.2

[RBND.6.2b] The RT-config binding comparison succeeds iff rt_config_sha256 matches per [RBND.5.1b]. Otherwise it reports DS_ERR_BND_RT_CONFIG_MISMATCH, with a detail string per [RBND.5.2].

Deferred: not binding in this edition.

see also: RBND.5.1b, RBND.5.2

[RBND.6.3] No call site in a runtime reimplements the comparison. A runtime's load path MUST use the comparisons of [RBND.6.1] rather than testing fields individually; that is what keeps the contract single-sourced, and a hand-rolled comparator is how one field quietly stops being checked. A path needing both bindings performs both in sequence and surfaces the first mismatch.

A reader outside a runtime, which pairs a trace with a DSC without a runtime's replayer, may make the dialect-binding comparison in its own code. [RFCS.4.5] and [RBND.5] bind that comparison as they bind a runtime's, and the reader must carry [RBND.8.1]'s conformance tests for it.


see also: RBND.5, RBND.6.1, RBND.8.1, RFCS.4.5

Error codes [RBND.7]#

[RBND.7.1] This spec owns error codes -700 through -709. Their tables are [NERR.11.1] and, for -704, [NERR.18], the one place each code is defined ([STYL.2.13.4]).

see also: NERR.11.1, NERR.18

[RBND.7.2] Other specs that perform binding checks (RFCS, NDBG, RTCT) MAY return BND_* codes directly or wrap them in spec-local codes that document the wrapping. Wrapping is permitted only to preserve a spec's existing error band; the underlying check is always the one defined here.


Test obligations [RBND.8]#

[RBND.8.1] Every consumer of the dialect-binding comparison ([RBND.6.1]) MUST carry at least four conformance tests:

  • identical tuples → DS_OK

  • mismatched dsc_sha256 → DS_ERR_BND_DSC_MISMATCH

  • mismatched capabilities (single-element delta) → DS_ERR_BND_DIALECT_MISMATCH

  • tuples naming different dialects whose settings resolve alike → DS_OK

A consumer may drive the third and fourth tests at its comparator rather than through a container. dsc_sha256 hashes the whole DSC, header included ([RDSC.3.6]), so no two compiled artefacts differ in capabilities alone, and the comparison stops at the second test's code first. The third test presents a tuple whose capabilities differ by one element under an equal dsc_sha256. The fourth presents the tuples of two DSCs compiled under different dialect names whose settings resolve alike: the tuple carries no name ([RBND.1.3]), so they compare equal.

see also: RBND.1.3, RBND.6.1, RDSC.3.6

[RBND.8.1b] Every consumer of the RT-config binding comparison ([RBND.6.1]) MUST carry at least two conformance tests:

  • identical values → DS_OK

  • mismatched rt_config_sha256 → DS_ERR_BND_RT_CONFIG_MISMATCH

Deferred: not binding in this edition.

see also: RBND.6.1

[RBND.8.2] One conformance test MUST exercise the canonical dialect serialization of [RBND.4]: produce the same resolved dialect by two different code paths (one via compile, one via direct construction) and assert their hashes agree byte-for-byte.

see also: RBND.4

[RBND.8.3] One conformance test MUST exercise the canonical contract serialization of [RBND.4b]: produce a RealtimeContract atom from two semantically identical .dsrt files (one with extra [measurement] cruft, one without) and assert the resulting rt_config_sha256 values are byte-identical.

Deferred: not binding in this edition.

see also: RBND.4b

The RT-config binding in this edition [RBND.9]#

[RBND.9.1] The RT-config binding is not in this edition. Realtime is refused ([LCAP.2.1.5]), so no engine runs under a contract and there is no resolved RT configuration to bind. In this edition:

  • A producer must leave rt_config_sha256 and the inline RT configuration values empty in every container [RBND.2] marks for the RT-config binding, and a loader must not reject a container for their absence under [RBND.2.1].

  • No load path compares the RT-config binding, and a runtime must not raise DS_ERR_BND_RT_CONFIG_MISMATCH. A runtime may omit the RT-config comparison of [RBND.6.1].

  • No artefact carries a realtime contract, and no profile measurement is produced, so neither row of [RBND.2] that names one applies.

The dialect binding ([RBND.1.3]) is not affected by this clause.

see also: LCAP.2.1.5, RBND.1.3, RBND.2, RBND.2.1, RBND.6.1