DSC compiled-artifact format

Contents

DSC compiled-artifact format#

The compiler emits one .dsc file per .ds source file. The runtime loads a .dsc into a single engine instance. This doc specifies the .dsc on-disk format. Its companion .proto files are in proto/.

A .dsc carries one version: the DS version that compiled it, in DscHeader.compiler_version. A runtime accepts artefacts from its own <major>.<minor>. series and rejects every other ([LDET.1.10]). A change to what bytes mean therefore lands with a minor release, never inside a series, because recordings made earlier in that series would stop replaying identically.


File layout [RDSC.1]#

[RDSC.1.1] A .dsc file is a stream of atoms beginning with a header atom and ending at end-of-stream.

[RDSC.1.2] An atom is an independently parseable record: one entry of the container's body oneof, framed [oneof_tag][varint len][body], and its field number is its identity ([RFCS.16.1], [RFCS.19.1]). An atom's name is its body message, the Atom column of [RDSC.7.1]; no name appears on the wire.

see also: RDSC.7.1, RFCS.16.1, RFCS.19.1

[RDSC.1.3] The body of every atom is a serialized protobuf message. The field number determines which message type the body decodes as.

[RDSC.1.4] The first atom of a file must be a DscHeader. An atom's identity is its oneof field number ([RDSC.1.2], [RFCS.16.1]), so this is a test of the leading atom's field number, not of the file's first four bytes. A runtime must reject any file whose first atom is not a DscHeader.

see also: RDSC.1.2, RFCS.16.1

[RDSC.1.5] A file must contain exactly one DscHeader atom ([RDSC.7.2]).

see also: RDSC.7.2

[RDSC.1.6] Atoms with the same field number may appear multiple times when the registry entry permits it (see [RDSC.7]).


see also: RDSC.7

Atom framing [RDSC.2]#

Framing is protobuf-native and two levels: a container is a Dsc or a Stream holding repeated Atom atoms = 1, the outer frame is [0x0A][varint len][Atom] and the inner Atom is [oneof_tag][varint len][body] ([RFCS.19.1]). An atom is identified by its oneof field number, never by a name ([RFCS.16.1]).

see also: RFCS.16.1, RFCS.19.1

[RDSC.2.5] A reader never needs to understand a body to walk past it. Extensibility lives in the body proto, not in the framing: a protobuf tag carries its own wire type and length ([RFCS.19.1]), so an atom whose body a reader cannot decode is still skippable by length alone.


see also: RFCS.19.1

[RDSC.10.9] A decoder's field numbers must be verifiably the proto's. Where an atom body is defined by a .proto, any decoder of that body — in any language, in this repository or another — must have its field numbers tied to that proto by something that fails when the two disagree. Two ways discharge it:

  1. Generated bindings, which satisfy it by construction; or

  2. A pinning test naming the proto and the decoder, which fails if a field number, wire type or oneof membership diverges.

A hand-written decoder with neither is a violation, not a preference.

This rules a property, not a mechanism. Generated bindings are the ordinary way to hold it and the one a new decoder should reach for first, but a target that cannot absorb the generated code may hand-write, and discharges the obligation with (2). What is forbidden is the third case: a hand-written decoder that nothing reconciles with its proto.

The failure this exists to catch is silent by construction. Protobuf's wire format lets a runtime skip an unknown field, and a correct forward-compatible skip is indistinguishable, at the wire, from a decoder that has gone stale against a field number it should know. Both ignore the field. So the drift does not surface as a decode error; it surfaces as an artefact that loads, verifies and runs with a field quietly dropped. No reader can tell the two apart at load time, which is why the tie has to exist ahead of it rather than be inferred from behaviour.

Header atom — DscHeader [RDSC.3]#

[RDSC.3.1] The DscHeader atom carries file-level metadata. The runtime must read it before processing any other atom.

[RDSC.3.2] Body proto: proto/header.proto.

defined in: proto/header.proto#DscHeader — see also: LNAM.7.2, RBND.1.3, RBND.1.4, RTCT.6

[RDSC.3.5] compiler_version is the load gate ([LDET.1.10]). The runtime should surface it in load-error messages and audit logs.

see also: LDET.1.10

[RDSC.3.6] dsc_sha256 is the SHA-256 of the DSC byte sequence with the dsc_sha256 field itself zeroed during hash computation; the compiler patches the real hash in after computing it. During the computation the field is present, as 32 zero bytes; it is not omitted. Encoded as the raw 32 bytes per [RBND.3.2]. At load, the runtime must recompute the hash with the field zeroed and refuse an artefact whose dsc_sha256 does not match, with DS_ERR_DSC_SEMANTIC ([NERR.8.1]).

ratified — see also: NERR.8.1, RBND.3.2

[RDSC.3.7] capabilities and dialect_def_sha256 are defined by [RBND.1.3]. The compiler must populate both: capabilities with every capability the program's resolved settings set true, which is the empty list when none is, and dialect_def_sha256 with its 32 bytes. A file whose dialect_def_sha256 is not 32 bytes is rejected with DS_ERR_BND_INCOMPLETE.

see also: RBND.1.3

[RDSC.3.8] rt_config_sha256 is defined by [RBND.1.4] and mirrors the value in the RealtimeContract atom ([RTCT.6.2] field 10). For a file whose dialect includes realtime, this field must be present, must be 32 bytes, and must equal the canonical hash inside the RealtimeContract atom; disagreement is DS_ERR_BND_INCOMPLETE. For a non-realtime file the field must be empty (zero bytes).

see also: RBND.1.4, RTCT.6.2

[RDSC.3.10] fault_fact_sites (field 14) is the program's fault-fact site count ([LERR.9.10]). The compiler must compute it from the rule network and write it in every artefact, 0 where the network has no site. A runtime that pre-sizes its working memory sizes its fault-fact pool from it at load; any other runtime may ignore it.

defined in: proto/header.proto#DscHeader — see also: LERR.9.10

[RDSC.3.11] A compiler's artefact is reproducible. Given the same sources under the same names, the same library inputs, the same compiler version and the same options, a compiler must write byte-identical .dsc output. A source's name is the one its DsSource atom records ([RDSC.14.2.3]), and it is the only path an artefact carries. A compiler must not write anything else that depends on the time, the host or a file path. [RDSC.3.6]'s hash is then a content address, and rebuilding an artefact under the same names checks it.

The guarantee is one compiler's: two conforming compilers need not agree byte for byte.

ratified — see also: RDSC.14.2.3, RDSC.3.6

Compression & per-module identity [RDSC.4]#

[RDSC.4.1] This section defines the two facilities that share the atom-body envelope: the body compression codec and the per-module module_id join key. The rule network itself travels as the AlphaNode / BetaNode / TerminalNode atoms ([RDSC.4a]); no atom carries rule-network source text.

see also: RDSC.4a

[RDSC.4.3] Compression codec. Compressible atom bodies (DsSource, SchemaDef) carry a Compression selector (proto/common.proto#Compression).

defined in: proto/common.proto#Compression — see also: RDSC.4.5

[RDSC.4.4] compression selects the codec applied to the body. COMPRESSION_NONE is the only supported codec: the compiler must emit COMPRESSION_NONE (bodies are stored uncompressed), and the runtime carries no decompressor. A body declaring any other codec is rejected with DS_ERR_DSC_DECOMPRESS ([RDSC.4.5.1]).

see also: RDSC.4.5.1

[RDSC.4.5] Atom bodies are stored uncompressed (COMPRESSION_NONE), so the runtime links no compression library and body bytes are stable across platforms and toolchains. SchemaDef ([RDSC.5.8]) and DsSource ([RDSC.14.2]) bodies are COMPRESSION_NONE like every other. The Compression value 2 is reserved and must never be reused ([STYL.2.8.7]).

see also: RDSC.14.2, RDSC.5.8

[RDSC.4.5.1] The runtime carries no decompressor, and must reject any body whose compression is not COMPRESSION_NONE with DS_ERR_DSC_DECOMPRESS. This is not a version gate: an all-COMPRESSION_NONE artefact is readable by any runtime, so artefacts stay forward-compatible and only the runtime's codec support is narrow. A .dsc a runtime cannot read is regenerated by recompiling its source — the .dsc is a one-way compile-to-load substrate, not a durable format ([RARC.4]).

see also: RARC.4

[RDSC.4.6] Load order is a property of the node graph. A reader does not concatenate or order atom bodies to reconstruct the rule network; the order in which nodes are linked is carried by the AlphaNode / BetaNode / TerminalNode graph itself ([RDSC.4a]). A file may therefore split its network across atoms freely.

see also: RDSC.4a

[RDSC.4.7] module_id — per-module join key. Every per-module atom carries a compiler-assigned module_id (a u32 starting at 1; module_id = 0 is the reserved "unset" sentinel and must not appear in an emitted atom) that identifies the source module the atom belongs to. The compiler assigns module_id in import-DAG topological order (leaves first, importer last). The runtime joins DsSource / LineSpan / SchemaSource / RuleSource / SchemaTtl / SchemaLogical / Slot / Hydration / SchemaDef / RuleCooldown / DocString / TestCase atoms across the bundle by module_id; AlphaNode / BetaNode / TerminalNode atoms are joined by node_id (globally unique per bundle) rather than module_id. Tooling that needs the display path for a module_id resolves via DsSource[module_id].file. No per-module atom carries a display-path string of its own; the runtime fills the equivalent display strings on its public-API view structs from DsSource at apply time.


C Rete network atoms — AlphaNode, BetaNode, TerminalNode [RDSC.4a]#

[RDSC.4a.1] The C Rete backend is described by three atom types — AlphaNode, BetaNode, and TerminalNode — each carrying one node of the compiled Rete network. Atoms are emitted one per node; the entire rule network for a bundle is the union of all AlphaNode, BetaNode, and TerminalNode atoms across all modules.

[RDSC.4a.2] The rule network is optional ([RDSC.8.1]). A program that declares no rule compiles to an artefact with no AlphaNode, BetaNode or TerminalNode atom, and the runtime must load it as it loads any other: its schemas are registered and an integrator asserts into them, and no rule fires.

see also: RDSC.8.1

[RDSC.4a.3] node_id. Every AlphaNode, BetaNode, and TerminalNode atom carries a node_id field — a compiler-assigned uint32 globally unique across all three atom types within a bundle. node_id = 0 is reserved as null/unset. Cross-references between atoms (BetaNode.right_alpha_id, BetaNode.left_parent_id, TerminalNode.parent_beta_id) use node_id. The loader builds one map keyed by node_id spanning all three types.

ratified

[RDSC.4a.4] Schema and rule cross-references. AlphaNode atoms reference schemas by schema_name; TerminalNode atoms reference rules by rule_name. Both are resolved against atoms already registered from Slot / SchemaLogical / SchemaTtl (schemas) and RuleCooldown (rules). AlphaNode and TerminalNode atoms carry no duplicate declarations of schema structure or rule metadata.

[RDSC.4a.5] Load ordering. The loader processes atoms in a single forward pass. AlphaNode atoms must precede any BetaNode that references them via right_alpha_id — the compiler guarantees this by emitting all AlphaNode atoms before any BetaNode. BetaNode-to-BetaNode parent references and BetaNode-to-TerminalNode leaf wiring are accumulated as pending references and resolved in one sweep after the stream ends. After the sweep the loader seeds root betas (left_parent_id == 0) with nil tokens (IRET.19). No second pass through the stream is required.

Every left_parent_id chain ends at a root beta. The compiler must not emit an artefact whose left_parent_id references form a cycle, and a loader must refuse one with DS_ERR_RETP_INVALID ([RDSC.11.1]). The check belongs to the sweep: it is a cheap structural need of the loader ([RDSC.9.9]), since a walk up the chain has no end on such an artefact.


checks: idris×27 — see also: IRET.19, RDSC.11.1, RDSC.9.9

AlphaNode atom [RDSC.4a.6]#

One alpha (pattern-filter) node. Admits facts of schema_name that pass all listed tests into the node's memory.

Proto: proto/alfa.proto#AlphaNode.

An AlphaNode atom with zero tests admits all facts of the named schema. A REGEX test compiles the pattern string at load time; the compiler pre-validates regex syntax. Regex flags travel inside the pattern as an RE2 flag group, and a pattern that does not compile fails the load ([RDSC.4a.6.1]).

defined in: proto/alfa.proto#AlphaNode — see also: RDSC.4a.6.1

[RDSC.4a.6.1] A malformed AlphaTest is refused at load. A loader must refuse, with DS_ERR_DSC_SEMANTIC, an artefact holding an AlphaTest (proto/alfa.proto#AlphaTest):

  • whose kind is no member of AlphaTestKind;

  • of kind ALPHA_TEST_EQ or ALPHA_TEST_CMP with no literal, or with a literal that sets no member of its value;

  • of kind ALPHA_TEST_CMP whose op is no member of AlphaCmpOp;

  • of kind ALPHA_TEST_REGEX whose pattern is empty, or does not compile;

  • whose slot_index is above 254, which the field cannot hold: it has no marker ([RDSC.4a.9.1]).

Each of these but a pattern that does not compile is a shape of the AlphaNode's body, refused as the body is decoded, and so before a name [RDSC.8.7] checks. Compiling a pattern is not part of decoding the body. None of these has a meaning, and the compiler must not emit any of them. Each is a cheap structural need of the loader under [RDSC.9.9], not a defence against a hostile artefact.


ratified — defined in: proto/alfa.proto#AlphaTest — see also: RDSC.4a.9.1, RDSC.8.7, RDSC.9.9

[RDSC.4a.6.2] A REGEX test whose subject is not a String faults. A regex match takes a String ([LREG.1.1]), so the compiler emits an ALPHA_TEST_REGEX test only on a String slot ([RLOW.5.2.2]). An artefact whose REGEX test reads a slot value that is not a String lies about that slot. Where the engine evaluates such a test, it must raise an EngineError of ENGINE_FAULT_ARTEFACT_LIED (proto/engine_fault.proto#EngineFault) naming $alpha_<id> ([LERR.9.11]), and halt the tier ([LERR.1.4.7]). It must not answer the test false instead.

The test is one conjunct of its node's tests, as a slot index that names nothing is ([RDSC.4a.9.1]). A test of the node that answers false decides the fact wherever it stands, and the engine raises the fault only when none does ([LNUL.4.2]).

defined in: proto/alfa.proto#AlphaTest — see also: LERR.1.4.7, LERR.9.11, LNUL.4.2, LREG.1.1, RDSC.4a.9.1, RLOW.5.2.2

[RDSC.4a.6.3] An AlphaNode names its schema. Its schema_name is the name of the schema whose facts it filters, and is never empty. A loader must refuse an AlphaNode whose schema_name is empty with DS_ERR_DSC_SEMANTIC ([RDSC.11.1]). The refusal belongs to the body's shape ([RDSC.8.7]), so the loader makes it before it looks any name up: an empty name is no name to look up, and is never DS_ERR_DSC_DANGLING.

ratified — defined in: proto/alfa.proto#AlphaNode — see also: RDSC.11.1, RDSC.8.7

BetaNode atom [RDSC.4a.7]#

One beta (join) node.

Proto: proto/beta.proto#BetaNode.

left_parent_id == 0 marks a root beta (first or only pattern in a rule). The loader seeds root betas with a nil token so that right-activations immediately produce single-fact tokens at pattern-index 0.

join_tests are Expr trees evaluated against (left_token, right_candidate_fact). A VAR node with pattern_index = 255 reads from the candidate right fact ([RDSC.4a.9.1]).

is_negative = true makes this a NOT node.


checks: idris×2 — defined in: proto/beta.proto#BetaNode — see also: RDSC.4a.9.1

TerminalNode atom [RDSC.4a.8]#

One terminal node — the leaf of a rule's LHS network.

Proto: proto/term.proto#TerminalNode.

rule_name resolves cooldown via RuleCooldown — no duplication in TerminalNode. Rule order is the terminal ordinal assigned at load, which is source order ([LDET.5.4]).

Actions evaluated in order: ACTION_CALL evaluates expr for side effects; ACTION_ASSERT / ACTION_LOGICAL_ASSERT build a fact from slot assignments and asserts it into working memory; ACTION_WITHDRAW retracts the fact bound at LHS pattern position withdraw_pattern_index.

Truth maintenance is the action's, not the terminal's: the fact an ACTION_LOGICAL_ASSERT asserts takes the firing activation as its justifier ([IRET.12.1]).

defined in: proto/term.proto#TerminalNode — see also: IRET.12.1, LDET.5.4

Fire guard [RDSC.4a.8.2]#

[RDSC.4a.8.2.1] A TerminalNode's fire_guard carries at most two parts:

  • the condition: a where that reads a clock or a series ([LTIM.2.4.1]), an after follow-up's included ([LTAC.3.4]), or a positive pattern's within window ([LTIM.2.7.1]), moved off the rule's pattern so that it is read under each pump's sample;

  • the rate gate: a CallExpr whose op is FN_RATE_ALLOW (RLOW.4.6.1).

The compiler must emit the guard in one of three shapes: the condition alone; the rate gate alone; or, for a rule that has both ([LTIM.2.5.4]), a BinopExpr whose op is BINOP_AND, whose left is the condition and whose right is the rate gate. The condition contains no FN_RATE_ALLOW call.

A runtime must tell the parts apart by these shapes and by the callee: a top-level call is the rate gate only when its op is FN_RATE_ALLOW, and any other guard expression, a call included, is a condition.

checks: idris — defined in: proto/term.proto#TerminalNode — see also: LTAC.3.4, LTIM.2.4.1, LTIM.2.5.4, LTIM.2.7.1

[RDSC.4a.8.2.2] The condition is a where test, evaluated before the firing. The runtime must evaluate it when it selects the activation, under the pump's clock sample ([LTIM.2.8.4]) and series snapshot ([LSER.8.6.1]), and must let the activation fire only when it is true: false and null both withhold it ([LNUL.4.3]). A withheld activation is not a firing. The runtime emits no event for it ([NCBK.2.6]), does not count it as a firing, and does not evaluate the rate gate. Which later tick fires the match is [LTIM.2.5.1]'s.

ratified — checks: alloy×4 idris×3 — see also: LNUL.4.3, LSER.8.6.1, LTIM.2.5.1, LTIM.2.8.4, NCBK.2.6

[RDSC.4a.8.2.3] The rate gate is evaluated once per firing, inside it. The runtime must evaluate it after RULE_FIRE_BEGIN ([NCBK.2.6]) and before the first action, exactly once per firing, and only for an activation whose condition, where the guard has one, was true. The gate records the firing it admits ([LCDB.3.2.1]), so a second evaluation would deny the firing the first admitted. It is a guard: null admits ([LNUL.4.8]), and false suppresses the actions while the firing stands ([LCDB.3.2.1.1]).

A firing whose actions the gate suppressed is still the match's firing. The runtime must not fire that match again on a later tick while it persists ([LTIM.2.5.1]); the next firing comes from a new match.


ratified — checks: alloy×4 idris×16 — see also: LCDB.3.2.1, LCDB.3.2.1.1, LNUL.4.8, LTIM.2.5.1, NCBK.2.6

Expression trees [RDSC.4a.9]#

Join tests (BetaNode) and action expressions (TerminalNode) share the Expr message type defined in proto/rete_expr.proto#Expr. proto/alfa.proto does not import it: an alpha test is an AlphaTest (slot, comparison op, literal or regex), not an expression tree.

There is one operator number space. BinopOp and UnopOp (proto/rete_expr.proto) are the operator enums, and no other enum encodes a DS operator. A consumer holds one operator table.

defined in: proto/rete_expr.proto#Expr

[RDSC.4a.9.1] A slot or pattern index is a byte, and 255 is a marker or nothing. A schema has at most 255 slots ([LGRA.5.11]) and a rule at most 255 patterns ([LGRA.8.7]), so an index runs from 0 to 254. Each field is uint32 on the wire.

Two fields read 255 as a marker, and the two compose:

  • a pattern index of 255 — VarExpr.pattern_index and Expr.entry_stamp — reads the beta's right-side candidate fact rather than a fact of the activation token ([RDSC.4a.7], [IRET.9.3]);

  • VarExpr.slot_index = 255 yields the fact itself, as a fact-reference value, rather than one of its slots. The compiler emits it for a bare binding reference (contributing_track: b) and for the parent-binding fact address in a capture fact.

VarExpr(pattern_index = 255, slot_index = 255) is a legal encoding meaning "the candidate right fact, as a reference", and is emitted whenever a bare binding names the right-side pattern.

The other three fields have no marker: AlphaTest.slot_index, SlotAssign.slot_index and Action.withdraw_pattern_index, which names a pattern of the terminal's own token, where there is no candidate fact.

A loader must refuse, with DS_ERR_DSC_SEMANTIC, an atom holding an index its field cannot hold: above 255 in a field with a marker, or above 254 in one without. Truncating it would change which fact or slot is read, and a silent reinterpretation is the failure mode this format rejects everywhere else. This is a cheap structural need of the loader under [RDSC.9.9], not a defence against a hostile artefact.

An index within its field's range that names nothing faults where the engine uses it. Such an index, one naming no slot of the fact's schema or no pattern of the rule, is not refused at load. Wherever the engine uses it, the engine must raise an EngineError (proto/engine_fault.proto#EngineFault) naming the node or rule that used it ([LERR.9.11]), and halt the tier ([LERR.1.4.7]):

  • ENGINE_FAULT_PATTERN_INDEX for a pattern index, read in an expression or named by a withdraw ([RARC.5.3.3]);

  • ENGINE_FAULT_ARTEFACT_LIED for a slot index, read by an AlphaTest or a VarExpr or written by a SlotAssign.

The engine must not answer the test false, skip the write or drop the withdraw instead. Each would be a silent reinterpretation.

An AlphaTest that faults is one conjunct of its node's tests. A test of the node that answers false decides the fact wherever it stands, and the engine raises the fault only when none does ([LNUL.4.2]). So every conforming runtime meets the fault at the same facts, in whatever order it evaluates the tests.

ratified — defined in: proto/rete_expr.proto#VarExpr — see also: IRET.9.3, LERR.1.4.7, LERR.9.11, LGRA.5.11, LGRA.8.7, LNUL.4.2, RARC.5.3.3, RDSC.4a.7, RDSC.9.9

[RDSC.4a.9.3] A builtin call carries its op, and the compiler settles its arity and where it stands. CallExpr (proto/rete_expr.proto#CallExpr) names a member of BuiltinFn in op and carries its operands in args: a built-in function of [LEXP.3], [LEXP.5] or [LGRA.9.8], or another op a clause has the compiler emit into a CallExpr, such as a cast ([LCST.4.5]) or a lowering's own op ([RLOW.4.6.6.1], [RLOW.6.3.3]).

Arity and placement are the compiler's guarantees ([RDSC.9.9]). The compiler must emit an op only at a site where a clause in force has it emit that op, and with an operand count the op admits, as [RDSC.4a.9.5] states it. A runtime must not refuse an op it has a handler for at the site where the op stands, and must not check at load how many operands a call carries. An artefact that did not come from a conforming compiler carries neither guarantee.

A call whose operands its op does not admit is an EngineError. When a call reaches evaluation with fewer operands than its op takes, with more than an op of fixed count takes, or in a shape its op does not admit, the engine must raise an EngineError whose fault is ENGINE_FAULT_ARTEFACT_LIED (proto/engine_fault.proto#EngineFault) and halt the tier ([LERR.1.4.7]). The artefact has broken a guarantee only the compiler gives, so nothing in it is trustworthy. This holds for every op: an expression builtin, a series read, a lowering's own op and an op standing as an action's expr alike.

Each op's operand count is stated once, in [RDSC.4a.9.5]. The table has one row per member of BuiltinFn but FN_UNSPECIFIED. A row's Min is the fewest operands the op takes and its Max the most; an empty Max sets no upper bound. Shape range admits every count from Min to Max. Shape pairs admits Min operands and then any whole number of pairs, Min + 2n, up to Max where it has one; FN_CALL's pairs are [RDSC.4a.9.4]'s. Shape none admits no count: no clause in force has the compiler emit the op as a call. Past its schema name, a call of FN_PUBLISH carries one operand per slot of that schema, which no row can state. A clause defining an op states the same count; where the two disagree, the table is right. Every runtime's view of the counts must be generated from the table ([STYL.2.15.6.1]), never written by hand.

The one op check a runtime makes is whether it can run the op where it stands. A CallExpr stands at one of two sites: as an action's expr (ACTION_CALL, [RDSC.4a.8]), or inside an expression, a fire guard's included. A runtime holds a handler for an op at a site, and one handler may serve both. A runtime must have a handler for every op at every site where a clause in force has the compiler emit it. At load, a runtime must refuse with DS_ERR_FN_NOT_FOUND an artefact holding a CallExpr whose op it has no handler for at the site where it stands. That is a compatibility refusal ([RDSC.9.9]): the artefact needs a builtin this runtime does not implement there, and loading it would leave a rule that silently never fires, which is indistinguishable from a false predicate. An op at a site where no clause has the compiler emit it is therefore refused by a runtime that holds no handler for it there, and run by one that does.

ratified — defined in: proto/rete_expr.proto#CallExpr — see also: LCST.4.5, LEXP.3, LEXP.5, LERR.1.4.7, LGRA.9.8, RDSC.4a.8, RDSC.4a.9.4, RDSC.4a.9.5, RDSC.9.9, RLOW.4.6.6.1, RLOW.6.3.3

[RDSC.4a.9.4] A call's operands. A CallExpr whose op is FN_CALL carries 2 + 2n operands in args, in this order: the service name, as a string literal; the correlation; then one pair per argument the call supplies, its name as a string literal followed by its value expression. The pairs are in strictly ascending order of name, compared by UTF-8 bytes, and no name appears twice. The compiler must emit this layout ([RDSC.4a.9.3] makes it the compiler's guarantee), and the runtime reads each argument's name from its pair.


ratified — see also: RDSC.4a.9.3

[RDSC.4a.9.5]

Op

Min

Max

Shape

FN_ABS

1

1

range

FN_ROUND

1

1

range

FN_FLOOR

1

1

range

FN_CEIL

1

1

range

FN_TRUNC

1

1

range

FN_SIGN

1

1

range

FN_SQRT

1

1

range

FN_EXP

1

1

range

FN_LN

1

1

range

FN_LOG2

1

1

range

FN_LOG10

1

1

range

FN_POW

2

2

range

FN_SIN

1

1

range

FN_COS

1

1

range

FN_TAN

1

1

range

FN_ASIN

1

1

range

FN_ACOS

1

1

range

FN_ATAN

1

1

range

FN_ATAN2

2

2

range

FN_SINH

1

1

range

FN_COSH

1

1

range

FN_TANH

1

1

range

FN_DEGREES

1

1

range

FN_RADIANS

1

1

range

FN_BIT_COUNT

1

1

range

FN_BIT_LENGTH

1

1

range

FN_EUCLIDEAN_2D

4

4

range

FN_EUCLIDEAN_3D

6

6

range

FN_MANHATTAN_2D

4

4

range

FN_MANHATTAN_3D

6

6

range

FN_CHEBYSHEV_2D

4

4

range

FN_CHEBYSHEV_3D

6

6

range

FN_HYPOTENUSE_2D

2

2

range

FN_HYPOTENUSE_3D

3

3

range

FN_GREAT_CIRCLE

4

4

range

FN_COSINE_2D

4

4

range

FN_COSINE_3D

6

6

range

FN_NOW

0

0

range

FN_FLOOR_TIME

2

2

range

FN_CACHE_GET

1

1

range

FN_EMIT

none

FN_PUBLISH

1

range

FN_LOG

3

3

range

FN_ALERT

none

FN_CALL

2

pairs

FN_RETRACT_CORR

3

3

range

FN_RETRACT_TOKEN_FACT

1

1

range

FN_HYDRATION_CALL

none

FN_CACHE_SET

3

3

range

FN_CACHE_DELETE

1

1

range

FN_RATE_ALLOW

2

range

FN_MIN

2

2

range

FN_MAX

2

2

range

FN_BIT_AND

2

2

range

FN_BIT_OR

2

2

range

FN_BIT_XOR

2

2

range

FN_BIT_NOT

1

1

range

FN_BIT_SHL

2

2

range

FN_BIT_SHR

2

2

range

FN_STR_LENGTH

1

1

range

FN_UPPER

none

FN_LOWER

none

FN_TO_STRING

1

2

range

FN_REGEX_MATCH

2

3

range

FN_JSON_HAS

2

2

range

FN_JSON_PATH

2

2

range

FN_JSON_BUILD

0

pairs

FN_JSON_VALUE

1

1

range

FN_UTC

1

1

range

FN_LOCAL

2

2

range

FN_TIME_DATE

2

2

range

FN_SERIES_MEAN

5

5

range

FN_SERIES_MEDIAN

5

5

range

FN_SERIES_STDEV

5

5

range

FN_SERIES_PSTDEV

5

5

range

FN_SERIES_VARIANCE

5

5

range

FN_SERIES_PVARIANCE

5

5

range

FN_SERIES_RATE

5

5

range

FN_SERIES_DIRECTION

5

5

range

FN_SERIES_MIN

5

5

range

FN_SERIES_MAX

5

5

range

FN_SERIES_COUNT

5

5

range

FN_SERIES_COUNT_DISTINCT

5

5

range

FN_SERIES_COUNT_OF

6

6

range

FN_SERIES_CONTAINS

6

6

range

FN_SERIES_SUM

5

5

range

FN_SERIES_FIRST

5

5

range

FN_SERIES_LAST

5

5

range

FN_SERIES_INTEGRAL

5

5

range

FN_SERIES_ACTIVE_FRACTION

5

5

range

FN_SERIES_BOOL_AND

5

5

range

FN_SERIES_BOOL_OR

5

5

range

FN_SERIES_ONSET_RATE

5

5

range

FN_GENSYM

0

0

range

FN_LATEST

none

FN_ERROR_CODE_MATCHES

2

2

range

FN_SERIES_PERCENTILE

6

6

range

FN_FLOAT_TO_INT

1

1

range

FN_FLOAT_TO_STRING

1

1

range

FN_STRING_TO_FLOAT

1

1

range

FN_STRING_TO_INT

1

1

range

FN_INT_TO_FLOAT

1

1

range

FN_STRING_TO_BOOL

1

1

range

FN_CURRENCY_ROUND

2

2

range

FN_CURRENCY_ROUND_TO

3

3

range

FN_CURRENCY_CONVERT

5

pairs

FN_REGEX_CAPTURE

4

4

range

FN_JSON_LEN

2

2

range

FN_MONOTONIC_NS

0

0

range

FN_HOUR

2

2

range

FN_MINUTE

2

2

range

FN_SECOND

2

2

range

FN_DAY

2

2

range

FN_MONTH

2

2

range

FN_YEAR

2

2

range

FN_DAY_OF_WEEK

2

2

range

FN_DURATION_TO_STRING

1

1

range

FN_ADD_MONTHS

2

2

range

FN_ADD_YEARS

2

2

range

FN_INT_DIV_EXACT

2

2

range

FN_INT_TO_STRING

1

1

range

FN_BOOL_TO_STRING

1

1

range

FN_DATE_ADD_DURATION

2

2

range

FN_DATE_SUB_DURATION

2

2

range

FN_DATE_DIFF

2

2

range

FN_BITS

3

3

range

FN_SIGN_EXTEND

2

2

range

FN_SWAP_BYTES

2

2

range

FN_LEADING_ZEROS

1

1

range

FN_TRAILING_ZEROS

1

1

range

FN_FMA

3

3

range

FN_INTERVAL_CHECK

3

5

pairs

FN_CALENDAR_TIME

7

7

range

FN_CALENDAR_DATE

3

3

range

Ahead-of-time compiled code atom — CompiledCode [RDSC.4c]#

[RDSC.4c.1] The CompiledCode atom carries compiled machine code for a single Rete node (one AlphaNode alpha test, one BetaNode join test, or one TerminalNode RHS). The body contains a fixed-layout slot table of external function pointer slots (zero-filled in the file, and filled at load time by a runtime that executes the code; in this edition none does, [RDSC.4c.3]) followed by position-independent machine code.

see also: RDSC.4c.3

[RDSC.4c.3] In this edition a runtime skips every CompiledCode atom. The runtime must dispose of one, whatever its arch, as [RDSC.9.4] disposes of an unrecognised atom in the skip band, and must not map, wire or execute the code it carries: ahead-of-time compiled code is deferred ([RAOT.1]), and no compiler of this edition emits the atom. The rest of the artefact loads as it would without the atom, and the runtime interprets every node.

ratified — see also: RAOT.1, RDSC.9.4

[RDSC.4c.4] Full specification including body layout, slot table, architecture strings, the AOT compilation pipeline, and compiler flags at [RAOT].


Schema atoms [RDSC.5]#

[RDSC.5.1] Schema atoms carry the schema definition's metadata: TTL, logical flag, slot kinds, hydration eligibility, source location. The runtime builds its schema descriptor from them.

[RDSC.5.2] Each schema atom carries the schema's own name ([LIMP.13.1]) as the join key. The runtime registers each schema by that name; the Rete alpha nodes that match on a schema reference it by that name, and so does every other atom that names a schema.

see also: LIMP.13.1

SchemaTtl — schema TTL [RDSC.5.3]#

[RDSC.5.3.1] The SchemaTtl atom declares a schema's default fact TTL per the language spec's TTL semantics in LFAC.

[RDSC.5.3.2] Body proto: proto/schema_ttl.proto.

defined in: proto/schema_ttl.proto#SchemaTtl

[RDSC.5.3.3] ttl_ns is the time-to-live in nanoseconds applied to facts of this schema. The compiler must omit the SchemaTtl atom when the schema has no TTL; the compiler must not emit SchemaTtl with ttl_ns = 0.

[RDSC.5.3.4] At most one SchemaTtl atom per schema name ([RDSC.7.2.1]).

see also: RDSC.7.2.1

SchemaLogical — schema logical flag [RDSC.5.4]#

[RDSC.5.4.1] The SchemaLogical atom carries a schema's declared scope: the lifecycles of [LSCP.1.5] other than ttl, which SchemaTtl carries ([RDSC.5.4.5]).

see also: LSCP.1.5, RDSC.5.4.5

[RDSC.5.4.2] Body proto: proto/schema_logical.proto.

defined in: proto/schema_logical.proto#SchemaLogical

[RDSC.5.4.3] A SchemaLogical atom carries a schema's lifecycle and its lifecycle field says which ([RDSC.5.4.5]). Absence of the atom makes the schema ttl, which carries an SchemaTtl atom instead.

see also: RDSC.5.4.5

[RDSC.5.4.4] At most one SchemaLogical atom per schema name ([RDSC.7.2.1]).

see also: RDSC.7.2.1

[RDSC.5.4.5] The SchemaLogical atom carries the schema's declared lifecycle, in lifecycle (proto/schema_logical.proto#SchemaLifecycle): EXPLICIT, LOGICAL or ACTIVATION, as scope declared it ([LSCP.1.5]). ttl is not a member — a ttl schema carries an SchemaTtl atom with its duration instead. A runtime must refuse an SchemaLogical atom whose lifecycle is UNSPECIFIED with DS_ERR_DSC_SEMANTIC ([NERR.8.1]): every artefact a runtime accepts was written by a release in its own version series ([LDET.1.10]), and every such release writes the field, so the zero value is a field nobody wrote.

The compiler must emit the field, and the runtime must drive each lifecycle's retraction from it: no engine retraction for EXPLICIT ([LSCP.2.1.1]), justification withdrawal for LOGICAL, and every completion path of the asserting activation for ACTIVATION ([LSCP.2.4.1]).

Slot roles do not carry this and cannot be made to. A logical schema marks every slot key or mutable ([LFAC.1.7.4]), so a schema with a role on no slot is not logical — but explicit and activation are both in that state, and IDENTITY_ROLE_UNSPECIFIED is proto3's zero, so the absence a reader would have to infer from is indistinguishable from a field nobody wrote. A reader that took the absence for MUTABLE would build a logical schema with an empty identity key, under which every fact of the schema is the same fact.

ratified — defined in: proto/schema_logical.proto#SchemaLifecycle — see also: LDET.1.10, LFAC.1.7.4, LSCP.1.5, LSCP.2.1.1, LSCP.2.4.1, NERR.8.1

Slot — slot definition [RDSC.5.5]#

[RDSC.5.5.1] The Slot atom carries a single slot's name, kind, and (when relevant) referenced schema.

[RDSC.5.5.2] Body proto: proto/slot.proto.

defined in: proto/slot.proto#Slot — see also: LFAC.1.7, LFAC.2.5.1, LLEX.9.5

[RDSC.5.5.3] schema_name identifies the owning schema. slot_name is the slot name within that schema.

[RDSC.5.5.4] kind declares the slot's value type per LFAC. The runtime applies type-checked conversion at assert and retract.

[RDSC.5.5.5] schema_ref is required when kind == SLOT_KIND_SCHEMA (a fact-pointer slot) and names the referenced schema by its own name ([LIMP.13.2]), as the file declaring the slot resolves it ([LIMP.1.5]). For other kinds the compiler must leave schema_ref empty, and a runtime must ignore it, in an artefact and in a recording's Slot atom ([RFCS.3.2]) alike.

ratified — see also: LIMP.1.5, LIMP.13.2, RFCS.3.2

[RDSC.5.5.6] One Slot atom per (schema_name, slot_name) ([RDSC.7.2.1]).

see also: RDSC.7.2.1

[RDSC.5.5.7] identity_role declares the slot's identity role per [LFAC.1.7]: IDENTITY_ROLE_KEY (the slot is part of the schema's identity key), IDENTITY_ROLE_MUTABLE (payload) or IDENTITY_ROLE_ENGINE (the engine's ts, [LFAC.9.1]: outside the key and outside the no-op comparison). On a logical schema the compiler emits KEY or MUTABLE for every author slot (require-all, [LFAC.1.7.4]) and ENGINE for ts; on a non-logical schema every slot is IDENTITY_ROLE_UNSPECIFIED. The runtime reads a logical schema's identity key from its KEY slots — it does not infer identity from slot 0 or from a slot named entity_id — and compares its KEY and MUTABLE slots for the no-op test ([LFAC.2.5.1]).

ratified — checks: alloy×5 — see also: LFAC.1.7, LFAC.1.7.4, LFAC.2.5.1, LFAC.9.1

[RDSC.5.5.8] kind is the slot's declared type, and the temporal kinds are Int-represented. The compiler must emit SLOT_KIND_TIME, SLOT_KIND_DATE or SLOT_KIND_DURATION for a slot declared Time, Date or Duration, and SLOT_KIND_DURATION for a slot declared a time unit or time ([LTIM.1.3.5]), never SLOT_KIND_INT. Each is represented on the wire as a signed 64-bit integer exactly as an INT slot is: a Time as the instant's nanoseconds since the epoch in UTC ([LTIM.1.1.3]), a Date as days since the epoch, a Duration as nanoseconds. No zone offset is stored for a Time: a Time is its instant, and a zone applies when it is read ([LTIM.6.5]). A runtime must accept the three kinds as it accepts INT for storage and comparison, and must report the declared type where it reports a slot's type; is Int stays a representation test, true of all three.

ratified — defined in: proto/slot.proto#SlotKind — see also: LTIM.1.1.3, LTIM.1.3.5, LTIM.6.5

Hydration — slot hydration eligibility [RDSC.5.6]#

Deferred: not binding in this edition.

[RDSC.5.6.1] The Hydration atom marks a slot as eligible for hydration per LHYD.

[RDSC.5.6.2] Body proto: proto/hydration.proto.

defined in: proto/hydration.proto#Hydration

[RDSC.5.6.3] Presence of Hydration for (schema, slot) makes the slot hydration-eligible. Absence makes it ineligible.

[RDSC.5.6.4] Hydration may reference only a slot that has a corresponding Slot atom in the same file. The runtime must reject a Hydration atom that names an unknown slot.

[RDSC.5.6.5] At most one Hydration atom per (schema_name, slot_name). The runtime must reject duplicates.

SchemaSource — schema source location [RDSC.5.7]#

[RDSC.5.7.1] The SchemaSource atom records the source location where a schema was declared, for diagnostics.

[RDSC.5.7.2] Body proto: proto/schema_source.proto.

defined in: proto/schema_source.proto#SchemaSource

[RDSC.5.7.3] file is the original .ds source path. line and col are 1-indexed.

[RDSC.5.7.4] At most one SchemaSource atom per schema name ([RDSC.7.2.1]).

see also: RDSC.7.2.1

SchemaDef — schema protobuf definition [RDSC.5.8]#

[RDSC.5.8.1] The SchemaDef atom carries the canonical protobuf definition for a schema. The DS author does not write protobuf; the compiler generates the .proto from the schema's DS declaration. The .proto is the cross-boundary shape for instances of the schema, per [LFST.8.10] and [LFST.11.9].

see also: LFST.11.9, LFST.8.10

[RDSC.5.8.2] Body proto: proto/schema_def.proto.

defined in: proto/schema_def.proto#SchemaDef

[RDSC.5.8.3] proto_source is the .proto text generated by the compiler from the schema declaration. The compiler must declare the field of every nullable slot (T?, the Slot atom's nullable flag, [LNUL.3.1]) as a proto3 optional field, so that its presence is explicit, and must not declare any other field optional. It must declare each slot's field with the proto3 type [RDSC.5.8.7] gives the slot's kind. A fact-reference slot's is uint64 because a recorded fact body carries the referenced fact's handle there ([RFCS.6.3]), and the temporal kinds' is int64 because they are Int-represented ([RDSC.5.5.8]). The runtime stores the text verbatim (the body is COMPRESSION_NONE, [RDSC.4.4]); consumers (storage adapters, replayers, debug tools) read it from the loaded engine via the integrator-facing surface.

The text names the message for the schema's own name ([LIMP.13.1]). The message is the schema's NAME, and the package is ds.dsc.user.v1, followed for a library's schema by the library's path: plant.sensors.Reading is the message Reading in package ds.dsc.user.v1.plant.sensors. So two libraries' schemas of one NAME are two messages in one descriptor pool.

A synthetic schema's proto_source is empty. Its name ([LLEX.10.6.1]) can't be a protobuf message name, and its facts never cross a boundary: none reaches a stream ([RFCS.5.1]), so nothing needs their wire shape.

ratified — see also: LIMP.13.1, LLEX.10.6.1, LNUL.3.1, RDSC.4.4, RDSC.5.5.8, RDSC.5.8.7, RFCS.5.1, RFCS.6.3

[RDSC.5.8.7]

Slot kind

proto3 field type

SLOT_KIND_INT

int64

SLOT_KIND_FLOAT

double

SLOT_KIND_STRING

string

SLOT_KIND_BOOL

bool

SLOT_KIND_JSON

string

SLOT_KIND_SCHEMA

uint64

SLOT_KIND_BYTES

bytes

SLOT_KIND_TIME

int64

SLOT_KIND_DATE

int64

SLOT_KIND_DURATION

int64

ratified

[RDSC.5.8.4] At most one SchemaDef atom per schema name ([RDSC.7.2.1]).

see also: RDSC.7.2.1

[RDSC.5.8.5] (Compiler invariant.) The SchemaDef .proto for a schema and the schema's Slot atoms must describe the same slots. The compiler emits both from a single internal representation; divergence is a compiler bug. The .proto describes no lifecycle and no hydration: SchemaTtl, SchemaLogical and Hydration carry those.

ratified

[RDSC.5.8.6] Round-trip test obligation. The conforming-compiler test suite must include a fixture that loads a .dsc and verifies the [RDSC.5.8.5] invariant mechanically: for every schema whose SchemaDef carries a proto_source, parse it, walk its message fields, and assert that the field set agrees one-for-one with the Slot atoms (slot count; each field's type against the type [RDSC.5.8.7] gives its Slot atom's kind; and the nullable flag against the field's optional, [RDSC.5.8.3]). A fact-reference slot's schema_ref has no .proto side, since its field is uint64 ([RDSC.5.8.3]), so the comparison does not reach it. Lifecycle and hydration are not compared: the .proto describes slots only ([RDSC.5.8.5]). The fixture must cover every slot kind in the [RDSC.5.5] enum (SLOT_KIND_INT, _FLOAT, _STRING, _BOOL, _JSON, _SCHEMA, _BYTES, _TIME, _DATE, _DURATION) and both lifecycles (LOGICAL and TTL), and a nullable slot of every kind that admits one ([LNUL.3.1]). Failure of any unidirectional case (Slot atom without matching .proto field, or .proto field without matching Slot atom) is a compiler bug per [RDSC.5.8.5]. Language-side counterpart at [LFAC.8.6].


ratified — see also: LFAC.8.6, LNUL.3.1, RDSC.5.5, RDSC.5.8.3, RDSC.5.8.5, RDSC.5.8.7

Series backend atoms [RDSC.5a]#

[RDSC.5a.1] Series backend atoms describe the runtime state the engine must allocate for the observation triples on a series declaration per [LSER.13]. Each atom declares one runtime backend keyed by (schema_name, slot_name, identity_slot_name). One author-level series declaration may emit one or more backend atoms depending on which triples appear and which aggregations are referenced — see [RDSC.5a.2].

see also: LSER.13, RDSC.5a.2

[RDSC.5a.1a] A read changes nothing a later read can see (all backends). Every backend's aggregation read computes its value from stored state as of the step's clock, over the window at the firing ([LSER.14.1]). The number of reads is unfixed under any evaluation strategy, so a read must be idempotent: otherwise the result would depend on how many rules reference the series and in what order they were tested ([LSER.8.8]).

A read may evict: drop the samples that have left the window at the step's clock. Every read at that clock or later excludes those samples anyway, because the clock does not go back, so whether a read evicts first changes no answer. A read must make no other change to the state: no lazy decay, sketch-buffer flush or compaction. The per-backend notes — the signal backings [LSIG.2.5] — are instances of this rule.

see also: LSER.14.1, LSER.8.8, LSIG.2.5

[RDSC.5a.2] Triple-driven backend selection. The compiler reads each observation triple (aggregation × time-model × accuracy) declared on the series, groups triples by compatible backings per [LSER.18.1], coalesces shared backings, and emits exactly the backend atoms needed. The wire shapes below name the v1 backings the matrix maps to:

  • SeriesBackendWelfordEwma — Welford running stats. Selected for every aggregation [LSER.18.1] backs with it on all_time (cumulative semantics). v1 is cumulative-only.

  • SeriesBackendRingBuffer — exact ring buffer. Selected for any aggregation on sliding <dur> whose triple admits exact backing per the matrix.

  • SeriesBackendMonotonicDeque — monotonic deque. Selected for exact min / max on sliding.

  • SeriesBackendFifoDeque — FIFO deque. Selected for first / bool_and / bool_or on sliding.

  • SeriesBackendReservoir — reservoir. Selected for the bag aggregations on the sample <n> time model; max_samples carries n.

  • SeriesBackendIntervalPulse — interval pulse ([RDSC.5a.9]). Selected for active_fraction on sliding ([LSIG.1.1]).

  • SeriesBackendNumericIntegral — numeric integral ([RDSC.5a.10]). Selected for integral on sliding and all_time ([LSIG.1.1]).

Every quantile / cardinality / membership / top-k need defers to the exact SeriesBackendRingBuffer bag.

The matrix is the source of truth for triple → backend selection; the wire shapes below are stable, but the selection rules summarised here are illustrative and evolve with the matrix.

A backing no rule reads is not emitted. The compiler may omit a backing that serves no aggregation a rule reads, whether or not the series' other backings are read, and a series no rule reads emits no backend atom at all. Such a series has no meaning: nothing but a rule reads a series ([NSBK.6.3]).

see also: LSER.18.1, LSIG.1.1, NSBK.6.3, RDSC.5a.10, RDSC.5a.9

[RDSC.5a.3] Identity slot. Every backend atom carries identity_slot_name. The empty string indicates by: none (one allocation per (schema, slot, module) with no per-identity breakdown per [LSER.7.6.2]). A non-empty value names the slot of the bound schema that the runtime uses as the per-key dimension.

see also: LSER.7.6.2

SeriesBackendWelfordEwma — Welford running-stats backend [RDSC.5a.4]#

[RDSC.5a.4.1] The SeriesBackendWelfordEwma atom declares a Welford running- stats backend serving every all_time aggregation [LSER.18.1] backs with it, cumulative from boot. It has no windowed (decay) form ([RDSC.5a.4.3]).

see also: LSER.18.1, RDSC.5a.4.3

[RDSC.5a.4.2] Body proto: proto/series_backend_welford_ewma.proto.

defined in: proto/series_backend_welford_ewma.proto#SeriesBackendWelfordEwma

[RDSC.5a.4.3] window_ns is 0 in v1: SeriesBackendWelfordEwma is unwindowed, cumulative-from-boot ([LSER.14.1]) — selected for all_time triples.

see also: LSER.14.1

[RDSC.5a.4.4] persist_ns = 0 indicates the series is live-only. A non-zero value forwards each absorbed sample to the integrator's sample callback per [LSER.8.3] and [NSTG.5].

see also: LSER.8.3, NSTG.5

SeriesBackendRingBuffer — ring buffer backend [RDSC.5a.5]#

[RDSC.5a.5.1] The SeriesBackendRingBuffer atom declares an exact-samples ring-buffer backend over a sliding window. Element type restricts which aggregations compile per [LSER.17].

see also: LSER.17

[RDSC.5a.5.2] Body proto: proto/series_backend_ring_buffer.proto.

defined in: proto/series_backend_ring_buffer.proto#SeriesBackendRingBuffer

[RDSC.5a.5.3] element_type is the inferred element type of the slot (per [LFAC]); the runtime applies type-checked conversion at sample absorption.

[RDSC.5a.5.4] window_ns is required (> 0) — the SeriesBackendRingBuffer backend is only selected for sliding <dur> triples per [RDSC.5a.2]. max_samples carries the series' capacity ([LSER.13.14]); 0 means the series declares none and the window is the only bound. A non-zero max_samples caps the samples each identity retains, even within the window, and a sample arriving at the cap is dropped or refused as [LSER.13.14] states for the backing's aggregation.

see also: LSER.13.14, RDSC.5a.2

[RDSC.5a.5.5] Eviction: per [LSER.9.3], ring-buffer state evicts when no sample for that identity has been absorbed for window_ns.

see also: LSER.9.3

SeriesBackendMonotonicDeque — monotonic-deque backend [RDSC.5a.7d]#

[RDSC.5a.7d.1] The SeriesBackendMonotonicDeque atom declares a monotonic deque providing exact sliding-window min / max. The deque holds the monotonic subsequence of in-window candidates, so a query reads the front in O(1) and amortised insert/evict is O(1); worst-case state is O(window·rate).

[RDSC.5a.7d.2] Body proto: proto/series_backend_monotonic_deque.proto.

defined in: proto/series_backend_monotonic_deque.proto#SeriesBackendMonotonicDeque — see also: LSER.7.6.2

[RDSC.5a.7d.3] window_ns > 0 is required — SeriesBackendMonotonicDeque backs min / max on sliding only (exact min / max on all_time use SeriesBackendWelfordEwma). max_samples carries the series' capacity ([LSER.13.14]) and caps the entries each identity retains; 0 means the window is the only bound.

see also: LSER.13.14

[RDSC.5a.7d.4] Determinism. Updates and eviction are slot-value comparisons and integer-timestamp tests — no transcendental — so SeriesBackendMonotonicDeque is cross-platform bit-exact ([LDET.3.2]) given event-trace order. Queries are read-only ([RDSC.5a.1a]).

see also: LDET.3.2, RDSC.5a.1a

SeriesBackendFifoDeque — FIFO-deque backend [RDSC.5a.7e]#

[RDSC.5a.7e.1] The SeriesBackendFifoDeque atom declares an order-preserving FIFO deque providing sliding-window first, bool_or, and bool_and. bool_* are tracked by an in-window true-count, so the query is O(1); first reads the front. State is O(window·rate) (bounded by max_samples).

[RDSC.5a.7e.2] Body proto: proto/series_backend_fifo_deque.proto.

defined in: proto/series_backend_fifo_deque.proto#SeriesBackendFifoDeque — see also: LSER.7.6.2

[RDSC.5a.7e.3] element_type (the SeriesElementType enum) distinguishes the slot value kind so first returns the correctly typed value and bool_* apply only to Bool slots. Note the field ordering: element_type takes tag 4, shifting window_ns / persist_ns / max_samples to tags 5 / 6 / 7 (unlike the other series backends, where window_ns is tag 4).

[RDSC.5a.7e.4] Determinism. The deque preserves arrival order; first is a value copy and bool_* reduce an integer count — no transcendental — so SeriesBackendFifoDeque is cross-platform bit-exact ([LDET.3.2]) given event-trace order. Queries are read-only ([RDSC.5a.1a]).

see also: LDET.3.2, RDSC.5a.1a

SeriesBackendReservoir — reservoir-sampling backend [RDSC.5a.7g]#

[RDSC.5a.7g.1] The SeriesBackendReservoir atom declares a uniform-random reservoir of size n over all-time history — the backing for the sample <n> time model ([LSMP.5]). State is O(n), independent of stream length. It serves the bag aggregations mean / stdev / pstdev / variance / pvariance / min / max / sum / count / median / pXX / bool_and / bool_or.

see also: LSMP.5

[RDSC.5a.7g.2] Body proto: proto/series_backend_reservoir.proto.

defined in: proto/series_backend_reservoir.proto#SeriesBackendReservoir — see also: LSER.7.6.2

[RDSC.5a.7g.3] max_samples carries the reservoir capacity n. window_ns is 0: a reservoir has no time axis and is bounded by n, not by a window, so there is no time-based eviction. Retention uses a fixed-seed xorshift64 PRNG (seed 0x9e3779b97f4a7c15), advanced once per absorbed sample in event-trace order.

[RDSC.5a.7g.4] Determinism. The retention PRNG is a deterministic function of the input sequence (pure 64-bit integer arithmetic), and the bag aggregations use only correctly-rounded IEEE-754 operations (variance/stdev via sqrt); quantiles sort a scratch copy of the bag, so queries are read-only ([RDSC.5a.1a]). SeriesBackendReservoir is therefore cross-platform bit-exact ([LDET.3.2]) — see [LSMP.2] for the full argument and the relationship to the [LDET.11.4] no-author-RNG rule.

see also: LDET.11.4, LDET.3.2, LSMP.2, RDSC.5a.1a

SeriesBackendIntervalPulse — interval-pulse backend [RDSC.5a.9]#

[RDSC.5a.9.1] The SeriesBackendIntervalPulse atom declares the interval-pulse backing of active_fraction ([LSIG.1.1]). The backing's state, update and query are [LSIG.2.2]'s. Body proto: proto/series_backend_interval_pulse.proto.

defined in: proto/series_backend_interval_pulse.proto#SeriesBackendIntervalPulse — see also: LSIG.1.1, LSIG.2.2

[RDSC.5a.9.2] window_ns > 0 is required: active_fraction is sliding only ([LSIG.1.1]). The slot is Bool, so the body carries no element type. identity_slot_name is empty for a series keyed by: none ([LSER.7.6.2]). max_samples carries the series' capacity ([LSER.13.14]), 0 when it declares none, and a full backing refuses ([LSIG.1.1]). null_policy is the series' nulls: policy ([LNUL.8.6]).

see also: LNUL.8.6, LSER.13.14, LSER.7.6.2, LSIG.1.1

SeriesBackendNumericIntegral — numeric-integral backend [RDSC.5a.10]#

[RDSC.5a.10.1] The SeriesBackendNumericIntegral atom declares the numeric-integral backing of integral ([LSIG.1.1]). The backing's state, update and query are [LSIG.2.3]'s. Body proto: proto/series_backend_numeric_integral.proto.

defined in: proto/series_backend_numeric_integral.proto#SeriesBackendNumericIntegral — see also: LSIG.1.1, LSIG.2.3

[RDSC.5a.10.2] element_type is the slot's, Float or Int ([LSIG.1.1]). time_model is SERIES_TIME_MODEL_SLIDING with window_ns > 0, or SERIES_TIME_MODEL_ALL_TIME with window_ns 0: the compiler refuses every tumbling line ([LSER.18.1]). gap_policy is the series' gap policy ([LSIG.3]) and null_policy its nulls: policy ([LNUL.8.6]); neither stands for the other, and [LSIG.2.3.6] says why the body carries time_model and gap_policy both. identity_slot_name is empty for a series keyed by: none ([LSER.7.6.2]). max_samples carries the series' capacity ([LSER.13.14]), 0 when it declares none, and a full backing refuses ([LSIG.1.1]).

see also: LNUL.8.6, LSER.13.14, LSER.18.1, LSER.7.6.2, LSIG.1.1, LSIG.2.3.6, LSIG.3

Multiplicity and uniqueness [RDSC.5a.8]#

[RDSC.5a.8.1] Each backend atom is at most one per (schema_name, slot_name, identity_slot_name, atom, window_ns) tuple per module ([RDSC.7.2.1]). The runtime must key the state it allocates on the same tuple.

The window is part of the key because a declaration may observe one slot at several of them. mean sliding 10_min as recent beside mean sliding 1_h as hourly selects one backing twice, at two windows, and each read resolves to its own line's window ([LSER.6.8.1]). One atom per (schema, slot, identity) can carry only one of them, so a key omitting the window answers every read of that slot from a single window whatever the author wrote.

The atom is part of it for the reason [RDSC.5a.8.2] gives: parallel backings over one slot are ordinary. No field changes — every backend atom already carries window_ns, and its field number names its backing.

ratified — see also: LSER.6.8.1, RDSC.5a.8.2, RDSC.7.2.1

[RDSC.5a.8.2] One series declaration may emit multiple distinct backend atoms (e.g., a series with both mean, stdev all_time and min, max sliding 5_min triples emits SeriesBackendWelfordEwma + SeriesBackendMonotonicDeque). These share (schema_name, slot_name, identity_slot_name) but differ in atom, or in window_ns where the declaration observes the slot at more than one window; the runtime treats them as parallel backends, each keyed by the full tuple of [RDSC.5a.8.1].

see also: RDSC.5a.8.1

[RDSC.5a.8.3] Different modules may emit backend atoms for the same (schema_name, slot_name, identity_slot_name); each module's atoms apply only within that module's load. Per-module isolation matches the existing per-schema atom multiplicity rule at [RDSC.7.2.1].


see also: RDSC.7.2.1

Rule atoms [RDSC.6]#

[RDSC.6.1] Rule atoms carry rule metadata that the Rete node graph does not itself encode: the cooldown window ([RDSC.6.5]), the source location ([RDSC.6.7]) and the debug display-name template ([RDSC.6.8]).

see also: RDSC.6.5, RDSC.6.7, RDSC.6.8

[RDSC.6.2] Each rule atom carries the rule name as the join key. The runtime correlates rule atoms with the rules realized by the TerminalNode atoms by exact name match.

RuleCooldown — rule cooldown [RDSC.6.5]#

[RDSC.6.5.1] The RuleCooldown atom declares a rule's cooldown window per LCDB.

[RDSC.6.5.2] Body proto: proto/rule_cooldown.proto.

defined in: proto/rule_cooldown.proto#RuleCooldown

[RDSC.6.5.3] window_ns is the cooldown window in nanoseconds. The rate gate in the rule's fire guard ([RLOW.4.6.1]) holds a firing back while less than window_ns has passed since the gate last let it fire for the same activation key ([RLOW.4.6.2.2]). Each key has its own window ([RLOW.4.6.2.3]).

see also: RLOW.4.6.1, RLOW.4.6.2.2, RLOW.4.6.2.3

[RDSC.6.5.4] Absence of a RuleCooldown atom for a rule means the rule has no cooldown.

[RDSC.6.5.5] At most one RuleCooldown atom per rule ([RDSC.7.2.1]).

see also: RDSC.7.2.1

RuleSource — rule source location [RDSC.6.7]#

[RDSC.6.7.1] The RuleSource atom records the source location where a rule was declared, for diagnostics.

[RDSC.6.7.2] Body proto: proto/rule_source.proto.

defined in: proto/rule_source.proto#RuleSource

[RDSC.6.7.3] line and col are 1-indexed. The atom carries no source path: module_id names the rule's module, and the path is that module's DsSource file ([RDSC.14.2.3]).

see also: RDSC.14.2.3

[RDSC.6.7.4] At most one RuleSource atom per rule ([RDSC.7.2.1]).

see also: RDSC.7.2.1

RuleDebugName — rule debug display-name template [RDSC.6.8]#

[RDSC.6.8.1] The RuleDebugName atom carries a display-name template for a rule, used by the DAP debug adapter to label activation threads with human-readable names instead of ephemeral numeric IDs. Old runtimes skip it per [RDSC.9.4].

see also: RDSC.9.4

[RDSC.6.8.2] Body proto: proto/rule_debug_name.proto.

defined in: proto/rule_debug_name.proto#RuleDebugName

[RDSC.6.8.3] name_template is a DS-interpolation-style string. Placeholders {binding.slot} are replaced with the activation's bound value for that slot at activation-creation time. Literal text outside {…} passes through unchanged.

[RDSC.6.8.4] The compiler generates name_template from the rule's LHS patterns. The template is the rule name, (, one entry per contributing pattern in source order separated by , , and ). Each entry is <binding>={<binding>.<slot>}: <binding> is the pattern's binding ([RDSC.6.8.9]), and <slot> is the first key slot the schema declares ([LFAC.1.7]), or the first slot it declares when it declares no key slot. A rule alert_high binding s to a schema keyed on entity_id therefore carries the template alert_high(s={s.entity_id}). The placeholder form is [RDSC.6.8.3]; which patterns contribute is [RDSC.6.8.5] and [RDSC.6.8.6].

ratified — see also: LFAC.1.7, RDSC.6.8.3, RDSC.6.8.5, RDSC.6.8.6, RDSC.6.8.9

[RDSC.6.8.5] A pattern whose schema declares no slots contributes no entry. When no pattern contributes an entry, the compiler emits an empty name_template, and the runtime falls back to "{rule_name} #{sequence}".

[RDSC.6.8.6] Negated patterns (no Schema x) contribute no placeholder — they have no bound value at activation time.

ratified

[RDSC.6.8.9] An omitted pattern binding contributes a placeholder exactly as a written one does. Where the author omits a binding ([LGRA.8.1]) the compiler must interpolate the synthetic name it assigned that pattern, so whether a binding was written does not affect the template's arity. [RDSC.6.8.5] and [RDSC.6.8.6] remain the clauses that decide whether a pattern contributes a placeholder at all.

⚠ This is the one surface on which a synthetic name reaches an author-facing display. [LLEX.10.6.1] gives a synthetic name no surface form, so a reader of a rendered display name may be shown a $-prefixed name they cannot write themselves. A display name identifies an activation rather than naming it in source, so the synthetic spelling is admissible there and in no other author-facing position.

see also: LGRA.8.1, LLEX.10.6.1, RDSC.6.8.5, RDSC.6.8.6

[RDSC.6.8.7] The RuleDebugName atom is optional. The compiler omits it when name_template is empty after generation. The runtime must treat absence of RuleDebugName the same as an empty template — it falls back to the rule-name-plus-sequence display name.

ratified

[RDSC.6.8.8] At most one RuleDebugName atom per rule per module ([RDSC.7.2.1]).


ratified — see also: RDSC.7.2.1

Service-dispatch atoms [RDSC.6a]#

[RDSC.6a.1] Service-dispatch atoms carry the manifest the runtime uses to bind integrator-supplied callbacks by service name at engine init per LADP.8.

see also: LADP.8

ServiceDef — service definition [RDSC.6a.2]#

[RDSC.6a.2.1] The ServiceDef atom carries one service decl as authored in a .ds file: dotted name, kwarg list and response schema (when any).

[RDSC.6a.2.2] Body proto: proto/service_def.proto.

defined in: proto/service_def.proto#ServiceDef

[RDSC.6a.2.3] name is the fully-qualified dotted service path (e.g. light.turn_on). The first segment is the service domain (LIMP.4.2.4). Flat-named services have one segment.

see also: LIMP.4.2.4

[RDSC.6a.2.7] ServiceKwarg.ds_type is the kwarg's declared type. For a schema the compiler must write the schema's own name ([LIMP.13.2]), as the file declaring the service resolves it ([LIMP.1.5]). For any other type it must write the name the declaration spells: a builtin type, a unit symbol, a dimension or scalar-group name, the kind Schema, or an opaque type. Nothing identifies a type other than a schema by that text ([LUNI.4.1.5]).

ratified — see also: LIMP.1.5, LIMP.13.2, LUNI.4.1.5

[RDSC.6a.2.4] Each ServiceKwarg.default_value is the canonical text of the value the service receives when a call omits the kwarg ([LADP.8.5.1], [LADP.8.5.2]), in the storage type of the kwarg's declared type. The compiler must write it, for each declared type a default may take ([LGRA.23.2]), as follows:

Declared type

default_value

Example

Int

the integer in decimal, - first when negative

255, -3

Float

the Float's canonical text ([LDET.3.2.7]), from an Int literal too

1.5; 2.0 for default 2

String

the value in double quotes, each " written \" and each \ written \\

"hello"

Bool

true or false

true

a unit symbol

the quantity expressed in that unit: in decimal where the unit's dimension declares storage int64 ([LUNI.7.2]), else the Float's canonical text

90 for 90 s on an s kwarg; 2 for 120 s on a min kwarg; -10.0 for -10_celsius on a celsius kwarg

a dimension or scalar-group name ([LUNI.7.1])

the quantity in the dimension's base unit, written as for a unit symbol

263.15 for -10_celsius on a temperature kwarg; 90000000000 for 90 s on a time kwarg

A reader of the manifest needs no unit table: the text is the number the service would be called with. default_value is empty when has_default is false.

ratified — see also: LADP.8.5.1, LADP.8.5.2, LDET.3.2.7, LGRA.23.2, LUNI.7.1, LUNI.7.2

[RDSC.6a.2.5] ServiceDef.hydration carries the hydration: block of [LHYD.9.4.1]. ServiceHydration.max_window_ns and max_limit use 0 to mean unspecified. Per-field operator caps are listed verbatim from the source — one of the seven canonical operators (==, !=, <, <=, >, >=, in).

Deferred: not binding in this edition.

see also: LHYD.9.4.1

[RDSC.6a.2.6] A service is identified by its name alone ([LIMP.5.3.1]), so an artefact carries one ServiceDef atom per service. The compiler must not emit a ServiceDef whose name is empty, nor two whose name is the same, from one module or from several ([LCRS.14.9]). module_id attributes the service to the module that declared it and takes no part in its identity.


ratified — see also: LCRS.14.9, LIMP.5.3.1

Source-preservation atoms [RDSC.14]#

[RDSC.14.1] Source-preservation atoms keep canonical source forms in the artefact for downstream tooling (debuggers, inspectors, replayers). The runtime does not require these atoms to operate; loaders may skip them in fast-load configurations. The compiler must emit them in production builds.

DsSource — DS source [RDSC.14.2]#

[RDSC.14.2.1] The DsSource atom carries the original DS source text for one source file. Tooling renders this when showing the author the rule or schema as authored.

[RDSC.14.2.2] Body proto: proto/ds_source.proto.

defined in: proto/ds_source.proto#DsSource

[RDSC.14.2.3] file is the source module's name. The compiler must write, for the file it was asked to compile, the name [RCLI.1.9] gives the input; for a library read from a search-path entry the invocation names ([LIMP.3.1.1]), the path it was read from, as that entry spells it; for a library read from the bundled library ([RCLI.1.11]), <stdlib>/ followed by its path relative to the bundle's directory, its segments joined by / (<stdlib>/calendar.ds, <stdlib>/units/si.ds), whatever directory the compiler found the bundle in; and for a module handed to the compiler with no path, a synthetic name in angle brackets (<in-memory:lib.ds>). The name is an input to the artefact ([RDSC.3.11]): the same library under a search-path entry spelled differently has another name, and a bundled library has one name wherever the compiler is installed. The compiler emits one DsSource atom per source module; the DsSource's module_id is the per-module join key it shares with every other atom belonging to the same module ([RDSC.4.7]).

ratified — see also: LIMP.3.1.1, RCLI.1.11, RCLI.1.9, RDSC.3.11, RDSC.4.7

[RDSC.14.2.4] At least one DsSource atom is required (the importing file). When the importing file imports libraries, additional DsSource atoms cover each transitively- loaded library.

[RDSC.14.2.5] At most one DsSource atom per module_id value ([RDSC.7.2.1]). Display-path strings (file) MAY repeat across modules when synthetic labels happen to collide; the runtime indexes by module_id, not by file.

see also: RDSC.7.2.1

LineSpan — source span [RDSC.14.3]#

The LineSpan atom records a source range, not a single line.

defined in: proto/line_span.proto#LineSpan

[RDSC.14.3.1] The LineSpan atom maps a Rete node (by node_id) to its DS source position. The runtime uses the mapping to translate a runtime diagnostic that references a node back to a DS source line and column.

[RDSC.14.3.2] Body proto (message name LineSpan, retained): proto/line_span.proto.

defined in: proto/line_span.proto#LineSpan

[RDSC.14.3.3] node_id is the bundle-global node index carried by every AlphaNode, BetaNode and TerminalNode atom. ds_line and ds_col are the 1-based DS source line and column of that node's originating construct. module_id identifies the owning module (display path via DsSource[module_id]). Fields 2 and 3 are reserved and never reissued.

[RDSC.14.3.4] Each Rete node the compiler attributes to a source construct carries one LineSpan atom keyed by its node_id. node_ids are bundle-global and unique, so LineSpan atoms cannot collide; a LineSpan atom whose node_id does not correspond to an emitted AlphaNode, BetaNode or TerminalNode atom is a malformed file. The owning module is recovered from the LineSpan atom's module_id.

[RDSC.14.3.5] LineSpan atoms appear once per attributed node; the file contains as many LineSpan atoms as the compiler produced node spans.

[RDSC.14.3.6] LineSpan-emission scope. The compiler must emit one LineSpan atom per beta and terminal node it attributes to a source construct ([RDSC.14.3.4]) — the rule-authored-construct nodes — and none per alpha node. A beta node carries its introducing pattern's join tests and maps to that pattern's source span; a terminal carries the rule's RHS and maps to the rule's source span.

A node the compiler makes for itself carries none, and the compiler must not invent a position for one: a capture view, a continuation's response pattern, a timer's beta, and the terminal of an after follow-up or of a call's sibling rule. Such a node is the compiler's, and a position given to it would point a runtime diagnostic at source that does not contain the node.

An alpha node carries no LineSpan atom because it belongs to no single rule. Its identity is (schema_name, tests) ([IRET.6.6]), so every pattern in the bundle whose schema and tests coincide shares one node, and a shared node has no single source span to name. Its source is the schema declaration, attributed by SchemaSource ([RDSC.5.7]).

That reason is deliberately independent of what an alpha carries. An alpha node may carry tests — [RDSC.4a.6] is the normative statement of the test list, and a where-predicate over one fact and a constant does lower onto one — so this rule must not be derived from an alpha having no tests, nor from a rule-authored predicate never reaching one. Sharing is the property that holds either way, so it is the one the rule rests on.

A predicate hoisted onto a shared alpha therefore has no LineSpan of its own. It is not thereby unattributable: the pattern that introduced it is named by that pattern's own beta LineSpan, and the schema by SchemaSource. A diagnostic naming a predicate's source reads the beta, never the alpha.

The node_id namespace remains AlphaNode / BetaNode / TerminalNode-global ([RDSC.14.3.3]); only the LineSpan-bearing subset is beta + terminal.

see also: IRET.6.6, RDSC.14.3.3, RDSC.14.3.4, RDSC.4a.6, RDSC.5.7

Docstring atom [RDSC.14.4]#

[RDSC.14.4.1] The DocString atom records the docstring of one declaration — a schema, slot, or rule — as structured, node-associated metadata, independently strippable from the full-source DsSource. It buys what DsSource cannot: a source-stripped library .dsc that still ships its documented API surface, and re-parse-free tooling (IDE hovers, doc-gen, debugger node annotations).

[RDSC.14.4.2] Body proto: proto/doc_string.proto.

defined in: proto/doc_string.proto#DocString

[RDSC.14.4.3] target identifies the documented node; schema_name / slot_name / rule_name carry its identity per target kind; text is the UTF-8 docstring. The source location is carried inline as ds_line / ds_col, not as a reference to a LineSpan atom: LineSpan atoms exist only for beta / terminal (rule) nodes ([RDSC.14.3.6]), so schema and slot targets have no LineSpan to reference — inline coordinates keep every DocString atom self-contained for tooling. The compiler emits DocString for schema, slot, and rule targets; DOC_TARGET_MODULE is reserved.

see also: RDSC.14.3.6

[RDSC.14.4.4] Skip-don't-reject. DocString is tooling metadata the engine never decodes; a runtime that does not consume docs recognizes and skips it ([RDSC.9.4]). Its presence is never a load error, and the runtime's proto build need not include DocString.

defined in: proto/doc_string.proto#DocString — see also: RDSC.9.4

[RDSC.14.4.5] Source-metadata tier + strip. DocString joins the source-metadata tier with DsSource and LineSpan; dsc strip drops it. DocString is independently strippable from DsSource — a .dsc may carry DocString with DsSource stripped (ship the API docs without the source).

[RDSC.14.4.6] The compiler must emit DocString atoms in a canonical order (by module_id, then declaration order) so the .dsc stays bit-identical — the same discipline as DsSource / LineSpan.

[RDSC.14.4.7] DocString is the docstring home. It is the only wire home for docstrings. Schema/rule/slot docstrings all travel as DocString.

[RDSC.14.4.8] DocString and LineSpan each hold a field number of their own in proto/atom.proto#Atom ([RFCS.16.1]), distinct from every other atom's, the stream-only StreamHeader included ([RDSC.7.5]).


see also: RDSC.7.5, RFCS.16.1

Dialect atom [RDSC.15]#

[RDSC.15.1] The DialectInfo atom records the name of the dialect the program's use directive named. It is informational: what the runtime executes under, and what binding compares, is the resolved settings of the CapabilityInfo atom ([RDSC.16.2]), never the name.

see also: RDSC.16.2

[RDSC.15.2] Body proto: proto/dialect.proto.

defined in: proto/dialect.proto#DialectInfo

[RDSC.15.3] name is the dialect name from the program's use directive ([LDIA.2.2]).

see also: LDIA.2.2

[RDSC.15.4] The DialectInfo atom is file-level: it has no module_id field. Only the program has a dialect; the libraries compiled into it have none ([LDIA.2.10.1]).

see also: LDIA.2.10.1

[RDSC.15.5] The DialectInfo atom is optional. Old compilers that do not emit it produce files that load cleanly on runtimes that support RDSC.15 — the runtime treats absence as dialect unknown.

see also: RDSC.15

[RDSC.15.6] At most one DialectInfo atom per file. The compiler must write no second, and the runtime does not check for one ([RDSC.7.2]).


see also: RDSC.7.2

Capability and RT-configuration atoms [RDSC.16]#

[RDSC.16.1] Capability atoms record the program's resolved settings and the capabilities its content requires, and, when realtime is true, the static RT parameters the runtime needs to pre-allocate resources.


CapabilityInfo — capability settings [RDSC.16.2]#

[RDSC.16.2.1] The CapabilityInfo atom records the program's resolved settings ([LDIA.1.3]) and the capabilities its content requires ([RDSC.16.2.8]). The runtime executes under the recorded settings: they, and nothing an integrator configures, select the engine's strategy ([LDET.1.12]).

see also: LDET.1.12, LDIA.1.3, RDSC.16.2.8

[RDSC.16.2.2] Body is a proto3-encoded CapabilityInfo message (proto/capabilities.proto). enabled lists every capability whose resolved setting is true; every capability of [LCAP.1] absent from it is false. requires lists the capabilities of [RDSC.16.2.8].

defined in: proto/capabilities.proto#CapabilityInfo — see also: LCAP.1, RDSC.16.2.8

[RDSC.16.2.3] What the message layout does not carry ([STYL.2.15.4]): each of enabled and requires is in ascending Capability order, without repetition and without CAPABILITY_UNSPECIFIED, and requires is a subset of enabled. The compiler must write them so, and the runtime must reject a body that breaks any of these with DS_ERR_DSC_SEMANTIC.

[RDSC.16.2.4] The CapabilityInfo atom is required: every artefact is built from a program, and every program has settings ([LDIA.2.10.1]). The runtime must reject an artefact without one with DS_ERR_DSC_SEMANTIC.

see also: LDIA.2.10.1

[RDSC.16.2.5] At most one CapabilityInfo atom per file. The compiler must write no second, and the runtime does not check for one ([RDSC.7.2]).

see also: RDSC.7.2

[RDSC.16.2.6] The CapabilityInfo atom is file-level (no module_id).

[RDSC.16.2.7] A capability the build lacks. Before decoding any atom body other than the header and the CapabilityInfo atom, the runtime must compare requires against the capabilities it was built with. For a member of requires it lacks, including a Capability value it does not know, the load fails with DS_ERR_DSC_CAPABILITY_ABSENT. When several are lacking, the error names the lowest, so the answer is stable. The detail names the capability as a value of proto/capabilities.proto#Capability.

This code means only that the runtime was compiled without the code. An artefact whose settings the integration does not admit is a policy refusal, DS_ERR_BND_DIALECT_MISMATCH ([NLFC.10]), and the two must stay distinct.

see also: NLFC.10

[RDSC.16.2.8] requires is computed from content. The compiler must list in requires exactly the capabilities whose code the artefact's content needs, whatever the settings: a capability can be true and unused. A strategy that is set (realtime, constspace) has no use site and is needed all the same: it decides how the engine carries out the whole program, so it is listed whenever it is true.

A runtime trusts requires ([RDSC.9.9]). It compares requires against its build ([RDSC.16.2.7]) and does not check it against the content. An artefact that did not come from a conforming compiler carries no guarantee that its requires names every capability its content needs.

see also: RDSC.16.2.7, RDSC.9.9

[RDSC.16.2.9] Order of the load-time checks. A load checks, in order: the capabilities the build lacks ([RDSC.16.2.7]); then the integration's admission policy ([NLFC.10]); then, where the load pairs artefacts, binding ([RBND.5]). The first failure is the one reported.


see also: NLFC.10, RBND.5, RDSC.16.2.7

RealtimeContract — realtime contract [RDSC.16.3]#

[RDSC.16.3.1] The RealtimeContract atom carries the realtime contract supplied by the author in a sibling .dsrt file when the resolved dialect includes realtime. The atom is fully specified in [RTCT.6]; this section covers only the DSC-side framing and load behaviour.

see also: RTCT.6

[RDSC.16.3.2] The RealtimeContract atom is required in any DSC produced from a realtime source and prohibited in any DSC produced from a non-realtime source. Exactly one RealtimeContract atom per file when present; runtime rejection on duplicate.

[RDSC.16.3.3] Loader behaviour. When the loader encounters a RealtimeContract atom, it takes these steps in this order. The refusals and their codes are [RTCT.6.5]'s, which wins where the two disagree; this clause orders them and adds what follows a contract that passes:

  1. Decode the RealtimeContract proto body ([RTCT.6.2]) and determine the encoding ([RTCT.6.7.1] — legacy nodes list or compact node_count/default_node_cap/node_overrides/ node_caps_packed). Reject an invalid or ambiguous encoding (both set, bad ordering, length mismatch) with DS_ERR_CONTRACT_INVALID.

  2. Cross-check the body's rt_config_sha256 against the value in DscHeader.rt_config_sha256 ([RDSC.3.8]); disagreement is DS_ERR_BND_INCOMPLETE.

  3. Materialize the logical contract ([RBND.4b.8]) and recompute the canonical-serialization hash ([RBND.4b]) over it; disagreement with the stored hash is DS_ERR_CONTRACT_INVALID. This step is the integrity linchpin: it is what binds the contract to the network the runtime actually loaded now that the compact encoding omits per-node kind, and it is what makes a pre-compact runtime reject a compact contract ([RTCT.6.7.6]). It MUST run for both encodings and MUST precede step 4.

  4. Apply node caps to their destinations. For each covered node in ascending node_id order, resolve its capacity per [RTCT.6.7.3] / [RTCT.6.7.4] and write it to that node's contract_capacity ([RTCT.7.1]). The runtime MUST NOT materialize a per-node intermediate structure beyond the per-node destination field; for the compact encoding the resolution is a single pass consuming default_node_cap / node_overrides / node_caps_packed directly.

  5. Store the scalar caps and series caps on the engine for cap enforcement ([RTCT.7]).

see also: RBND.4b, RBND.4b.8, RDSC.3.8, RTCT.6.2, RTCT.6.5, RTCT.6.7.1, RTCT.6.7.3, RTCT.6.7.4, RTCT.6.7.6, RTCT.7, RTCT.7.1

[RDSC.16.3.4] Missing RealtimeContract under realtime is DS_ERR_CONTRACT_MISSING. This case is unreachable for a .dsc produced by a conforming compiler (since [RTCT.4.4] mandates emission) but the runtime still checks defensively.

see also: RTCT.4.4

[RDSC.16.3.5] Position. RealtimeContract appears between the DscHeader header atom and the first per-module group (the first DsSource atom); absolute position within that range is not specified.

[RDSC.16.3.7] Body revisions vs registry. The atom registry ([RDSC.7.1]) tracks which atoms exist and their field numbers, not body-proto revisions. The compact node-cap encoding ([RTCT.6.7]) adds fields 11–14 to the RealtimeContract body; because RealtimeContract already exists in the registry and the encoding is gated on the realtime capability with an encoding-independent hash ([RBND.4b.8]), it is a body revision, not a registry change, and adds no registry row. A runtime that does not understand the compact encoding is unaffected on non-realtime bundles, and rejects a compact realtime contract structurally per [RTCT.6.7.6].

see also: RBND.4b.8, RDSC.7.1, RTCT.6.7, RTCT.6.7.6

[RDSC.16.3.7b] Renaming an atom's body message is not a format change. An atom is identified by its field number ([RFCS.16.1]), so a rename that keeps the field number and the body's fields adds no registry row, and a reader built before it reads the atom unchanged.


see also: RFCS.16.1

Initial-block atoms [RDSC.17]#

[RDSC.17.1] An InitialFact atom carries one fact item of a ruleset's initial: block ([LGRA.24]), and an InitialCacheSeed atom one cache item. Body proto: proto/initial.proto.

defined in: proto/initial.proto#InitialFact, proto/initial.proto#InitialCacheSeed — see also: LGRA.24

[RDSC.17.2] module_id names the module whose block holds the item ([RDSC.4.7]), and source_order the item's place in that block, counted over its fact and cache items together. A runtime must apply the items in ascending module_id, then ascending source_order: that is [LGRA.24.3]'s order, because module_id ascends in import-DAG order ([RDSC.8.1.1]). A fact item's slot values and a cache item's value are TestSlotLiterals, as a .dstest's TestFact carries them; a cache item's slot_name is unused.

see also: LGRA.24.3, RDSC.4.7, RDSC.8.1.1

Atom registry [RDSC.7]#

[RDSC.7.6] The complete atom registry.

An atom's identity on the wire is its oneof field number ([RFCS.16.1]), and its name is its body message: the Atom column below, which is also how [RDSC.8.1]'s grammar states it as a terminal. That number is the Field # column, which is the field the atom occupies in proto/atom.proto#Atom's body oneof — so a reader holding [RDSC.7.1] and not the proto can identify an atom and not merely frame one. A struck row is out of use: its Field # cell names the numbers proto/atom.proto#Atom reserves for it, and they are never reissued.

The test atoms (TestCase / TestFact / TestCacheSeed / TestResponse / TestReply) and the oracle atoms (OracleActivated / OracleEmit / OraclePublish / OracleCall / OracleCacheSet / OracleCacheDelete / OracleLog / OracleRetract / OracleWorkingMemory / OracleExclusive) are skip-don't-reject additive test metadata ([LTSL] / [RTIM]): a production runtime that does not run tests skips them per RDSC.9.4 and runs reactive execution unchanged. Each holds a field number of its own, so a self-contained [DSC][StreamHeader] stream ([RFCS.13]) stays unambiguous ([RDSC.7.5]). A bundle carrying them costs a non-test runtime only file size.

see also: RDSC.7.1, RDSC.7.5, RDSC.8.1, RFCS.13, RFCS.16.1

[RDSC.7.1]

Atom

Field #

Multiplicity

module_id

Concern

Container-legality

Stream-class

DscHeader

263

exactly 1

no

compiler version, build metadata

DSC

—

DialectInfo

264

at most 1

no

dialect the root module compiled against

DSC

—

CapabilityInfo

265

exactly 1

no

capability settings and requires

DSC

—

~~Connection~~

266

—

—

Reserved, out of use. Field 266 is never reissued

—

—

RealtimeContract

128

exactly 1 iff realtime, else 0

no

realtime contract (RTCT.6)

DSC

—

DsSource

267

per module

yes

original DS source text

DSC

—

AlphaNode

268

per alpha node

no

one Rete alpha filter node (RDSC.4a)

DSC

—

BetaNode

269

per beta node

no

one Rete join node (RDSC.4a)

DSC

—

TerminalNode

270

per terminal node

no

one Rete terminal node (RDSC.4a)

DSC

—

LineSpan

303

per span × per module

yes

Rete-node source span

DSC

—

DocString

304

per documented decl × per module

yes

structured docstrings (schema/slot/rule); skip-don't-reject tooling metadata

DSC

—

SchemaTtl

300

per schema × per module

yes

schema TTL

DSC

—

SchemaLogical

299

per schema × per module

yes

schema logical-fact flag

DSC

—

Slot

257

per slot × per module

yes

slot name, kind, schema reference

both

structural

Hydration

301

per slot × per module

yes

slot hydration eligibility

DSC

—

SchemaSource

302

per schema × per module

yes

schema source location

DSC

—

SchemaDef

256

per schema × per module

yes

canonical schema .proto definition

both

structural

~~RuleBand~~

305

—

—

Reserved, out of use. Field 305 is never reissued

—

—

~~RuleRefraction~~

306

—

—

Reserved, out of use. Field 306 is never reissued

—

—

RuleCooldown

307

per rule × per module

yes

rule cooldown window

DSC

—

~~RuleDebounce~~

308

—

—

Reserved, out of use. Field 308 is never reissued

—

—

RuleSource

309

per rule × per module

yes

rule source location

DSC

—

RuleDebugName

310

per rule × per module (optional)

yes

DAP debug display-name template

DSC

—

ServiceDef

311

per service × per module

yes

service-dispatch manifest (LADP.8)

DSC

—

SeriesBackendWelfordEwma

312

per (schema, slot, id-slot) × per module

yes

series Welford running-stats backend, cumulative (LSER)

DSC

—

SeriesBackendRingBuffer

313

per (schema, slot, id-slot) × per module

yes

series ring-buffer backend (LSER)

DSC

—

SeriesBackendMonotonicDeque

314

per (schema, slot, id-slot) × per module

yes

series monotonic-deque min/max (LSER)

DSC

—

SeriesBackendFifoDeque

315

per (schema, slot, id-slot) × per module

yes

series FIFO-deque first/bool (LSER)

DSC

—

SeriesBackendReservoir

316

per (schema, slot, id-slot) × per module

yes

series reservoir-sampling backend (LSER)

DSC

—

SeriesBackendIntervalPulse

129

per (schema, slot, id-slot) × per module

yes

series interval-pulse backend, active_fraction (LSIG); reject-don't-skip

DSC

—

SeriesBackendNumericIntegral

130

per (schema, slot, id-slot) × per module

yes

series numeric-integral backend, integral (LSIG); reject-don't-skip

DSC

—

InitialFact

131

per fact × per module

yes

a ruleset initial: fact (LGRA.24); program content, so reject-don't-skip

DSC

—

InitialCacheSeed

132

per cache seed × per module

yes

a ruleset initial: cache seed (LGRA.24); program content, so reject-don't-skip

DSC

—

~~portable IR expression atoms~~

271–278, 322

—

—

Reserved, out of use. Fields 271–278 and 322 are never reissued

—

—

~~portable IR action atoms~~

279–286

—

—

Reserved, out of use. Fields 279–286 are never reissued

—

—

CompiledCode

298

per node × per arch

no

AOT compiled code blob (RDSC.4c)

DSC

—

TestCase

317

per test case × per module

yes

.dstest scenario: one test case (LTSL); skip-don't-reject

DSC

—

TestFact

318

per fact placement × per test

yes

.dstest scenario: an initial/timeline input fact (LTSL); skip-don't-reject

DSC

—

TestCacheSeed

319

per cache seed × per test

yes

.dstest scenario: initial: cache seed (LTSL); skip-don't-reject

DSC

—

TestResponse

320

per for call stub × per test

yes

.dstest scenario: outbound-call reply stub (LTSL); skip-don't-reject

DSC

—

TestReply

321

per reply fact × per stub

yes

.dstest scenario: a stub reply fact (LTSL); skip-don't-reject

DSC

—

OracleActivated

287

per assertion × per test

yes

.dstest oracle: activated <rule> (LTSL); skip-don't-reject

DSC

—

OracleEmit

288

per assertion × per test

yes

.dstest oracle: emitted <Schema> (LTSL); skip-don't-reject

DSC

—

OraclePublish

289

per assertion × per test

yes

.dstest oracle: published <Schema> (LTSL); skip-don't-reject

DSC

—

OracleCall

290

per assertion × per test

yes

.dstest oracle: called <service> (LTSL); skip-don't-reject

DSC

—

OracleCacheSet

291

per assertion × per test

yes

.dstest oracle: cached "k" (LTSL); skip-don't-reject

DSC

—

OracleCacheDelete

292

per assertion × per test

yes

.dstest oracle: cache_deleted "k" (LTSL); skip-don't-reject

DSC

—

~~OracleRecord~~

293

—

—

Reserved, out of use. Field 293 is never reissued

—

—

OracleLog

294

per assertion × per test

yes

.dstest oracle: logged <level> (LTSL); skip-don't-reject

DSC

—

~~OracleAlert~~

295

—

—

Reserved, out of use. Field 295 is never reissued

—

—

OracleRetract

296

per assertion × per test

yes

.dstest oracle: retracted <Schema> (LTSL); skip-don't-reject

DSC

—

OracleWorkingMemory

297

per assertion × per test

yes

.dstest oracle: wm has/count/empty (LTSL); skip-don't-reject

DSC

—

OracleExclusive

324

per assertion × per test

yes

.dstest oracle: exclusive <rule>, <rule> (LTSL.8.8); skip-don't-reject

DSC

—

defined in: proto/atom.proto#Atom

[RDSC.7.2] "exactly 1" means the compiler must write exactly one such atom. The runtime must reject a file with none, and does not check for a second: every multiplicity of [RDSC.7.1] is the compiler's guarantee, which the runtime does not re-check ([RDSC.9.9]). An artefact that did not come from a conforming compiler carries none of them.

see also: RDSC.7.1, RDSC.9.9

[RDSC.7.2.1] "per module" means at most one atom per module_id value (DsSource) or one per (module_id, named entity) pair (every other per-module atom). The compiler must write no duplicate within a module's namespace, and the runtime does not check for one ([RDSC.7.2]). A schema's own name ([LIMP.13.1]), a rule's name ([LGRA.6.8]) and a service's name ([LCRS.14.9]) are each unique in a program, so the compiler must write no two schema_groups of one name, no two rule_groups of one rule and no two ServiceDefs of one service. No atom of one module replaces an atom of another.

see also: LCRS.14.9, LGRA.6.8, LIMP.13.1, RDSC.7.2

[RDSC.7.3] "per schema" / "per slot" / "per rule" means at most one atom per named entity; multiple atoms of the same kind are permitted when each names a different entity. A schema, its slots and a rule each belong to one module ([RDSC.7.2.1]).

see also: RDSC.7.2.1

[RDSC.7.4] An atom whose field number this table does not list comes from a newer compiler. A runtime disposes of it by its field number's band ([RDSC.9.4]).

see also: RDSC.9.4

[RDSC.7.5] StreamHeader is an event-trace framing atom and must not appear in a DSC: it has no row in the [RDSC.7.1] registry. This keeps a concatenated self-contained stream [DSC][StreamHeader] ([RFCS.13]) unambiguous: a reader walking the DSC atoms recognises the StreamHeader atom as "DSC done, event trace begins" and never mistakes a DSC atom for it.

The format makes a collision unrepresentable rather than merely prohibited. An atom's identity is its oneof field number ([RFCS.16.1]), and two members of one oneof cannot share a number. What the rule protects, the [RFCS.13] boundary walk, holds ([RFCS.19.4]).


see also: RDSC.7.1, RFCS.13, RFCS.16.1, RFCS.19.4

Canonical emission order [RDSC.8]#

[RDSC.8.1] The canonical atom order is a grammar. Each terminal is one framed atom ([RFCS.19.1]); the lexicon binding a terminal to its oneof field number is the registry [RDSC.7.1].

Each terminal is the protobuf message that is the atom's body. An atom's identity is its field number ([RDSC.1.2], [RFCS.16.1]), and the message reached from that field is the one name for it that the format itself defines — so a reader can resolve every terminal below against proto/ without an intermediate table.

dsc            ::= header module_group* rete_network? code_atom*

header         ::= DscHeader DialectInfo? CapabilityInfo RealtimeContract?

module_group   ::= DsSource schema_group* series_atom* rule_group*
                   ServiceDef* DocString* initial_atom* test_group*

initial_atom   ::= InitialFact | InitialCacheSeed

schema_group   ::= lifecycle_atom Slot* Hydration* SchemaSource SchemaDef
lifecycle_atom ::= SchemaTtl | SchemaLogical

series_atom    ::= SeriesBackendWelfordEwma | SeriesBackendRingBuffer
                 | SeriesBackendMonotonicDeque | SeriesBackendFifoDeque
                 | SeriesBackendReservoir | SeriesBackendIntervalPulse
                 | SeriesBackendNumericIntegral

rule_group     ::= RuleCooldown? RuleSource RuleDebugName?

test_group     ::= TestCase TestFact* TestCacheSeed* response_stub* oracle_atom*
response_stub  ::= TestResponse TestReply*
oracle_atom    ::= OracleActivated | OracleEmit | OraclePublish | OracleCall
                 | OracleCacheSet | OracleCacheDelete
                 | OracleLog | OracleRetract | OracleWorkingMemory
                 | OracleExclusive

rete_network   ::= AlphaNode* BetaNode* TerminalNode* LineSpan*

code_atom      ::= CompiledCode

rete_network and code_atom* are bundle-global. Each occurs at most once for the whole artefact, after every module_group — not once per module. AlphaNode / BetaNode / TerminalNode carry no module_id ([RDSC.7.1]) and are joined by node_id ([RDSC.4.7]), so there is no module for them to be grouped under.

A schema takes exactly one lifecycle atom, SchemaTtl or SchemaLogical — never both, never neither.

The grammar is the normative statement of order ([STYL.2.15.5]).

The grammar is context-free; the format is not. Loading a .dsc is a context-sensitive process: whether an atom is required, where it may sit, and whether it is well-formed can all depend on a value carried in a different atom, or on the whole parsed stream. No production can say any of that. Each such condition is therefore stated in English beside the grammar, once, explicitly ([STYL.2.15.4]):

  • conditional cardinality — [RDSC.8.5]

  • ordering by field value — [RDSC.8.6]

  • cross-atom referential integrity — [RDSC.8.7]

  • the closed alphabet — [RDSC.8.8]

  • order within a group, which is source order — [RDSC.8.4]

Those five are not commentary on the grammar. They are the part of the format a context-free grammar cannot reach, and a reader who has read only the productions has not yet read the format.

see also: RDSC.1.2, RDSC.2, RDSC.4.7, RDSC.7.1, RDSC.8.4, RDSC.8.5, RDSC.8.6, RDSC.8.7, RDSC.8.8, RFCS.16.1, RFCS.19.1

[RDSC.8.1.1] module_id ascending order matches import-DAG topological order — leaf libraries first, the importing file last — so a schema or node declared in a library is loaded before any downstream reference to it.

[RDSC.8.2] Reason for schemas-before-network: the runtime registers schema metadata (slot kinds, TTL, logical flag) before it assembles the Rete nodes. Having that metadata in place before the alpha nodes referencing those schemas lets the runtime validate name correspondence and slot count as the network is built.

The ordering holds because every module_group precedes the bundle-global rete_network ([RDSC.8.1]) — so all schemas are registered before any node is assembled, across the whole artefact rather than one module at a time.

see also: RDSC.8.1

[RDSC.8.3] Rule metadata is resolved by name, not by position. A rule_group's atoms reference a rule that a TerminalNode atom realizes, and the runtime attaches RuleCooldown / RuleSource data to known rules in a single pass once the network is assembled.

That pass is what makes the ordering in [RDSC.8.1] workable at all: a rule_group is emitted inside its module_group, while rete_network is bundle-global and arrives after every module group. So the metadata precedes the terminals it names, and a reader that tried to attach it on sight would fail on the first rule. It accumulates instead, and resolves at the end.

The name alone is the join: TerminalNode carries no module_id, and a rule's name picks out one rule in an artefact ([LGRA.6.8]).

see also: LGRA.6.8, RDSC.8.1

[RDSC.8.4] Within a group, the compiler must emit atoms in source order: the order of their declarations in the module's .ds file. Atoms that one declaration yields follow the order of its parts, so a schema's Slot atoms are in the order of its slots ([RLOW.3.2.1]).

A series declaration's backend atoms follow its lines. Each atom is one backing at one window ([RDSC.5a.8.1]), so one backing at two windows is two atoms. An atom that several lines share ([RDSC.5a.2]) takes the place of the first line that selects it. Atoms that one line selects first share its window, and follow [RDSC.8.1]'s series_atom alternation.

The order of the TerminalNode atoms is the terminal ordinal, the first key of the firing order ([LDET.5.4]). The compiler must emit them in [RLOW.14.3]'s order, which is source order across the import DAG. The runtime must number the terminals from that sequence and from nothing else: in particular not from the order of the rule_groups, which it resolves by name ([RDSC.8.3]).

What the world outside the program reads is sorted instead. A call's kwargs and a service's are in name order ([RDSC.4a.9.4], [LGRA.23.2]), and the header's capability lists and node-cap overrides in number order ([RDSC.16.2.3], [RTCT.6.7.3]).


ratified — see also: LDET.5.4, LGRA.23.2, RDSC.16.2.3, RDSC.4a.9.4, RDSC.5a.2, RDSC.5a.8.1, RDSC.8.1, RDSC.8.3, RLOW.14.3, RLOW.3.2.1, RTCT.6.7.3

[RDSC.8.5] Side condition — conditional cardinality. [RDSC.8.1] marks DialectInfo and RealtimeContract optional. A grammar cannot say what each is conditional on, because the condition depends on a value carried in another atom. CapabilityInfo is not optional: every artefact carries exactly one ([RDSC.16.2.4]).

  • DialectInfo is present when the program's dialect is known ([RDSC.15.3]).

  • RealtimeContract is present exactly when CapabilityInfo.enabled holds realtime, and absent otherwise ([RTCT.6]). The runtime must reject an artefact carrying a RealtimeContract atom whose CapabilityInfo does not enable realtime: the contract would bind caps nothing asked for.

see also: RDSC.15.3, RDSC.16.2.4, RDSC.8.1, RTCT.6

[RDSC.8.6] Side condition — ordering by field value. One ordering in [RDSC.8.1] is a property of the atoms' contents rather than of the productions, so the grammar admits sequences this rule forbids: module_groups appear in module_id ascending order. The reason that order is the useful one is [RDSC.8.1.1].

see also: RDSC.8.1, RDSC.8.1.1

[RDSC.8.7] Side condition — cross-atom referential integrity. [RDSC.8.1] admits a well-formed atom sequence whose atoms name things no other atom defines. Each of these is a well-formedness condition over the parsed stream, not over the production set.

  • A Hydration atom names a slot that a Slot atom in the same file declares ([RDSC.5.6.4]), and at most one Hydration exists per (schema, slot) ([RDSC.5.6.5]).

  • A rule_group's atoms name a rule that a TerminalNode atom realizes ([RDSC.8.3]).

  • An AlphaNode atom names a schema that some schema_group registers.

  • An oracle_atom, and every test atom but TestCase and TestReply, names the TestCase test it belongs to; a TestReply names the TestResponse stub it answers.

Note that the first three of these are satisfied across the bundle-global boundary: a rule_group is emitted inside its module_group, while the TerminalNode atom realizing its rule arrives later, in rete_network. The reference is by name, resolved once the whole artefact is read, never by position.

A loader must refuse an artefact in which an atom it reads names something that no atom in the artefact defines, as listed above, with DS_ERR_DSC_DANGLING ([RDSC.11.1]). The artefact alone decides.

The stream is parsed when every atom body is decoded in full: its protobuf decode ([RDSC.9.5]), and the shape a network node's own clause gives it, which covers a node id ([RDSC.4a.3]), an AlphaNode's schema name ([RDSC.4a.6.3]) and an expression's shape ([RDSC.11.3]). A loader must refuse a body that fails any of these before it checks a name this clause lists, so an artefact with both defects is refused for the body. A check that needs the registered schemas is not part of decoding a body.

The last bullet binds the reader of test atoms, not a runtime's loader. A runtime skips the test and oracle atoms ([RDSC.7.6], [RTIM.8.3.1]), and [RDSC.9.9] forbids it to analyse what its load does not use, so it does not check what they name. The .dstest interpreter reads them, and it must refuse the run, running no case, over a test atom that names a test or a stub no atom declares ([RTIM.14.15]).

ratified — see also: RDSC.11.1, RDSC.11.3, RDSC.4a.3, RDSC.4a.6.3, RDSC.5.6.4, RDSC.5.6.5, RDSC.7.6, RDSC.8.1, RDSC.8.3, RDSC.9.5, RDSC.9.9, RTIM.14.15, RTIM.8.3.1

[RDSC.8.8] Side condition — the alphabet is closed, and it is not the fact stream's. The terminals of [RDSC.8.1] are the DSC atoms of [RDSC.7.1], named by their body message, and no others. A grammar states how its terminals combine; it cannot state which symbols are not terminals, and here that needs saying.

The event trace is a separate format that shares this one's framing and two of its terminals, SchemaDef and Slot ([RFCS.3.1]). Its other atoms, every other row of [RFCS.3.1], are not DSC atoms and must not appear in a .dsc.

see also: RDSC.7.1, RDSC.8.1, RFCS.3.1

Loading semantics [RDSC.9]#

[RDSC.9.1] The runtime reads atoms in stream order. For each atom the loader reads the outer frame, then the inner Atom's oneof tag, looks up the registered handler for that field number, and dispatches the body bytes to it ([RFCS.19.1], [RFCS.16.1]).

Reading in stream order is not a licence to act on every atom as it is read: [RDSC.4c.3] forbids acting on a CompiledCode atom at all in this edition.

see also: RDSC.4c.3, RFCS.16.1, RFCS.19.1

[RDSC.9.2] The loader must process the DscHeader atom first and verify its compiler_version against the runtime's own <major>.<minor>. series ([LDET.1.10]) before processing any further atom.

see also: LDET.1.10

[RDSC.9.3] The loader processes atoms in a single forward pass and does not re-order atoms. AlphaNode / BetaNode / TerminalNode atoms reference each other by node_id (globally unique per bundle), so cross-module references resolve regardless of stream position; emitting per-module groups in module_id ascending order keeps a declaration ahead of its downstream references.

[RDSC.9.4] An unrecognised atom is disposed of by its band, and skipping is only one of the three answers. The band of the oneof field number fixes what a loader with no table entry for it must do ([RFCS.16.2]): 256–2047 skip — log at info level (category dsc-load, message including the field number and the byte offset) and step over the frame; 128–255 reject with DS_ERR_DSC_VERSION; 1–127 reject, the inject band, which no DSC-legal atom occupies — so an atom there is a misplaced stream input and the band catches it blind ([RFCS.16.3]). A reader that knows the atom rejects on container-legality instead ([RFCS.17.3]).

So "the loader does not error" holds for the skip band and for nothing else, and the skip band is where every additive atom is allocated — which is why a clause citing this one for "a runtime without an entry for it skips it" is right.

checks: alloy — see also: RFCS.16.2, RFCS.16.3, RFCS.17.3

[RDSC.9.5] An atom whose body fails protobuf-decode must cause the loader to error. The error names the atom, the byte offset, and the protobuf decoder's reason.

A loader must refuse with DS_ERR_DSC_DECODE a body in which a singular message field, or a message-typed member of a oneof, occurs more than once, at any depth, and one in which proto/header.proto#DscHeader's dsc_sha256 occurs more than once, since [RDSC.3.6] hashes the artefact with that one field zeroed. Otherwise a loader must hold each body as protobuf decodes it, whether it decodes with a protobuf library or walks the bytes itself: a scalar field that occurs more than once holds its last occurrence, a repeated field holds every occurrence in order, and a oneof holds only the member that occurs last. No loader then merges two occurrences of a message, so no loader's answer rests on a library's merge, and two loaders of one artefact hold the same atom. No conforming compiler writes a field twice ([RDSC.9.9]).

ratified — see also: RDSC.3.6, RDSC.9.9

[RDSC.9.6] An atom whose protobuf decodes successfully but whose semantic content violates a per-atom rule in [RDSC.5] or [RDSC.6] must cause the loader to error. The error names the atom, the offending field, and the violated rule's ID.

see also: RDSC.5, RDSC.6

[RDSC.9.7] A truncated stream (read returns fewer bytes than expected) must cause the loader to error.

ratified

[RDSC.9.8] A failed load spends the engine. A load that fails once it has begun reading the artefact must return the error that stopped it and set the engine's halt latch ([NCBK.2.9]): every later call on that engine, but the few [NCBK.2.9] leaves valid, is refused with DS_ERR_ENGINE_HALTED. Nothing ran, so the failed load raises no EngineError and records no stream event. The engine's state after it is undefined, as a halted engine's is ([LERR.1.4.7]), and nothing can read it.

A load refused before it reads the artefact changes nothing: one on an engine that already holds an artefact or has emitted a stream event ([NFCT.1.1]), and one on an engine already halted.

An allocation that fails during a load fails the load, with one exception. A runtime that observes an allocation failing while it loads must fail the load with DS_ERR_OOM, which spends the engine as above. It may instead absorb the failure and go on only where the allocation reserves capacity the engine also grows on demand. Then the loaded program and every value and event are what they would have been without the failure, and the capacity is grown later, when it is needed. A load must not absorb a failure by dropping anything the artefact carries. Nor may it absorb one by leaving the engine on a slower path for its life: an index whose absence a lookup survives by scanning is not capacity grown on demand.

see also: LERR.1.4.7, NCBK.2.9, NFCT.1.1

[RDSC.9.10] No NaN in an artefact's doubles. A loader must refuse with DS_ERR_DSC_SEMANTIC an artefact that holds a NaN, of any payload, quiet or signalling, in a double field of an atom it decodes:

  • proto/alfa.proto#AlphaLiteral's float_val, in an AlphaNode's tests;

  • proto/rete_expr.proto#Expr's lit_float;

  • proto/slot.proto#Slot's tolerance;

  • proto/test_scenario.proto#TestSlotLiteral's f_val, wherever it is carried: an InitialFact or InitialCacheSeed ([RDSC.17]), or a .dstest atom.

An infinity is not refused.

A loader must judge each field's value as the decoded atom holds it ([RDSC.9.5]): a NaN that a later occurrence, or a later member of its oneof, replaces is not held, and is not refused. A body that fails protobuf decode is DS_ERR_DSC_DECODE, whatever NaN it carries ([RDSC.11.4]).

This is a cheap structural need of the loader's ([RDSC.9.9]): one comparison per field. A conforming compiler writes no NaN, since nan is DS_VALIDATE_NAN_VALUE in every value position ([LEXP.4.2]). These fields are the one path by which a signalling NaN could reach a Float operand ([NDET.1.4]), and a runtime that took the bits as they are would compute on a value no source the language admits could produce.

ratified — checks: alloy×2 — defined in: proto/alfa.proto#AlphaLiteral, proto/rete_expr.proto#Expr, proto/slot.proto#Slot, proto/test_scenario.proto#TestSlotLiteral — see also: LEXP.4.2, NDET.1.4, RDSC.11.4, RDSC.17, RDSC.9.5, RDSC.9.9

[RDSC.9.9] A .dsc is trusted input. An integration loads an artefact deliberately, and the artefact's provenance is the integration's responsibility, not the runtime's. Whether an artefact was built to attack a runtime is not a question a load can decide, so a runtime must not spend load time, or memory, analysing an artefact for malicious construction.

A loader may refuse an artefact for compatibility — the version series ([LDET.1.10]), the band of an atom it does not know ([RDSC.9.4], [RFCS.16.3]) — or for a cheap structural need of its own ([RDSC.4a.9.1]). It must not refuse or analyse an artefact on the ground that it may be hostile. Heavier verification of an artefact belongs to a separate tool that runs when someone chooses to run it, never as part of a load.

A program a trace embeds ([RFCS.13]) is trusted the same way: whoever opens the trace chooses to run it.

So are a recorded fact stream ([RFCS.1]) and a FactExternal ([NCBK.10.4]). Whoever opens a trace chooses to replay it, and an integration chooses the tiers it takes a FactExternal from. The integration must accept either only from a source it trusts. A reader of either may refuse it for compatibility or for a cheap structural need of its own, and must not refuse or analyse it on the ground that it may be hostile, as a loader must not.

Trust does not extend to corrupting the host. Whatever bytes it is handed, a loader must either load them or refuse them, and an engine running what it loaded must fault rather than read or write outside what it allocated. This is a property of the code that reads the bytes, not an analysis of the artefact, and it costs no load pass of its own. A fact-stream reader owes the same for every stream it reads, and ds_engine_assert_external for every record it is handed: a record that breaks a refusal of [NCBK.10.4] is refused, whatever its bytes.

This clause covers the .dsc, embedded or not, a recorded fact stream and a FactExternal. Adapter data and every other host input come from outside the deployment, and the clauses that defend against them stand.


see also: LDET.1.10, NCBK.10.4, RDSC.4a.9.1, RDSC.9.4, RFCS.1, RFCS.13, RFCS.16.3

[RDSC.9.11] No negative tolerance. A loader must refuse with DS_ERR_DSC_SEMANTIC an artefact holding a proto/slot.proto#Slot whose tolerance, as the decoded atom holds it ([RDSC.9.10]), is less than zero, -inf included. -0.0 is not less than zero: it is exact equality, as 0 is ([LGRA.5.9.8]).

A source declares a tolerance as an unsigned, finite literal ([LGRA.5.9.7]), and the compiler converts it by a scale's magnitude ([LUNI.7.4]), so no conforming compiler writes a negative one. This is a cheap structural need of the loader's ([RDSC.9.9]), one comparison per slot, and it leaves [LFAC.2.5.1]'s comparison no negative bound to give a meaning to.

ratified — defined in: proto/slot.proto#Slot — see also: LFAC.2.5.1, LGRA.5.9.7, LGRA.5.9.8, LUNI.7.4, RDSC.9.10, RDSC.9.9

[RDSC.9.12] A string field holds well-formed UTF-8 and no U+0000. A loader must refuse with DS_ERR_DSC_DECODE an atom body in which a field of protobuf type string, at any depth it reads ([RDSC.11.4]), holds bytes that are not well-formed UTF-8 (RFC 3629), or that hold U+0000, which no String holds ([LSTR.1.1]). Protobuf's own decode of a proto3 string field refuses ill-formed UTF-8 at the occurrence that holds it, so such a body has not decoded, and it is refused before any other rule judges it. A field that occurs more than once is judged at every occurrence. A loader must not repair the string, nor truncate it at a U+0000.

Two bytes fields carry text, and are judged as strings. Where a loader reads them, it must refuse the same way an atom body whose proto/ds_source.proto#DsSource data, the module's source text ([RDSC.14.2.1]), or whose proto/schema_def.proto#SchemaDef proto_source, the schema's .proto text ([RDSC.5.8.3]), is not well-formed UTF-8 or holds U+0000. This clause reaches no other bytes field. A loader reads either field as text only when its body's compression is COMPRESSION_NONE. Under any other, it refuses the body for its compression ([RDSC.4.5.1]) and reads no text. What it judges is the field's value, which for a field that occurs more than once is its last occurrence ([RDSC.9.5]).

No conforming compiler writes such a string: every name it emits is an identifier ([LNAM.2]), every literal a String ([LSTR.1.1]), and the source and .proto texts are UTF-8 ([LLEX.1.1]). This is a cheap structural need of the loader's ([RDSC.9.9]), one pass over each string it reads.

see also: LLEX.1.1, LNAM.2, LSTR.1.1, RDSC.11.4, RDSC.14.2.1, RDSC.4.5.1, RDSC.5.8.3, RDSC.9.5, RDSC.9.9

Errors [RDSC.11]#

[RDSC.11.1] Loader errors return a status with these ds_err_code_t mappings:

Condition

Code

File too short to contain a DscHeader atom

DS_ERR_DSC_TRUNCATED

First atom is not a DscHeader, or the file is not an atom container

DS_ERR_DSC_BAD_MAGIC

compiler_version is outside the runtime's <major>.<minor>. series ([LDET.1.10])

DS_ERR_DSC_VERSION

Atom body fails protobuf decode, whatever atom it is ([RDSC.11.4])

DS_ERR_DSC_DECODE

Atom body decodes but violates a per-atom rule

DS_ERR_DSC_SEMANTIC

Atom claimed length exceeds remaining file bytes

DS_ERR_DSC_TRUNCATED

An atom names a schema, rule, slot or test that no atom in the bundle defines ([RDSC.8.7]); an AlphaNode's schema included

DS_ERR_DSC_DANGLING

a body declares a non-NONE compression codec; the runtime carries no decompressor ([RDSC.4.5.1])

DS_ERR_DSC_DECOMPRESS

AlphaNode/BetaNode/TerminalNode carries node_id 0, or a node_id another of the three already holds ([RDSC.4a.3])

DS_ERR_RETP_INVALID

BetaNode left_parent_id references form a cycle ([RDSC.4a.5])

DS_ERR_RETP_INVALID

AlphaNode/BetaNode/TerminalNode node_id cross-reference not found

DS_ERR_RETP_INDEX_OOB

An artefact with no rule network is no error ([RDSC.4a.2]).

Framing. A frame ([RFCS.19.1]) is malformed when its outer tag is not 0x0A, its inner tag is not a length-delimited field, its inner tag's field number is in no band ([RFCS.16.3]), one of its varints runs past ten bytes, or its Atom has no oneof member ([RFCS.19.3]). A loader must refuse a malformed first frame with DS_ERR_DSC_BAD_MAGIC, since the bytes are not an atom container, and a malformed later frame with DS_ERR_DSC_DECODE. Where the bytes run out before a frame is complete, inside a varint or because a declared length is longer than the bytes that remain, the code is DS_ERR_DSC_TRUNCATED at any position and whatever the length; a loader that refuses a length past its own bound before reading the body ([RFCS.19.7]) answers that code too. A body that ends early inside a complete frame fails protobuf decode, and is DS_ERR_DSC_DECODE wherever its atom stands, the first included.

No padding is admitted. An artefact ends at the end of its last atom. Every byte after an atom begins a frame, so a trailing 0x00 or 0xFF is a malformed frame, and the loader must refuse the artefact with DS_ERR_DSC_DECODE. It must not stop at such a byte and load the atoms before it: a tail that was zeroed or erased is a truncated rule bundle ([RDSC.9.7]).

ratified — see also: LDET.1.10, RDSC.4.5.1, RDSC.4a.2, RDSC.4a.3, RDSC.4a.5, RDSC.11.4, RDSC.8.7, RDSC.9.7, RFCS.16.3, RFCS.19.1, RFCS.19.3, RFCS.19.7

[RDSC.11.2] The loader emits one error per failed load. The error message names the atom (when known), the byte offset, and the failing rule's RDSC ID.

[RDSC.11.3] An expression the artefact does not state is refused, and so is one nested past the format's limit. A runtime must refuse at load, with DS_ERR_DSC_SEMANTIC, an artefact carrying:

  • an Expr (proto/rete_expr.proto#Expr) with no member of its kind oneof set;

  • a SlotAssign (proto/term.proto#SlotAssign) with no expr;

  • an Action (proto/term.proto#Action) of kind ACTION_CALL with no expr. ACTION_CALL is the one kind that reads expr ([RDSC.4a.8]), and it is the kind's zero, so an Action with nothing set is one;

  • an Action of kind ACTION_WITHDRAW_BY_ID with no withdraw_fact_id, which aims the withdraw at nothing;

  • an Expr nested deeper than 48. The outermost Expr of a test, an action or an assignment is at depth 0, and an Expr inside another is one deeper.

None of these has a meaning: an absent expression is not a literal 0, not null, and not an unassigned slot. The compiler must not emit any of them. It must refuse, with DS_VALIDATE_EXPRESSION_TOO_DEEP, a program any of whose expressions would lower to an Expr nested deeper than 48, so that no program it accepts becomes an artefact a runtime refuses. Each is a cheap structural need of the loader under [RDSC.9.9], not a defence against a hostile artefact.

ratified — defined in: proto/rete_expr.proto#Expr, proto/term.proto#SlotAssign, proto/term.proto#Action — see also: RDSC.4a.8, RDSC.9.9

[RDSC.11.4] A body is decoded before it is judged. A loader must refuse with DS_ERR_DSC_DECODE an atom body that fails protobuf decode, or that holds a field more than once as [RDSC.9.5] refuses, whatever other defect the body carries. A loader must not judge a body by any other rule until the body has decoded; a body that decodes and breaks another rule is refused with the code that rule names.

A loader must not read the bytes inside an Expr nested deeper than [RDSC.11.3]'s limit of 48. It reads that Expr's field in its parent, a tag and a length within the bytes that remain, and no more. A body whose bytes decode down to that limit and that holds an Expr nested deeper is DS_ERR_DSC_SEMANTIC ([RDSC.11.3]), whatever the bytes inside that Expr hold. So no loader recurses past the limit to answer for a body, however deep its bytes nest ([RDSC.9.9]).


see also: RDSC.11.3, RDSC.9.5, RDSC.9.9

Implementation notes [RDSC.12]#

[RDSC.12.1] Every atom body is a protobuf message in the protobuf binary encoding, as proto/ defines it ([RDSC.1.2]). A compiler or a runtime may encode and decode the bodies with any implementation of that encoding, a library's or its own.

see also: RDSC.1.2

[RDSC.12.3] The .proto schemas live in proto/ at the repository root. A .proto file may define several atom bodies; proto/atom.proto#Atom names each atom's body message ([RDSC.1.2]).

see also: RDSC.1.2

[RDSC.12.4] The loader streams the file rather than mmaping it. Atom-by-atom dispatch is O(N) where N is atom count; per-atom decode is O(M) where M is atom body size.