Reference-runtime architecture#
The shape of the DS reference runtime: tier mechanism (topology-agnostic), engine subsystems (working memory, Rete, agenda, conflict resolver, recorder, dispatcher, clock source, consumption loop), cross-tier fact flow, threading, clock model, determinism invariants, and the compilation model. The language-side tier contract lives in [LTIE]; this doc specifies the mechanism that realises it.
What this is not#
Not a language-semantic spec — see the language tree.
Not the DS → native-Rete lowering spec — see [RLOW].
Not a transport spec. The reference runtime commits to the semantics of one engine. It reaches anything outside its process only through callbacks the integrator registers, and moving facts between tiers is the integrator's.
Not a deployment / operations guide.
Architecture commitments [RARC.1]#
[RARC.1.2] Tier mechanism (topology-agnostic). The runtime implements the language-side tier contract from [LTIE] as a mechanism. Each tier is one engine, with its own working memory, cache ([LTIE.5.2]), clock, dialect and stream. Tier-to-tier transport is integrator-supplied, and fact flow is upward-only. The runtime does not commit to a tier count or topology: the integrator builds the topology by creating one engine per tier and bridging them.
see also: LTIE.5.2
[RARC.1.3] Native Rete engine. Each engine runs one Rete network, built from the compiled rule set ([RARC.5.3.1]). The network is the runtime's own code, not a vendored engine.
see also: RARC.5.3.1
[RARC.1.7] Storage backend external to the runtime. The runtime ships no storage backend. The cache is the engine's own ([LSTO.4.7]); an integrator that wants it to survive a restart persists it through the optional cache callbacks ([NCBK.7.1]), against whatever backend it runs.
[RARC.1.8] Stream delivery is foundational. Every observable event reaches the stream callback ([RARC.5.8.1]), so an integrator that keeps the stream holds a replayable recording at any point.
see also: RARC.5.8.1
Process topology [RARC.2]#
[RARC.2.1] A DS deployment hosts one or more tier instances, each one engine environment with its own working memory, dialect, clock, and stream. The runtime makes no commitment about whether tiers run in the same process, in cooperating processes, or on separate hosts — that is the integrator's choice, made when wiring the deployment.
[RARC.2.2] Within a single process, several engines may coexist and
exchange facts by direct calls: the integrator takes the upward publish one
engine delivers on its stream and asserts it into the next tier's engine.
Across processes, the integrator wires whatever transport it likes — local
sockets, a message broker, gRPC, cross-host RPC. The engine has no protocol
surface; the integrator is the bridge.
[RARC.2.3] The runtime provides the per-tier mechanism: an engine, its working memory, its clock, its dispatcher, its stream and its callback table. It does not provide cross-tier transport, adapter connectivity, debugger plumbing, or storage-backend wiring — those are integrator concerns, layered on top of the typed callbacks the engine exposes.
Process-boundary tradeoffs [RARC.2.4]#
[RARC.2.4.1] The integrator picks process boundaries by the constraints of each tier:
[RARC.2.4.2] Co-locate tiers in one process when an upstream tier consumes a downstream tier's emits inside the downstream tier's own cycle (tight- latency case). Direct in-process assertion via the integrator's RHS callback is the lightest path. See [LFAC] for the
ttl/logicaldistinction that makes same-cycle consumption coherent.
[RARC.2.4.3] Split tiers into separate processes when the upstream tier serves multiple downstream hosts, when its horizon is much longer than the downstream tier's cycle, or when independent restart is worth the integrator-side transport cost.
[RARC.2.4.4] Adapters may run as separate processes, because they bridge to external systems with their own lifecycles (a Home Assistant restart, an MQTT broker reconnect). Running them apart keeps an adapter crash from taking the engine down. The integrator wires the adapter-to-engine bridge however suits its stack.
The compiler runs ahead of the engine [RARC.2.5]#
[RARC.2.5.1] The compiler runs as a separate tool, ahead of the engine
([RARC.9.1]). The integrator loads its output, a compiled .dsc artefact,
into an engine, which builds its network from it. The artefact carries:
see also: RARC.9.1
[RARC.2.5.2] schema metadata (schema definitions, lifecycle category per schema, TTL defaults);
[RARC.2.5.4] the service set: which services the
callaction may name, with their argument and response shapes ([RARC.9.3.5]);
see also: RARC.9.3.5
[RARC.2.5.5] sidecar metadata (rule names, source locations, schema info) that the engine loads from the
.dscartefact per the artefact format at [RDSC.1].
see also: RDSC.1
Tier mechanism [RARC.3]#
[RARC.3.1] Each tier runs its own engine, with its own working memory and its own settings ([LDIA.1.3]); a rule file compiles against the settings of the tier it targets. The language-side tier contract is [LTIE.8.1]'s, and the topology is the integrator's ([LTIE.2]). This section specifies what the runtime provides so that contract holds for any topology an integrator picks.
see also: LDIA.1.3, LTIE.8.1, LTIE.2
What a tier instance is [RARC.3.2]#
[RARC.3.2.1] A tier instance is:
[RARC.3.2.2] one Rete network ([RARC.5.3.1]), running the rule set compiled for this tier's dialect;
see also: RARC.5.3.1
[RARC.3.2.3] its own working memory (the network's fact set);
ratified
[RARC.3.2.4] its own clock source (see [RARC.5.5] below);
see also: RARC.5.5
[RARC.3.2.5] its own consumption loop ([RARC.5.6.1]), the sole writer of its stream;
see also: RARC.5.6.1
[RARC.3.2.6] its own stream,
seq-ordered and per engine ([LFST.5.3]);
see also: LFST.5.3
[RARC.3.2.8] its own outbound dispatcher (for
call,publish,cache_*,log; [RARC.5.7.1]).
see also: RARC.5.7.1
[RARC.3.2.9] Multiple tier instances may share one host process (intra-process cooperation) or run in separate processes with integrator-supplied transport between them.
Connecting tiers [RARC.3.3]#
[RARC.3.3.1] The runtime exposes the per-tier engine surface; tier-to-tier connectivity is integrator territory. Two patterns an integrator can implement:
[RARC.3.3.2] Intra-process direct. The lower tier's
publishaction surfaces as anACTION_PUBLISHevent on the lower tier's stream callback; the integrator's stream-cb body asserts the matching fact into the upstream tier's engine via a direct assert. No serialisation cost; both tiers share a process. Appropriate when the upstream tier must consume the lower tier's emits inside the lower tier's own cycle (tight-latency case).
[RARC.3.3.3] Cross-process integrator-bridged. The lower tier's stream-cb encodes the
ACTION_PUBLISHpayload (the integrator picks the encoding — protobuf, JSON-over-HTTP, gRPC, whatever fits the deployment) and forwards to a remote process. That process's integrator-side transport receives the payload and asserts into the local engine via a direct assert. libds has no protocol surface; the transport is entirely the integrator's design.
[RARC.3.3.4] The upward-only rule ([LTIE.3.1]) holds in either case as long as the integrator's bridge carries facts upward only. What crosses is a schema name and slot values ([NCBK.10.1]): the receiving tier's own schema decides the fact's lifecycle and TTL ([LTIE.9.4]), and truth maintenance does not cross ([LTIE.4.6.2]). The runtime does not enforce cross-tier semantics — they are the integrator's to maintain across their transport.
see also: LTIE.3.1, NCBK.10.1, LTIE.9.4, LTIE.4.6.2
Clock and pacing per tier [RARC.3.4]#
[RARC.3.4.1] Each tier's engine has its own clock source ([RARC.5.5.1]). How often the integrator pumps it is the integrator's choice, made per tier. Three patterns:
see also: RARC.5.5.1
[RARC.3.4.2] Input-driven. The integrator moves the clock and pumps on each input. This suits tight-latency tiers whose cadence an external signal paces: a frame arrival, a sample tick.
[RARC.3.4.3] Cycle-paced. The integrator asserts the inputs that accumulated during a fixed period, then pumps once. This suits orchestration tiers that want a stable per-cycle view of incoming state changes.
[RARC.3.4.4] Event-driven. The integrator pumps on any input and also on a timer of its own, so that time-bound tests re-evaluate between inputs ([RARC.5.5.4.5]). This suits tiers whose work is irregular and whose horizon is longer than any single event's latency budget.
see also: RARC.5.5.4.5
[RARC.3.4.5] All three use the same engine operations; the only difference is which signal makes the integrator pump.
What a tier sees, what it emits [RARC.3.5]#
[RARC.3.5.1] Sees: facts emitted into its own working memory by rules compiled against its dialect, plus cross- tier publishes arriving from downstream tiers, plus adapter emits from adapters bound to this tier, plus call responses and storage-plane reads.
[RARC.3.5.2] Does not see: facts local to sibling tiers or to higher tiers, or another tier's cache. Cross-tier visibility is upward-only.
[RARC.3.5.3] Emits upward: stream callback observes
ACTION_PUBLISHfor the asserted fact; integrator forwards into the parent tier's environment via whatever bridge they wired (intra-process direct assert, integrator-defined cross-process transport).
[RARC.3.5.4] Storage access: gated by the tier's settings. A tier whose settings make
callfalse reaches no storage service, and one whose settings makecacheorcache_deletefalse cannot write the cache ([LFCA.2.1]); every tier reads its cache ([LFCA.2.4]).
Illustrative topologies [RARC.3.6]#
[RARC.3.6.1] The mechanism supports topologies ranging from trivial to deep. Two examples:
[RARC.3.6.2] Single-tier deployment. One engine, one dialect, one clock. No cross-tier flow. Simplest deployment; useful for small rule sets, embedded contexts, or tests.
[RARC.3.6.3] Multi-tier deployment. One tier per source for tight-latency per-source decisions feeding an orchestration tier for cross-source state, optionally feeding a site-level tier for cross-deployment orchestration. A process boundary splits the tier tree wherever independent restart or remote topology matters; integrator-side transport carries
ACTION_PUBLISHpayloads across.
[RARC.3.6.4] The integrator builds the topology by creating engines and bridging them. The language spec and the cross-tier contract are identical for every choice.
Format version discipline [RARC.4]#
[RARC.4.1] DS persistent formats refuse anything outside the current
minor series. A current DS binary reads artefacts written by its own
<major>.<minor>. series and no others ([LDET.1.10]). Encountering a
version outside that series is a fatal error, not a translation event.
see also: LDET.1.10
[RARC.4.2] Replaying historical behavior requires historical code. A trace, event trace, profile, or compiled DSC produced by an older release is read by checking out that release and building it. There are no compatibility shims, version-tagged code paths, or migration adaptors inside the current runtime.
[RARC.4.4] Migration tools. A one-shot batch translator is a separate binary, not a feature of the runtime. A v(N-1)→v(N) translator is permitted but lives outside the engine and is itself version-discipline-bound: a v(N+1) runtime does not ship the v(N-1)→v(N) translator. The same rule applies transitively.
[RARC.4.5] In scope. This policy governs every artefact DS defines that
persists across a process or a release boundary. That includes a compiled
.dsc and a fact-stream recording, each of which records the DS version that
wrote it ([LDET.1.10]). Each format's spec must cite this section where it
states its refusal, and the refusal has no opt-out.
see also: LDET.1.10
[RARC.4.6] The dialect and contract bindings are sibling guards. A DS
version proves the encoding is current. It does not prove that the behaviour
the artefact describes, or the sizing it was produced under, is the one in
force. Two bindings supply those guards: the dialect binding ([RBND.1.3]) and,
under realtime, the contract binding ([RBND.1.4]). Which artefacts carry
which binding, and what a mismatch refuses, are RBND's.
[RARC.4.7] Scope exclusion: in-memory IPC. This policy applies to artifacts that persist across process boundaries in time (files) or across release boundaries. Live IPC between sibling tiers is the integrator's transport, carrying whatever the integrator encodes ([RARC.3.3.3]) — the engine defines no format there, so there is no version to refuse.
see also: RARC.3.3.3
Engine subsystems [RARC.5]#
[RARC.5.1] An engine is the network compiled from one rule set, together with its clock source ([RARC.5.5]), working memory ([RARC.5.2]), agenda ([RARC.5.4]) and dispatcher ([RARC.5.7]). The integrator drives it through public calls — assert, retract, the clock operations and pump — and each call is processed serially to completion before it returns ([RARC.5.6]). The engine has no thread, queue or loop of its own. Everything it does that an integrator can observe reaches the integrator through its callbacks: the stream callback for every observable event ([RARC.5.8]), and the typed callbacks for the actions the dispatcher routes.
see also: RARC.5.2, RARC.5.4, RARC.5.5, RARC.5.6, RARC.5.7, RARC.5.8
Working memory [RARC.5.2]#
[RARC.5.2.1] An engine's working memory holds every fact asserted into it. Fact representation is the network's own: fact records over the schema. Working memory is single-threaded. It is read and written only inside the public call being processed, including from RHS action code running inside a rule fire, which is still inside that call. The integrator must not make two calls into one engine concurrently.
[RARC.5.2.2] Invariants working memory upholds:
[RARC.5.2.3] Fact identity. Two facts are equal iff all their slot values compare equal ([LDET.3.2.4]), by the comparison of [LFAC.2.5.1]. The engine must suppress a no-op reassertion of a fact of a
logicalschema, and only of one ([LFAC.1.4.4]). Facts of attlschema accumulate ([LFAC.1.3.2]): two equal asserts are two live facts, each with its own expiry.The suppression is a working-memory discipline and does not reach the recorder — a no-op reassertion is still an arriving input and is still written as a
FactAssert([RFCS.6.7]). Dropping it would leave a trace carrying the pump ([RFCS.22]) but not the input that provoked it.
ratified — see also: LDET.3.2.4, LFAC.1.3.2, LFAC.1.4.4, LFAC.2.5.1, RFCS.22, RFCS.6.7
[RARC.5.2.4] TTL bookkeeping.
ttlfacts carry a deadline, and a fact whose deadline is at or before the engine clock is expired: a fact due at the current instant does not survive it. A pump retracts every expiredttlfact at its entry, before the agenda runs ([NTST.3.4]). Retraction is ordered: each TTL retraction reaches the stream with its ownseq.
ratified — checks: tla — see also: NTST.3.4
[RARC.5.2.5] Logical-fact truth maintenance. A
logicalfact is retracted when its last justifying activation ends ([LLOG.15]). The engine coalesces justifiers: a fact asserted by two activations lives while at least one of them remains ([LLOG.2]). Its assertion and its retraction reach the stream as any fact's do, asfact_assertandfact_retractevents (proto/stream_event_kind.proto).
ratified — see also: LLOG.15, LLOG.2
[RARC.5.2.6] Slot typing, on every path. No fact enters working memory carrying a slot value whose kind differs from the schema's declared slot type. There is no implicit conversion, and the invariant is a property of working memory rather than of any one entry point: it binds a host assertion, a rule-fired
emit, a call's response fact, a published fact and a replayed inject-class atom identically. At a host call or in a replayed atom, a violation isDS_ERR_SLOT_TYPE_MISMATCH([IDAT.4.6]); produced by a rule's activation, it is aTypeError(RARC.5.2.7).[NFCT.2.3] is this invariant stated at the host boundary, and [RLOW.1.4]'s compile-time obligation — "every typed slot access must match the declared slot type" — is defence in depth in front of it, not a substitute for it. A rule whose lowering produces a mistyped value must be refused at compile time and cannot reach working memory if it is not.
ratified — see also: NFCT.2.3, RLOW.1.4, IDAT.4.6
[RARC.5.2.7] A rule that emits a value its slot does not admit raises a
TypeError. When a rule's activation would put into a slot a value whose kind the declared type does not accept (RARC.5.2.6),nullinto a slot not declaredT?([LNUL.3.1]), or a NaN into any slot ([LEXP.4.2]), the engine must raise aTypeError([NCBK.2.8]) naming the schema and the slot, and abandon the activation (rung 5, [LERR.1.4]). The fact does not enter working memory, and apublishsends nothing ([LTIE.4.8]). The pump returns no error for it: the fault is the stream event and theTypeErrorfault fact ([LERR.9.3]), whoseschemaandslotname the slot that refused the value.A NaN is a value its expression computed correctly ([LDET.3.6.2]); what the engine refuses is storing it in a slot, where its meaning is undefined.
A
Jsonvalue whose root isnullisnullfor this clause ([LNUL.3.4]). The engine must store it in aJson?slot asnull, and refuse it for aJsonslot as it refuses anynullinto a slot not declaredT?.The compiler must refuse the program instead wherever it can prove the mismatch from the declared types (RLOW.1.4); this clause is what binds when it cannot.
ratified — see also: LDET.3.6.2, LERR.1.4, LERR.9.3, LEXP.4.2, LNUL.3.1, LNUL.3.4, LTIE.4.8, NCBK.2.8
Rete network [RARC.5.3]#
[RARC.5.3.1] The runtime builds the network from the compiled rule set; the network is the runtime's own, not a vendored engine. Its firing order is deterministic ([LDET.5]) but not legible from source text alone, and the introspection queries expose it ([NDBG.4]).
checks: idris — see also: LDET.5, NDBG.4
[RARC.5.3.2] Network introspection (topology, live node occupancy, a fact's match trace) is surfaced through the in-process introspection queries ([NDBG.4]) in DS-level names: rule names, schema names and slot names, not internal node labels. The translation from the network's internal representation to those names is the introspection layer's.
see also: NDBG.4
[RARC.5.3.3] An expression that reads a pattern position the match never bound is an unrecoverable fault: the engine must halt the tier ([LERR.1.4.7]).
It is not an absent value. Nothing is missing — the
artefact is asking about a position the network does not
have, so the shape the rule set declared at load and the
shape the network is running disagree. Answering null
would report "unknown" for a rule set that cannot be run
as written, and would let the disagreement propagate as
data.
The engine does not repair it, because it cannot: which position the author meant is not recoverable from the artefact that got it wrong.
see also: LERR.1.4.7
Agenda and conflict resolver [RARC.5.4]#
[RARC.5.4.1] The agenda is the list of matched-but-not-yet-fired activations. The conflict resolver picks the next activation to fire.
[RARC.5.4.2] The conflict resolver enforces the firing order [LDET.5] commits to, with two keys:
see also: LDET.5
[RARC.5.4.5] The terminal ordinal — first key. The rule's zero-based index in the compiled artefact's terminal sequence, which
[RLOW.14.3]requires to be canonical source order: earlier in its source file first, and across files import-DAG topological, leaf libraries first.[LDET.5.4]is the normative statement.
[RARC.5.4.6] Activation-creation order — second key, and only within one rule. Among activations of the same rule, partial matches completed earlier fire before those completed later, by the creation timetag [LDET.5.5] defines — a stamp monotone in completion order, assigned when a match completes. It never decides between two rules.
[LDET.5.5]is the normative statement.
see also: LDET.5.5
[RARC.5.4.7] The total order is a property of the agenda's comparator, not of any per-rule annotation or pluggable conflict-resolution strategy. Each activation carries its rule's terminal ordinal and its creation timetag; the comparator orders by ordinal, then timetag — exactly [LDET.5.4] then [LDET.5.5]. The ordinal is unique per rule, so it decides between any two rules on its own; the timetag ascends with completion order and orders the activations of one rule against each other.
Refraction is not a key. An activation whose (rule, token) identity has already fired is suppressed when selected rather than sorted later ([LDET.5.3]): the comparator never weighs whether an activation fired.
see also: LDET.5.3, LDET.5.4, LDET.5.5
[RARC.5.4.8] Implementations MAY use internal data structures (hash tables, heaps) for agenda management as long as the observable firing order matches the spec. Hash-order dependence is forbidden per [LDET.5.9].
see also: LDET.5.9
[RARC.5.4.9] The order key is unique, and a duplicate is a defect in the runtime. [RARC.5.4.7]'s comparator is a total order only while the pair (ordinal, creation timetag) is unique. Under [LDET.5.5]'s timetag it is: no rule holds two activations with one timetag after any history, so a correct runtime never meets a duplicate. A runtime may check for one, and on finding it must treat it as an unrecoverable fault and halt the tier ([LERR.1.4.7]), because the agenda then has no defined next activation and the firing order [LDET.5] commits to is not determined by the artefact.
The engine must not break the tie by any other means. A tiebreak the comparator does not specify is a hash-order dependence under another name, which [RARC.5.4.8] forbids — and it would be worse than the fault it conceals, because the run would complete and its output would look ordinary while being unreproducible on any other implementation.
checks: idris×2 — see also: LDET.5, LDET.5.5, LERR.1.4.7, RARC.5.4.7, RARC.5.4.8
Clock source [RARC.5.5]#
[RARC.5.5.1] One clock source per engine instance. Engines do not share clocks: each has its own, and its trace records its own samples ([LTIM.2.8.5], [LFST.4.10]).
see also: LFST.4.10, LTIM.2.8.5
[RARC.5.5.2] The clock source is mockable as a first-class API per [LTES.3]; the integrator's mock clock is [NTST.3]'s. In live mode, the clock source reads the host's monotonic clock and its UTC wall clock, one sample of each per step ([LTIM.2.8.4]). In test / replay mode, it returns whatever the harness or the recording sets for each. No code path reads wall-clock time outside the clock source.
see also: LTES.3, LTIM.2.8.4, NTST.3
[RARC.5.5.3] This is an architectural invariant: every time value the engine
computes with — now(), fact timestamps, TTL and timer deadlines, the clock
tick — must come from the clock source. A subsystem that read host time
directly would diverge on replay and break the determinism guarantee. The
one other reading of host time is a real-time tier's pump-WCET measurement,
which no rule reads and which decides only the halt of [RTCT.7.3].
see also: RTCT.7.3
Ticks for time-bound LHS [RARC.5.5.4]#
[RARC.5.5.4.1] Time-bound LHS tests (t.dwell > 5_min, no Event within 30_s) don't naturally re-evaluate on wall-clock
passage: the network re-evaluates on fact change. So each pump retracts and
re-asserts a synthetic $ClockTick fact once, after its TTL sweep and before
its agenda runs, and the network's re-evaluation then re-fires the time-bound
tests at the pump's instant.
ratified
[RARC.5.5.4.2] The tick has no interval of its own. It follows the pump, so time-bound tests re-evaluate as often as the integrator pumps:
[RARC.5.5.4.3] An integrator that pumps after every input re-evaluates time-bound tests at every input.
[RARC.5.5.4.4] An integrator that pumps once per fixed period re-evaluates them once per period.
[RARC.5.5.4.5] An integrator whose inputs are sparse should also pump on a timer of its own choosing, so that time-bound tests re-evaluate between inputs. The interval is the integrator's.
[RARC.5.5.4.6] The resolution of a time-bound test is therefore the integrator's pump interval: a condition that becomes true between two pumps is seen at the next one.
Processing a call: the consumption loop [RARC.5.6]#
[RARC.5.6.1] The consumption loop is the processing an engine performs inside one public call: an assert, a retract, a clock move or a pump. It is the engine's single writer. Every change to working memory happens inside it, whether the change comes from the integrator's input, an RHS action or a TTL sweep. It runs on the caller's thread and finishes before the call returns; the engine has no thread or queue of its own. Across an input and the pump that follows it, the loop:
checks: idris×14
[RARC.5.6.2] Takes the input the call carries: a fact to assert or retract, or a new clock value.
checks: idris×6
[RARC.5.6.3] Samples both clocks, as the engine does whenever it consumes an input ([LTIM.2.8.4]), whatever
clock_nsthe event carries. A pump, at its entry and before anything fires, then retracts the expiredttlfacts, a fact being expired when its deadline is at or before the monotonic sample ([RARC.5.2.4]). An assert, a retract or a clock move retracts nothing: an expired fact stays in working memory until the next pump.
ratified — checks: idris×27 — see also: LTIM.2.8.4, RARC.5.2.4
[RARC.5.6.4] Applies the event to working memory (assert / retract / TTL update / logical retract).
checks: tla×2 idris×59
[RARC.5.6.5] Hands the change to the network, which propagates it through its alpha and beta memories and populates or updates the agenda.
checks: idris×57
[RARC.5.6.6] During a pump, the conflict resolver fires activations one at a time until the agenda is empty or a real-time tier's firing limit is reached ([RTCT.7.1]); each firing reaches the stream as rule-fire events.
checks: alloy×3 tla×11 idris×6 — see also: RTCT.7.1
[RARC.5.6.7] Runs each RHS action in the order the artefact declares: an
emitor awithdrawchanges working memory directly, and every other verb goes through the dispatcher ([RARC.5.7.1]).
checks: idris×65 — see also: RARC.5.7.1
[RARC.5.6.8] Delivers the input's event and every derived event, internal and action alike, to the stream callback in the order they were processed ([RARC.5.8]).
Processed means propagated, per action. Each RHS action's change to working memory is propagated through the network, truth-maintenance retractions included, before the change is recorded and before the next action of the same firing runs. A cascade retraction is therefore recorded ahead of the assert that caused it, and a firing that emits twice, where only the second emit invalidates a
no (...), records the retraction between its two asserts. Stream order is processing order, not causal order; a reader that takes precedence for causation attributes every cascade to the wrong cause.This is a rule's action. A host input is recorded on arrival, before what its evaluation produces ([RFCS.6.7]), and an engine withdrawal before the withdrawals it cascades into ([RFCS.7a.4], [LFST.7.3.6]).
ratified — see also: LFST.7.3.6, RARC.5.8, RFCS.6.7, RFCS.7a.4
[RARC.5.6.9] The loop is strictly serial within an engine. Parallelism
across tiers comes from running engines on separate threads or in separate
processes, which is the integrator's choice. Within one engine there is no
parallelism at the event level: seq is assigned as each event is produced
and increases monotonically ([LFST.5.3]).
see also: LFST.5.3
[RARC.5.6.10] Consumption-loop determinism is the choke point that makes the whole engine deterministic ([LFST.7.1.1]). If the consumption loop is deterministic ([RARC.5.6.9]) and the ambient inputs agree, replay is byte-for-byte identical.
Ambient inputs are every input to the record that the loop does not compute, the clock origin and the identity assigned to an event among them. They are defined by that property, not by a list.
⚠ Loop determinism alone does not give byte-identical replay. Two runs can agree on every value the loop computed and still record different events if their clock origins differ. So the engine must take no ambient input from outside the run where the run can supply it: a mock clock starts at a fixed origin rather than a wall-clock reading ([NLFC.5.4]), and an event's identity is derived from the run ([RARC.5.8.8]) rather than drawn at random.
see also: LFST.7.1.1, NLFC.5.4, RARC.5.6.9, RARC.5.8.8
[RARC.5.6.11] A read that reaches a binding before the action establishing it has run is an unrecoverable fault: the engine must halt the tier ([LERR.1.4.7]).
The right-hand side runs in the order the artefact declares (step 6, [RARC.5.6.7]). A read arriving ahead of its binding means the declared order and the executed order disagree, so the artefact is not describing the run the engine is performing.
It is not an absent value, and the distinction is the
whole point: the binding is not missing, it is unreachable in
a rule set that was compiled correctly. Answering null
would turn a broken artefact into a rule that quietly does
not fire.
see also: LERR.1.4.7, RARC.5.6.7
Dispatcher [RARC.5.7]#
[RARC.5.7.1] RHS actions other than emit and withdraw, which change
working memory directly, go through the dispatcher:
Action |
Destination |
|---|---|
|
integrator's |
|
integrator's stream callback receives an |
|
integrator's cache callbacks (cache plane) |
|
integrator's log callback |
A cached(...) read is not dispatched. It is a pure internal read of the
engine's cache and invokes no callback ([LFST.5.1]).
see also: LFST.5.1
[RARC.5.7.2] The dispatcher is the engine's only outbound writer. Actions never bypass it to call integrator code directly: a bypassing action would be missing from the stream. This is an architectural invariant.
[RARC.5.7.3] Dispatcher sub-components:
[RARC.5.7.4] Call dispatcher. Invokes the integrator's call callback with the service, the correlation, the arguments and the identity of the firing that issued it. The correlation is the call's
asvalue or the one the compiler generated for it ([LCRS.3.1]); the dispatcher allocates none. It keeps no per-call deadline either; timeouts are the adapter's ([LCRS.7.3]).
ratified — see also: LCRS.3.1, LCRS.7.3
[RARC.5.7.5] Publish dispatcher. Judges the action's values as an
emit's are judged ([LTIE.4.8]) and asserts nothing into working memory ([LTIE.4.3]). It delivers anACTION_PUBLISHstream event carrying a view of the published fact, valid while the callback runs, and itsFactExternalencoding ([NCBK.2.5], [NCBK.10.1]). The integrator's stream callback observes the event and decides whether, and how, to forward it upward to another tier.
see also: LTIE.4.3, LTIE.4.8, NCBK.10.1, NCBK.2.5
[RARC.5.7.6] Cache-op dispatcher. Routes the
cacheandcache_deletewrite actions to the integrator's optional write-through persistence callbacks. The cache itself is engine state ([LSTO.4.7.1]), so acached(...)read — the let-RHS expression form per [LGRA.9.8.2] — is served from the in-engine map with no callback, and completes in-rule at RHS entry.
see also: LGRA.9.8.2, LSTO.4.7.1
[RARC.5.7.8] Log dispatcher. Interpolated string output, delivered to the integrator's log callback. The stream carries the string verbatim, so a replay compares the exact text.
[RARC.5.7.9] Every dispatcher action reaches the stream before it leaves
the engine, as an action_call, action_publish, action_cache_set,
action_cache_delete or action_log event (proto/stream_event_kind.proto).
A cached() read reaches neither the stream nor a callback: the cache is
engine state ([LSTO.4.7]) and a read is a pure internal read, re-derived on
replay from the cache writes the replayed rules make again. It is therefore no replay input
([LFST.9.2]).
ratified — see also: LFST.9.2, LSTO.4.7
[RARC.5.7.10] A cache seed ([IARC.12]) writes the
engine-owned cache directly at setup, bypassing the dispatcher. It is not
one of the dispatcher actions of [RARC.5.7.9]: it emits no action_cache_set
event. A recording carries the seed instead, as a CacheSeed in the
stream's prelude ([RFCS.26.1]), and a replay applies it before the first input
([RFCS.26.2]). So a replay starts from the cache the run started from, whether
the seed was the integrator's restore ([NSTG.9]) or a test's initial: arrange
([RTIM.14.4]), and the integrator does not seed the replaying engine. From
there the running cache evolves deterministically, re-derived on replay from
the cache writes the replayed rules make again ([RARC.5.7.9]) — not from
recorded reads or writes, neither of which a recording carries ([RFCS.3.6]).
The atom carries the value as the cache holds it, the canonical text a rule
write also produces ([IARC.12.2]), so the replayed entry is byte-identical to
the seeded one.
see also: IARC.12, IARC.12.2, NSTG.9, RARC.5.7.9, RFCS.26.1, RFCS.26.2, RFCS.3.6, RTIM.14.4
Stream delivery [RARC.5.8]#
[RARC.5.8.1] Stream delivery is foundational, not a feature. Every event-producing path in the engine delivers its event to the stream callback ([NCBK.2.1]) through a hook site; no path produces an observable event without delivering it. The engine writes no recording of its own. A recording is what the integrator keeps of the stream.
see also: NCBK.2.1
[RARC.5.8.2] Design:
[RARC.5.8.3] Single writer per engine's stream. Events are delivered from inside the consumption loop ([RARC.5.6.1]), in
seqorder. Nothing else delivers to the stream.
see also: RARC.5.6.1
[RARC.5.8.4] Hook points are narrow and spec-defined. Each
StreamEventfield-number in [LFST.5] corresponds to exactly one hook site in the engine. Adding a stream event kind is a spec change.
see also: LFST.5
[RARC.5.8.5] Lossless. Every observable event is delivered. There is no sampling and no per-kind suppression ([LFST.12]).
see also: LFST.12
[RARC.5.8.6] Deterministic encoding. Wherever an event is encoded in the fact-stream format, the encoding is deterministic: the same event on the same platform encodes to the same bytes, per [LFST].
[RARC.5.8.7] Delivery within the producing call. The engine must hand the integrator every event ([RARC.5.8.5]) in
seqorder, each before the integrator's typed callback for the action it describes runs ([RARC.5.8.9], [RARC.5.8.12]), and all of them before the call that produced them returns ([RARC.5.6.1]). The engine must hold no event past that return, and must spawn no writer ([RARC.6.4.1], [RARC.5.8.3]). Within those bounds a runtime may deliver in either of two ways:Synchronously. The hook site hands each event to the integrator's stream callback from inside the consumption loop, on the caller's stack ([RARC.6.5.1]), and the engine holds no queue of its own. Where the integrator's sink is slower than the tier produces events, the callback blocks and the consumption loop blocks with it, so a slow sink throttles the engine mid-pump. The block is metered under
ds.recorder([NMET.4.1]).As a returned effect list. The call returns its events and actions as one ordered list, and the integrator's shell hands each to its callback in that order. The engine holds the list from the first event to the return, and nothing reaches the integrator before the call returns. So a slow sink throttles the engine only between calls, never mid-pump, and a call holds all of its effects until it returns.
Either way the lossless contract outranks the throughput ceiling ([RARC.14.3]), because loss would be a determinism-guarantee violation, and the order the integrator sees is the same. What differs is when a slow sink is felt. Buffering, batching and any onward flush are the integrator's.
see also: NMET.4.1, RARC.14.3, RARC.5.6.1, RARC.5.8.12, RARC.5.8.3, RARC.5.8.5, RARC.5.8.9, RARC.6.4.1, RARC.6.5.1
[RARC.5.8.8]
event_idis a deterministic derivation. The UUID is keyed on the run identifier, the tier identifier and theseqof the fact'sFactAssert([LFST.5.6]), by the function [RFCS.6.8] states, so distinct keys derive distinctevent_ids. All three inputs reproduce on replay; reading/dev/urandomwould break replay ([LDET.6.4.2]). Theevent_ididentifies a fact within this engine only: a fact received from another tier gets this engine's own ([LFST.5.6]).
checks: alloy×3 — see also: LDET.6.4.2, LFST.5.6, RFCS.6.8
[RARC.5.8.9] Every observable event reaches the stream callback before it becomes observable any other way: before an in-language fact it produces is asserted, and before the integrator's typed callback for it runs.
[RARC.5.8.10] Inputs (
fact_assert,fact_retract): delivered at step (1) of the consumption loop, right afterseqassignment, and after thetickof the sample taken for that input ([LTIM.2.8.5]). A call's response fact and aCallErrorarrive asfact_asserts.
see also: LTIM.2.8.5
[RARC.5.8.11] Engine internals: delivered inline at the site that generates them.
pumpat a pump's entry ([RFCS.22]);rule_fire_begin,rule_lhs_factsandrule_fire_endaround each firing; a truth-maintenance retraction, or a TTL expiry, as afact_retractwhere the engine makes it;timer_armedwhere a timer is armed; andtype_error,bounds_error,engine_errorandcomputation_errorat the site of the fault ([NCBK.2.3]).
ratified — checks: tla — see also: NCBK.2.3, RFCS.22
[RARC.5.8.12] Actions (
action_emit,action_call,action_publish,action_cache_set,action_cache_delete,action_log): delivered before the integrator's typed callback for the action runs ([RARC.5.8.9]). The event does not depend on that callback: a callback that fails, or none registered, leaves it delivered, and a failure reaches the caller as the returned status. Acached()read is not among them: it is a pure internal read ([LSTO.4.7.1]).
ratified — see also: LSTO.4.7.1, RARC.5.8.9
[RARC.5.8.13] If the integrator's stream callback reports a recording failure, the consumption loop continues, and the public call that fired the callback returns the status ([NCBK.1.5]). The tier does not halt: the stream is an observer, and the engine's behaviour must not depend on whether its observer succeeded. Whether to keep running on an incomplete recording is the integrator's decision, taken with the status in hand.
see also: NCBK.1.5
Threading model [RARC.6]#
An engine runs on its caller's thread [RARC.6.1]#
[RARC.6.1.1] An engine has no thread of its own ([RARC.5.1]). Each call runs on the thread that makes it and finishes before it returns ([RARC.5.6.1]), and each engine writes its own stream. A deployment of many engines — one per tier, or one per source within a tier — drives each from whichever threads the integrator chooses.
see also: RARC.5.1, RARC.5.6.1
[RARC.6.1.2] Upward fact flow within one process is integrator code. The lower engine hands the fact to the integrator through a callback, and the integrator asserts it into the upper engine: from inside that callback if it chooses, since that enters a different engine ([RARC.13.16]), or after the lower engine's call has returned.
see also: RARC.13.16
[RARC.6.1.3] Cross-process upward publish is integrator- bridged: the lower tier's stream callback hands the payload to whatever transport the integrator wired, and a process on the upstream side asserts into its own engine. Neither engine has a thread of its own; the bridge is integrator code.
[RARC.6.1.4] Calls on one engine must not overlap. The engine takes no lock, so the integrator serialises the calls it makes on one engine, whatever threads they come from; calls on different engines may run at the same time ([RARC.5.6.9]). Each engine is the single writer of its own stream.
see also: RARC.5.6.9
Parallelism across tier instances [RARC.6.2]#
[RARC.6.2.1] Separate engines are independent ([RARC.1.2]) and may run at
the same time on different threads, for example several per-source engines of
one tier. Their streams are independent: no seq space is shared between
them. Correlation across sibling engines flows through an upstream engine:
each sibling's facts are bridged upward ([RARC.6.1.2]), and the upstream
engine consumes them in the order its integrator asserts them.
ratified — see also: RARC.1.2, RARC.6.1.2
Parallelism within a rule fire [RARC.6.3]#
[RARC.6.3.1] Within one engine, activations fire one at a time ([RARC.5.6.6]), and a firing's actions run in the order the artefact declares, each propagated before the next ([RARC.5.6.8]). A runtime may overlap work only where [LDET.6.5] admits it, and the stream it produces must be the one the serial order produces.
see also: LDET.6.5, RARC.5.6.6, RARC.5.6.8
Integrator I/O [RARC.6.4]#
[RARC.6.4.1] All I/O — adapter ingest, cross-tier bridging, storage access, debugger and observability sinks — is the integrator's, and runs on the integrator's threads (an asyncio task, a dedicated thread, a pool). The engine performs none of it and spawns no thread. Input reaches an engine when the integrator calls it.
Stream delivery [RARC.6.5]#
[RARC.6.5.1] Stream delivery completes within the call that produced the event ([RARC.5.8.7]): on that call's stack, or in the ordered effects it returns. Any onward flushing — to disk, to a file, to a remote collector — is the integrator's, on whatever thread, queue or ring its backend prefers. The engine keeps no event past the call's return, and flushes nothing.
see also: RARC.5.8.7
Thread summary [RARC.6.6]#
Thread |
What runs on it |
|---|---|
Whichever thread calls an engine |
That call, start to finish, and every callback it makes ([RARC.6.1.1], [RARC.6.5.1]). One call at a time per engine ([RARC.6.1.4]). |
The integrator's other threads |
I/O, bridging between engines, and whatever drives the clock ([RARC.6.4.1]). The engine owns no thread. |
see also: RARC.6.1.1, RARC.6.1.4, RARC.6.4.1, RARC.6.5.1
Fact flow through the engine [RARC.7]#
[RARC.7.1] An input's path through the engine, from the integrator's call to the events on the stream, is the consumption loop's ([RARC.5.6]). The input is applied to working memory ([RARC.5.6.4]) and propagated through the network to the agenda ([RARC.5.6.5]). During a pump, activations fire one at a time ([RARC.5.6.6]), and every event, the input's and each derived one, reaches the stream callback in the order it was processed, each action's change propagated before the next action runs ([RARC.5.6.8]). Facts an action asserts re-enter the same path. The call returns when the loop is done ([RARC.5.6.1]).
see also: RARC.5.6, RARC.5.6.1, RARC.5.6.4, RARC.5.6.5, RARC.5.6.6, RARC.5.6.8
[RARC.7.15] A pump retracts the expired ttl facts at its entry, before
anything fires ([RARC.5.6.3]): a fact expires when its deadline is at or before
the clock ([RARC.5.2.4]). An input does not: an assert made after a fact's
deadline joins against that fact until the next pump retracts it. Each
retraction is its own event with its own seq, and the logical retractions it
causes cascade through truth maintenance.
ratified — see also: RARC.5.2.4, RARC.5.6.3
Determinism invariants [RARC.8]#
[RARC.8.1] The architecture enforces the invariants that make [LDET] deliverable.
Single-writer-per-stream [RARC.8.2]#
[RARC.8.2.1] An engine's consumption loop ([RARC.5.6.1]) is the sole writer
of its stream. seq is assigned in consumption order, and nothing outside the
loop touches it. This is the architectural guarantee that makes replay
byte-for-byte identical by construction ([LFST.7.1]).
see also: LFST.7.1, RARC.5.6.1
Consumption-order sequencing [RARC.8.3]#
[RARC.8.3.1] Inputs are sequenced in the order the integrator makes the calls that carry them. Two inputs the integrator asserts "at the same instant" are sequenced by which call it makes first. That order is in the stream, and a replay makes the calls in exactly that order, producing the same output.
No hash-order dependence [RARC.8.4]#
[RARC.8.4.1] Agenda data structures, working-memory indices, and Rete alpha / beta memories MAY be hashed for performance. The conflict resolver MUST NOT use hash iteration order as a tiebreaker. The observable firing order follows the spec's total order regardless of internal hashing.
[RARC.8.4.2] DS defines no configuration that reverses hash iteration, which
[LCON.2.4.1] relies on only where an implementation exposes one. The
conformance suite therefore varies the engine's
internal hash layouts another way: it re-runs a scenario with its facts asserted
in different orders. That also changes each fact's seq and creation timetag,
and with them the order in which one rule's activations fire ([LDET.5.4]). So
what must not change between the orders is only what insertion order cannot
reach: which rules fire, in rule order, and how many facts result. A scenario
for it is written so that this is its whole output.
see also: LCON.2.4.1, LDET.5.4
Parallelism-equivalent-to-sequential [RARC.8.5]#
[RARC.8.5.1] An engine processes every observable event serially, inside its consumption loop ([RARC.5.6.9]). Any parallelism in a deployment lives in integrator code: sibling engines on different threads, or integrator-side I/O fan-out. Sibling engines are independent streams, and ordering across them is the integrator's to define when it bridges them.
see also: RARC.5.6.9
Platform-signature fidelity [RARC.8.6]#
[RARC.8.6.1] Replay is bit-for-bit, within a platform and across platforms alike ([LDET.3.4.1]). The platform signature ([LDET.2.3]) is provenance, and a trace does not record it.
see also: LDET.2.3, LDET.3.4.1
No uncontrolled randomness [RARC.8.7]#
[RARC.8.7.1] Synthetic identifiers (the synthetic names of [LLEX.10.6.1]) are
source-derived, not random. The runtime
must not take an identifier or a seed from an entropy
source or the wall clock, only from inputs that replay
reproduces. event_id is keyed on the run identifier,
the tier identifier and the seq of the fact's
FactAssert ([RARC.5.8.8]).
see also: LLEX.10.6.1, RARC.5.8.8
Compilation model [RARC.9]#
[RARC.9.1] The compiler is a separate tool that runs before the engine. Its
inputs are the rule source files and the libraries they import; its output is
a compiled .dsc artefact, which the integrator loads into an engine. The
engine never invokes the compiler, and nothing it does at runtime changes the
compiled rule set.
[RARC.9.2] The compilation model is explicit about which manifests are required when.
Compile-time (static) inputs [RARC.9.3]#
[RARC.9.3.1] Must be present when the compiler runs, or the compile fails with a specific error:
[RARC.9.3.2] Dialect manifests. The dialect the rule file declares (
use <dialect>) must be registered. Registration happens at compiler startup, from the built-in dialects and any definitions the integrator supplies ([LDIA.2.2], [NDLC.2.1]).
[RARC.9.3.3] Rule-file schema declarations.
schema ...blocks in rule files are parsed eagerly; they're part of the compilation unit.
[RARC.9.3.4] Service declarations reached by
import. An adapter declares the services it hosts in its.dslibrary file, and a rule file reaches them by importing that library ([LADP.8.1]). Those declarations are a compile-time input: the compiler resolves eachcall <service>against the declared set and builds the dispatch table at compile time ([LADP.8.2]). Acallnaming a service that is not in scope is a compile failure —DS_VALIDATE_UNKNOWN_SERVICE([LADP.8.2.3], [LCRS.10.4.2]).
see also: LADP.8.1, LADP.8.2, LADP.8.2.3, LCRS.10.4.2
[RARC.9.3.5] An adapter's service set reaches the compiler the same way for every adapter — through the imported
.dslibrary ([RARC.9.3.4]) — and reaches the engine at runtime as per-service callbacks the integrator registers against the C API, with the compiled.dsccarrying the service set the engine binds against ([LADP.8.1]).
see also: LADP.8.1, RARC.9.3.4
Registration-time inputs [RARC.9.4]#
[RARC.9.4.1] Arrive after the compiler has run, before the engine starts processing events. Validated at engine startup or first use:
[RARC.9.4.2] The service set is fixed at compile time from the imported library ([RARC.9.3.4]) and travels in the
.dsc; an adapter reaches the engine by the callbacks it registers ([IARC.1.14]). What is discovered at runtime is only whether a callback was registered for a given service: an unregistered one fails the call, it does not change the set.
see also: IARC.1.14, RARC.9.3.4
[RARC.9.4.3] Discovery-driven adapter schemas. An adapter that enumerates its entities at connect ([LADP.2.2]) emits umbrella facts whose entity is a string slot. The compiler validates the types of those facts; it cannot validate entity ids, which are not known until runtime.
see also: LADP.2.2
Runtime-bound inputs [RARC.9.5]#
[RARC.9.5.1] Arrive during engine operation, after event processing has begun:
[RARC.9.5.2] Adapter availability. When the integrator's call callback handles an adapter that is currently unreachable, it returns
CallErrorwith anadapter.*code whose leaf it chooses ([LECC.4.3]) — reachability is the integrator's environment and DS specifies no leaf for it ([LCRS.10.6.1]). The rule sees thatCallErroras it sees any ([LCRS.4.2.1]).
see also: LCRS.10.6.1, LCRS.4.2.1, LECC.4.3
[RARC.9.5.3] Storage-backend connectivity. A wired persistence callback may fail when the integrator's storage backend is unavailable. Its non-OK result reaches the integrator verbatim and the write stays in the engine's cache: a persistence failure is reported, not rolled back ([NCBK.7.5]).
see also: NCBK.7.5
[RARC.9.5.4] Hydration-query result shape. Runtime- validated against the declared schema in the hydration call; mismatches surface as
CallErrorper [LHYD].
Deferred: not binding in this edition.
Failure modes [RARC.9.6]#
Failure |
When detected |
Behaviour |
|---|---|---|
Undeclared dialect in rule file |
Compile |
Hard compile error with dialect list |
Unknown form for this dialect |
Compile |
Hard compile error per [LDIA.3.4.2] |
Call to an undeclared service |
Compile |
Hard compile error. The service set is fixed at compile time and carried in the |
Call to a declared service with no registered callback |
Runtime |
Fails at dispatch. There is no startup check, because nothing is published at startup to check against ([RARC.9.4.2]) |
Adapter cannot reach what it fronts |
Runtime |
The callback returns |
see also: LDIA.3.4.2, RARC.14.5, RARC.9.4.2, RARC.9.5.2
Changing the rule set [RARC.10]#
[RARC.10.1] An engine runs the artefact it was created with for its whole
life. To change the rule set, the integrator
frees the engine and creates a new one from the new .dsc. The new engine's
stream is a new session with the new ruleset_hash ([LFST.13.2],
[LFST.13.3]), and the new engine inherits nothing from the old one: what the
integrator wants carried across, it asserts again.
see also: LFST.13.2, LFST.13.3
[RARC.10.8] Nothing preserves activations across a change of rule set. A
call pending when its engine is freed is cancelled by nothing: the engine tracks
no pending call ([LCRS.10.6.1]) and synthesises no CallError ([NCBK.6.5]).
An answer that arrives afterwards has no engine to be asserted into.
see also: LCRS.10.6.1, NCBK.6.5
Engine-external components [RARC.11]#
Compiler [RARC.11.3]#
[RARC.11.3.1] A separate tool that turns DS source into a compiled .dsc
artefact before the engine runs ([RARC.9.1]). The integrator runs it, from a
command line or a build step, and loads its output; the engine never invokes
it.
see also: RARC.9.1
Test harness [RARC.11.5]#
[RARC.11.5.1] Lives alongside the engine for conformance and integration testing. Drives the engine with a synthetic event trace via direct asserts; mocks integrator callbacks to inspect what the engine emits; controls the clock deterministically via the mock-clock surface. It drives the engine through the same public surface any other integrator uses.
Adapters, storage backends, debugger bridges [RARC.11.6]#
None of them is a runtime component. Adapter-engine integration is the integrator's design (whatever transport, framing, and connection model fits their stack); storage backends connect via the cache callbacks; debugger bridges layer on top of the existing stream callback. See [IARC.1.14] for the discipline.
see also: IARC.1.14
Synthetic identifiers [RARC.12]#
[RARC.12.1] Synthetic names ([LLEX.10.6.1]), $ followed by the name, e.g.
$ClockTick, are the DS compiler's and the engine's own. No source text can
write one, so no author schema, rule or binding collides with one. The compiler
uses them for machine-generated names created during desugaring and for
engine-internal facts the runtime asserts directly:
see also: LLEX.10.6.1
[RARC.12.3] Compiler-generated synthetic facts, rules, series.
[RARC.12.4] Engine-internal facts like
$ClockTick.
(No synthetic name is author-visible; cache reads use the
IDENT-shape let v = cached(...) form per [LGRA.9.8.2].)
see also: LGRA.9.8.2
[RARC.12.5] $ is not a NAME character ([LLEX.10]), so author and compiler
namespaces can't collide structurally, not just by policy. The compiler passes
synthetic names through lowering unchanged. A synthetic schema carries no
.proto text, since no protobuf identifier can hold a $ ([RDSC.5.8.3]).
see also: LLEX.10, RDSC.5.8.3
Architecture invariants [RARC.13]#
[RARC.13.1] Tier mechanism, topology-agnostic. Each tier is one engine, with its own working memory, clock, dialect and stream, and the integrator bridges them. The runtime commits to no tier count or topology ([RARC.1.2]).
ratified — see also: RARC.1.2
[RARC.13.2] Process boundaries are integrator-picked. Co-locate tiers in one process for tight-latency cooperation; split across processes for independent restart, remote topology, or tier-to-tier fan-in. ([RARC.2.4]). Adapters and storage backends may run as separate processes for crash isolation.
see also: RARC.2.4
[RARC.13.3] The compiler is a separate tool. It runs before the engine and outputs a compiled
.dscartefact; the engine never invokes it ([RARC.9.1]).
see also: RARC.9.1
[RARC.13.4] Upward-only fact flow ([LTIE.3.1], [RARC.1.2]).
emitstays within its engine andpublishcrosses to the tier above. Downward effects go throughcall.
ratified — see also: LTIE.3.1, RARC.1.2
[RARC.13.5] A tier's cache is its own ([RARC.1.2]). A read is always an explicit
cached(...)([LGRA.9.8.2]) of that tier's engine.
see also: LGRA.9.8.2, RARC.1.2
[RARC.13.6] Same-tier emit-and-match is legal. A rule at tier T may
emit X; another rule at tier T may matchX. Normal Rete behaviour — emit asserts into the tier's working memory; the matcher sees it. Refraction keeps one activation from firing again until its LHS changes ([LDET.5.3], [LCYC.1.8]).
ratified — see also: LCYC.1.8, LDET.5.3
[RARC.13.7] Engine subsystems are first-class. Working memory, the network, the agenda and its conflict resolver, the clock source, the dispatcher and the consumption loop are each named, and each reaches the integrator only through the stream and the typed callbacks ([RARC.5.1]).
see also: RARC.5.1
[RARC.13.8] Stream delivery is foundational. Every observable event reaches the stream callback ([RARC.5.8.1]) through a narrow, spec-defined hook site ([RARC.5.8.4]), within the call that produced it ([RARC.5.8.7]) and without loss ([RARC.5.8.5]).
see also: RARC.5.8.1, RARC.5.8.4, RARC.5.8.5, RARC.5.8.7
[RARC.13.9] The consumption loop is the single writer per stream. Every input, internal and action event passes through it, and
seqis assigned at consumption ([RARC.8.2.1]).
ratified — see also: RARC.8.2.1
[RARC.13.10] Every time the engine computes with comes from the clock source ([RARC.5.5.3]). There is one clock per engine ([RARC.5.5.1]), and the clock tick follows the pump, with no interval of its own ([RARC.5.5.4.2]).
ratified — see also: RARC.5.5.1, RARC.5.5.3, RARC.5.5.4.2
[RARC.13.11] The conflict resolver enforces the firing order. The agenda's comparator orders by terminal ordinal, then creation timetag; refraction suppresses rather than sorts ([RARC.5.4.7]). Hash-order dependence is forbidden ([RARC.8.4.1]).
ratified — see also: RARC.5.4.7, RARC.8.4.1
[RARC.13.12] Dispatcher is the only outbound writer. Every action (
call,publish,cache_*,log) goes through the dispatcher, which records before sending. No bypass paths. Restates [RARC.5.7.1] and [RARC.5.8.12].
see also: RARC.5.7.1, RARC.5.8.12
[RARC.13.13] Parallelism is the integrator's, not the engine's. Sibling engines may run in parallel; within an engine, processing is serial ([RARC.8.5.1]).
see also: RARC.8.5.1
[RARC.13.14] A new rule set is a new engine. The new engine's stream is a new session, and nothing pending in the old engine is cancelled or carried. Restates [RARC.10.1] and [RARC.10.8].
see also: RARC.10.1, RARC.10.8
[RARC.13.15] Storage backend is external. The runtime ships no storage backend; persisting the cache is the integrator's, through the optional cache callbacks. Restates [RARC.1.7].
see also: RARC.1.7
[RARC.13.16] The engine is not re-entrant. Under synchronous delivery ([RARC.5.8.7]) a callback runs on the pump's own stack holding a live engine handle, so re-entry is invited by the design rather than merely possible. Any
ds_engine_*call on the engine that invoked the callback returnsDS_ERR_STATE. Every call, not only the mutating ones: a read taken from inside a callback observes a pump in progress — some activations fired and some not, the agenda part-drained — and a torn snapshot is worse than a refusal, because nothing about it announces that it is torn.Re-entering a different engine is the intended pattern and is unaffected. It is what [RARC.13.6]'s same-tier emit-and-match and [RARC.2.4.2]'s co-located tiers are built on, and it is why the rule has to be stated: an integrator writing the obvious cross-tier bridge eventually points it at the same engine, by configuration error or in a single-tier deployment.
[NLFC.8.2]'s refusal of
ds_engine_clonemid-pump is this rule applied to one call: the reason clone refuses is the reason every call refuses.Detection is an obligation, not a courtesy. Without it the failure is memory corruption — working memory mutated while the network propagates,
seqallocated from inside an event that has not finished being recorded — and the integrator gets no diagnostic at the point of the mistake. This is the invariant that protects the engine core's being a pure function of its inputs.That purity claim is bounded rather than bare, and the bound is the point. It quantifies over exactly four observables — the return value, the effect list, the event stream delivered to callbacks, and any
ds_engine_*read — and says the mutation is unobservable through those. It does not say the engine does not mutate; it mutates heavily.⚠ Timing is excluded, and must be. A declared
pump_wcetcap ([RTCT.7.1]) makes wall-clock a caller-visible quantity, so a purity claim quantifying over timing would simply be false.Its load-bearing lemma is refinement. The pump's cycle, with the integrator's callbacks run between its steps, reaches the working memory and delivers the event sequence of a single step computed from the engine state and the queued inputs, in every interleaving. The refusal above is what carries it: with every mid-pump call refused, a callback's only observation of the pump is the events it is handed, in their order, so no intermediate state that no single step has can reach the caller. That nothing leaks — no caller-reachable handle aliases engine state, the queue is the only channel — is less than this: the two part exactly where an implementation has intermediate states with no atomic counterpart.
⚠ And two of its premises are not the engine's to keep. Single-writer exclusion is the integrator's duty: [NLFC.3.3] makes a concurrent pump and assert undefined behaviour, so the refinement assumes the exclusion it reasons about, and nothing in C enforces it. [NLFC.2.2]'s eventual return is conditional on weak fairness in the scheduler, which is an assumption about the host rather than a property of the engine.
checks: tla×17 — see also: NLFC.2.2, NLFC.3.3, NLFC.8.2, RARC.13.6, RARC.2.4.2, RARC.5.8.7, RTCT.7.1
[RARC.13.17] A read's visitor callback refuses re-entry too. An enumerating read — of working memory, of the network's nodes and edges, of a match trace, of refracted activations — invokes a callback once per item it visits. [RARC.13.16]'s refusal holds inside that callback, for every call on the engine being enumerated. The enumeration is not on the pump's stack, but it is in progress: a call from inside it that mutates what is being enumerated invalidates the enumeration, and a read observes it half-visited. A call on a different engine is unaffected.
see also: RARC.13.16
Architecture refinements [RARC.14]#
[RARC.14.2] Event order. Within one engine every event takes the next
seqas it is produced ([RARC.5.6.9], [LFST.5.1]). Separate engines' streams are independent and share no order; there is no clock or counter spanning engines.
see also: LFST.5.1, RARC.5.6.9
[RARC.14.3] No event is dropped. The engine hands every event to the integrator before the call that produced it returns, and keeps none past that return ([RARC.5.8.7]), so it has no buffer to overflow. A sink slower than the engine slows the engine: mid-pump under synchronous delivery, between calls under a returned effect list.
see also: RARC.5.8.7
[RARC.14.4] Clock source under test harnesses. A test drives the clock through the mock clock ([NTST.3]). The next input or pump samples the clock source, and a mock mutation is recorded at that sample, not when it is made ([NTST.3.3]).
[RARC.14.5] Adapter-disconnect recovery semantics. The engine has no concept of a disconnected adapter ([NADP.5.1.1]). Rules do not pause, the callback keeps being invoked, and an unreachable adapter is reported by the callback returning
CallErrorwith a code it chooses ([RARC.9.5.2]). Pending correlations are neither cancelled nor replayed by the engine.
see also: NADP.5.1.1, RARC.9.5.2
[RARC.14.8] Back-pressure between tiers is the integrator's. The engine holds no queue between engines ([RARC.6.1.2]), so it applies no back-pressure: what happens when an upper engine falls behind a lower one is decided by the integrator's bridge.
see also: RARC.6.1.2