DS fact model: lifecycle and no-op reassertion discipline#
This document covers:
The two fact lifecycle categories (
logical/ttl) declared on every schema, and what the choice commits an adapter (or rule) to at runtime.The no-op reassertion discipline — the engine-side contract that
logicalfact semantics depend on.
Paired with [LGRA], which specifies the syntax for the lifecycle modifier; this doc specifies the runtime semantics the modifier implies.
What this is not#
Not a schema-declaration grammar reference — that's [LGRA].
Not a cross-tier fact-flow specification — see [LTIE] for the language-side contract and [RARC] for the runtime-side mechanism.
Not an implementation guide for adapter authors — adapter-specific docs own the per-system details of meaningful-change filtering.
The two fact lifecycle categories [LFAC.1]#
[LFAC.1.1] Every schema picks a lifecycle via the optional
scope clause on its header. Four values are admitted per
[LSCP.1.5]: explicit, logical, ttl <duration> and
activation, and logical and ttl may carry the ambient
modifier. When scope is omitted, the schema
defaults to scope explicit per [LSCP.1.4].
This section covers logical and ttl; explicit,
activation, and ambient live at [LSCP.2].
ratified — checks: k — see also: LSCP.1.4, LSCP.1.5, LSCP.2
logical facts [LFAC.1.2]#
[LFAC.1.2.1] Asserted by adapters that bridge external entity-oriented state (Home Assistant entities, MQTT retained topics, weather current-conditions, author-declared state facts) or by rules using
emit X logical.
[LFAC.1.2.2] Retract-and-replace on each meaningful change. Exactly one live fact per identity key — the slots the
logicalschema declareskeyper [LFAC.1.7]. (This is the key-subset case of the declared-key model.)
checks: k idris×23 — see also: LFAC.1.7
[LFAC.1.2.3] Persist in working memory until the next meaningful change retracts them.
[LFAC.1.2.4]
t.dwell(time since last meaningful change) is well-defined.
[LFAC.1.2.5]
emit X logicalcompiles only whenXis declaredlogical. The engine maintains truth correspondence between the emit rule's LHS and the emitted fact: the fact lives while the LHS matches, retracts when it stops matching, and survives cycles where the LHS continues to match.
ratified
[LFAC.1.2.6] Examples of logical schemas:
Adapter-emitted: HA entity state, MQTT retained-topic state, weather current-conditions.
Rule-emitted: derived state like
Occupied,InQuietHours,OnCall— things that are either "true right now" or "not true right now."
Identity keys [LFAC.1.7]#
checks: alloy×2 idris×2
[LFAC.1.7.1] A logical fact's identity is the declared
subset of its slots marked key; the remaining slots, marked
mutable, are payload. The author declares the role of every
slot with the per-slot key / mutable markers (the
field_decl production is [LGRA.5.1]; the marker tokens are
reserved words per [LLEX.9.5]). Identity
comparison is exact: a tolerance is admissible only on a
mutable slot, never a key slot ([LGRA.5.9.10]). Two Float keys are
exactly equal when they compare equal under IEEE 754 ==, so -0.0 and
0.0 are one identity ([LDET.3.2.7]). A NaN never reaches a key, because a
NaN Float is refused before it enters working memory ([LEXP.4.2]).
ratified — checks: idris — see also: LDET.3.2.7, LEXP.4.2, LGRA.5.1, LGRA.5.9.10, LLEX.9.5
[LFAC.1.7.2] One rule covers the whole range: two assertions with the same key values are the same fact — the later one supersedes the earlier, its payload replacing the prior. The width of the key selects the behaviour:
key = ∅ (every slot
mutable) — a singleton: one live fact, latest payload wins.key = one slot — entity-state: one live fact per entity.
key = several slots — a composite key.
key = all slots (every slot
key, no payload) — a relation: distinct tuples coexist and identical tuples coalesce. This is the key-all case of [LLOG.2.7].
A schema of one slot, marked key, is both the second case and the last. They
are one behaviour there: one live fact per key value, which a reassertion
coalesces.
ratified — checks: k souffle idris×8 — see also: LLOG.2.7
[LFAC.1.7.3] Relation, entity-state, and singleton are not separate fact modes — they fall out of which slots are the key.
[LFAC.1.7.4] Require-all. Every slot of a logical
schema must be marked key or mutable. The compiler rejects
an unmarked slot on a logical schema. Require-all is the
forcing function: no slot is unmarked, so there is no
default-direction question and no silent guess. The one slot it
does not reach is ts, which is the engine's and carries no marker
([LFAC.9.1]).
ratified — checks: alloy×2 — see also: LFAC.9.1
[LFAC.1.7.5] The identity key is the single answer every identity consumer reads: retract-and-replace dedup ([LFAC.1.2.2]), cooldown keying ([LCDB.3.3.1]), no-linear-scan join anchors ([LNLS.3.3]), series grouping ([LSER.7.6.1]), and debug display names ([RDSC.6.8.4]). No consumer resolves identity independently.
see also: LCDB.3.3.1, LFAC.1.2.2, LNLS.3.3, LSER.7.6.1, RDSC.6.8.4
[LFAC.1.7.6] ttl / event facts carry no markers. A
mutable payload presupposes supersedure, the defining
property of logical; ttl facts have no per-identity
uniqueness ([LFAC.1.3.2]) — they accumulate and expire — so
key / mutable are a category error on them. The compiler
rejects a marker on a non-logical slot. A ttl schema's
grouping needs (cooldown-per-entity, series by:) are separate
per-consumer concepts, unchanged by this model.
see also: LFAC.1.3.2
[LFAC.1.7.7] The declared-key identity model applies to a logical
base whether or not the ambient modifier is layered ([LSCP.2.5]):
scope logical ambient is scope logical for identity — same
require-all markers, same key = all ⇒ relation ([LFAC.1.7.2]).
ambient changes who may write, never how the fact is keyed.
ratified — see also: LFAC.1.7.2, LSCP.2.5
ttl facts [LFAC.1.3]#
[LFAC.1.3.1] Asserted by event-oriented adapters (HA events from the event bus, camera detections, MQTT non-retained messages, response facts and
CallErrorfrom service calls) or by rules using plainemit(nological).
[LFAC.1.3.2] Accumulate in working memory — multiple in-flight facts of the same schema coexist; there's no per-identity uniqueness.
ratified — checks: k
[LFAC.1.3.3] Expire via per-schema or per-emit TTL. A fact received from another tier takes the receiving schema's lifecycle ([LTIE.9.4]).
ratified — checks: k — see also: LTIE.9.4
[LFAC.1.3.4]
t.dwellis a compile error ([LFAC.4.5]) — the fact's entry stamp ([LTIM.2.8.6]) is the moment it was asserted, not the moment something changed.
see also: LFAC.4.5, LTIM.2.8.6
[LFAC.1.3.5]
emit X logicalis a compile error whenXis declaredttl.
ratified — checks: idris
[LFAC.1.3.6] Examples of ttl schemas:
Adapter-emitted: HA event-bus events, camera detections, MQTT non-retained messages, call response facts and
CallError([LCRS.4.3.2]).Rule-emitted: alerts, transient intermediate events, anything that represents "something just happened."
see also: LCRS.4.3.2
Why the choice is load-bearing [LFAC.1.4]#
[LFAC.1.4.1] The lifecycle category decides whether several load-bearing language primitives work against a schema:
[LFAC.1.4.2]
t.dwell— only well-defined onlogical-schema bindings. Onttlschemas it is a compile error ([LFAC.4.5]).
ratified — see also: LFAC.4.5
[LFAC.1.4.3]
logicalemit — targets must belogicalschemas. A rule usingemit X logicalwith attl-declared X is a compile error.
[LFAC.1.4.4] No-op reassertion discipline — applies to
logical-schema emitters only (see [LFAC.2]).ttlschemas don't need the discipline because each emit is independently timestamped and meaningful.
see also: LFAC.2
[LFAC.1.4.5] Cross-tier emit semantics —
logicalfacts crossing a tier boundary need retract-replace on the wire;ttlfacts don't. See [LTIE].
[LFAC.1.4.6] Making the choice implicit would hide all of these consequences behind a default. The mandatory header is a one-time decision per schema that reaches into every rule touching the schema.
Mapping from source to category [LFAC.1.5]#
[LFAC.1.5.1] Typical adapter-side mapping:
[LFAC.1.5.2] HA entity →
logical. Retract + reassert onstate_changedwith meaningful-change suppression.
[LFAC.1.5.3] HA event-bus event →
ttl. Emits once per event, TTL-based.
[LFAC.1.5.4] Camera detection →
ttl. Each detection is an event.
[LFAC.1.5.5] MQTT retained topic →
logical. Retained = "current state."
[LFAC.1.5.6] MQTT non-retained →
ttl. Published events.
[LFAC.1.5.7] Weather current-conditions →
logical. One fact per location at a time; retract-replace on refresh.
[LFAC.1.5.8] Weather forecast →
ttl. Many forecast slots simultaneously; refresh retracts all and reasserts the new set.
[LFAC.1.5.9] Rule
emit X(nological) →ttlby default.
[LFAC.1.5.10] Rule
emit X logical→logical(and X must be declared so).
[LFAC.1.5.11] If a concept legitimately needs both forms
— e.g., Occupied as both a transient entry event and a
maintained state — split into two schemas
(OccupiedEvent ttl + Occupied logical). Forces the two
intents to be visible at authoring time.
Mixing categories in one rule [LFAC.1.6]#
[LFAC.1.6.1] A rule's LHS can pattern-match both categories without any special syntax.
ratified
[LFAC.1.6.2] The category difference is a property of
each fact, not the rule. The rule fires when a matching
Person arrives while the lux sensor is in the "low"
state.
No-op reassertion discipline [LFAC.2]#
checks: alloy×2
[LFAC.2.1] logical-fact semantics depend on this
discipline. When an incoming reassertion of a live fact
carries the same slot values, the engine must not
retract-and-reassert. Doing so would:
[LFAC.2.2] Reset
dwell(sincedwellmeasures from the fact's entry stamp and a reassertion would re-enter the fact, [LTIM.2.8.6]), making dwell-based rules wrong.
see also: LTIM.2.8.6
[LFAC.2.3] Briefly end
logicalemit activations whose LHS depended on the fact, causing derived facts to flicker retract → reassert.
[LFAC.2.4] Generate meaningless series samples, polluting statistics over the slot.
ratified
Enforcement [LFAC.2.5]#
[LFAC.2.5.1] Engine-side (primary): the engine de-duplicates no-op reassertions as the correctness contract. For
String,Bool,TYPE_NAME, and defaultInt/Floatslots the comparison is exact equality; for aFloatthat is IEEE 754==, so a reassertion that turns0.0into-0.0is a no-op ([LFAC.1.7.1]). ForJsonslots the comparison is deep structural equality: two values are equal iff they are the same kind andtwo objects have the same set of keys and, under each key, equal values; member order carries no meaning;
two arrays have the same length and equal elements, position by position;
two strings have the same bytes, two booleans the same value, and two nulls are equal;
two integers have the same value, and two floats compare by IEEE 754
==, so0.0equals-0.0.
An integer and a float are different kinds, so
1and1.0are not equal: a leaf keeps the kind it was written with ([LEXP.7.12.1]).For a slot with a declared
tolerance([LGRA.5.9]; on a unit-typed slot, in its base unit, [LUNI.7.4]), values within the tolerance are treated as equal. The bound is INCLUSIVE: the values are equal iff they are exactly equal or|delta| <= tolerance, so a change of exactlytoleranceIS suppressed. Two equal infinities are therefore equal under any tolerance, though theirdeltais NaN. This matters in ordinary use rather than at a float edge —toleranceis declared onIntslots too, where a delta landing exactly on the bound is commonplace.When a reassertion is suppressed,
dwelldoes not reset, no series sample is generated, and derivedlogicalfacts do not flicker.The comparison is over the author's slots.
tsis not compared ([LFAC.9.1]): a reassertion that differs from the live fact only intsis a no-op, and the live fact keeps itsts.
ratified — checks: alloy×3 tla k idris×25 — see also: LEXP.7.12.1, LFAC.1.7.1, LFAC.9.1, LGRA.5.9, LUNI.7.4
[LFAC.2.5.2] Adapter-side (optional efficiency): adapters may additionally suppress no-op updates at the source-system boundary to reduce wire traffic and engine load. Not required for correctness — the engine's dedup is the contract. Adapters that suppress aggressively emit less (entity adapters comparing against last-emitted state; message-bus adapters dropping identical republishes; polling adapters dropping unchanged refreshes); adapters that pass everything through let the engine do the work. Adapter-specific documentation describes what each adapter chooses to do.
ratified
[LFAC.2.5.3] The complement: a meaningful change is a replace, never a second fact, and is never silent. A reassertion that is not a no-op under [LFAC.2.5.1] — a
tolerance-bearing slot whose value moves outside the tolerance, or any exactly-compared slot that changes — is a meaningful change. The engine must apply it as a retract-and-replace per [LFAC.1.2.2]: the prior fact for that identity key ([LFAC.1.7]) is retracted and the new one asserted, so exactly one live fact per key remains (the live count is unchanged), the new fact is a fresh wrapper with a newfact_id([IDAT.4.4]), andtsadvances. The engine must surface this on the stream asFACT_ASSERT(new)followed byFACT_RETRACT(old), whether a host assert or a rule's emit produced the new fact: the successor is recorded before the withdrawal it causes ([RFCS.6.7], [RFCS.6a.4]).FACT_MODIFYis reserved and not emitted ([NCBK.2.4]). An in-place same-wrapper mutation that emits no stream event, and any path that leaves a second live fact for the same key, are both non-conforming.
ratified — checks: alloy×3 tla×2 k idris×18 — see also: IDAT.4.4, LFAC.1.2.2, LFAC.1.7, LFAC.2.5.1, NCBK.2.4, RFCS.6.7, RFCS.6a.4
[LFAC.2.5.4] Equality basis:
String/Bytesby content, not pointer. The no-op vs meaningful-change decision onStringandBytesslots — and the identity-key match ([LFAC.1.7]) — is by byte content, never by interned-pointer identity. Interning is a non-observable runtime optimization ([IRET.1.4] / [IDAT.4.7]): a conforming implementation MUST NOT depend on two equal strings sharing a pointer, nor expose interned-pointer identity across the wire or any observable surface. Two facts with byte-equalString/Bytesslots are equal regardless of how the runtime stores those bytes (interned engine-lifetime, refcounted, arena-copied, or duplicated), so the intern-leak seal's refcount + arena machinery is invisible to conforming programs.
ratified — checks: idris×5 — see also: IDAT.4.7, IRET.1.4, LFAC.1.7
Scope [LFAC.2.6]#
[LFAC.2.6.1] The discipline applies to logical-schema
emitters:
[LFAC.2.6.2] All adapters emitting
logical-declared schemas.
[LFAC.2.6.3] All rules using
emit X logical.
[LFAC.2.6.4] tolerance is legal on logical schemas only.
It drives the no-op dedup above — a within-tolerance reassertion
of the same identity ([LFAC.1.7]) is suppressed — so it
presupposes identity dedup. A ttl / event fact carries no
identity markers ([LFAC.1.7.6]) and does not dedup; such facts
accumulate and expire on their deadline, so tolerance has
nothing to suppress there. tolerance on a ttl-scoped schema
is therefore a compile error (DS_VALIDATE_TOLERANCE_TTL_SCHEMA;
grammar rule [LGRA.5.9.5]). The rule is logical-only, not
merely ttl-specific: the compiler rejects tolerance on every
non-logical lifecycle (ttl, explicit, ambient), matching
the runtime, which rejects it on any non-logical schema at
load. The ttl case (the common one) reports
DS_VALIDATE_TOLERANCE_TTL_SCHEMA.
ratified — checks: idris — see also: LFAC.1.7, LFAC.1.7.6, LGRA.5.9.5
Why it's load-bearing [LFAC.2.7]#
[LFAC.2.7.1] Spec language throughout DS assumes the discipline holds:
[LFAC.2.7.2] Series aliases (
t.mean,t.stdev,t.direction,t.dwell) are well-defined only when the fact re-enters working memory — and its entry stamp advances ([LTIM.2.8.6]) — on meaningful change alone. See [LSER].
see also: LTIM.2.8.6
[LFAC.2.7.3]
logicalemit's truth-maintenance correspondence depends on stable LHS bindings; no-op reassertions destroy stability. See [LLOG].
[LFAC.2.7.4]
within <dur>onlogicalpatterns means "a live fact whose last meaningful change was within the last dur" — only coherent under the discipline.
[LFAC.2.7.5] The engine's dedup discipline holds
regardless of adapter behaviour. Rule authors can read
t.dwell > 5_min and rely on dwell advancing only on
meaningful change.
[LFAC.2.7.6] For noisy-sensor slots where "meaningful
change" means something other than exact equality, the
tolerance modifier on the schema declaration (see
[LGRA]) is the visible,
engine-enforced way to set the threshold — no reliance on
adapter-specific configuration living outside the rule
file.
Fact-model commitments [LFAC.4]#
[LFAC.4.1] Two lifecycle categories, declared on the schema header. An omitted
scopeisscope explicit([LSCP.1.4]); the choice is load-bearing.
see also: LSCP.1.4
[LFAC.4.2] Keywords are
logicalandttl. The schema-header word matches the emit-modifier word (emit X logical). See [LGRA].
ratified
[LFAC.4.3] Engine-primary no-op dedup. The engine de-duplicates reassertions as the correctness contract. Adapters may suppress at the source as an efficiency optimisation. See [LFAC.2.5].
ratified — see also: LFAC.2.5
[LFAC.4.4] Slot-declared tolerance. Numeric slots with per-slot tolerance drive the engine's tolerance-aware comparison. Author-visible at the schema; no hidden per-adapter epsilon.
[LFAC.4.5] Compile-time enforcement.
emit X logicalrequires X's schema lifecycle to belogical.t.dwellonttl-schema bindings is a compile error.
ratified
[LFAC.4.6] Splitting categories for dual-intent concepts. If a concept has both event and state aspects, split into two schemas (
FooEvent ttl+Foo logical) rather than conflating.
Cross-boundary representation [LFAC.8]#
[LFAC.8.1] Schemas are declared in DS source using DS's declarative schema syntax. The author does not write protobuf.
[LFAC.8.2] The compiler generates a canonical .proto
definition for each schema declaration. The generated
.proto is the structural shape of fact instances of
that schema for any cross-boundary use: persistence to
disk by storage adapters, recording in event-trace
artefacts per [LFST.8.10], hypothetical wire transport,
debug inspection, code generation for integrator type
stubs.
see also: LFST.8.10
[LFAC.8.3] The compiler ships every schema's generated
.proto inside the compiled rule artefact (.dsc), per
[LFST.11.9] and [RDSC.5.8]. Tooling that needs
schema-typed access fetches the .proto from the
artefact rather than from a separate distribution.
[LFAC.8.4] The in-process callback surface delivers fact
instances as typed in-memory values per [LFST.2.1];
protobuf is the cross-boundary serialisation form. A
callback receiver may itself encode to protobuf (using
the schema's .proto from the artefact) when forwarding
cross-boundary, but the runtime does not protobuf-encode
for in-process delivery.
see also: LFST.2.1
[LFAC.8.5] The compiler must keep a schema's generated
.proto consistent with the schema's slots: one field per slot,
of the type the slot's kind takes ([RDSC.5.8.7]), optional exactly when
the slot is nullable ([RDSC.5.8.3]). The .proto describes an
instance's slots and nothing else: the schema's lifecycle, slot
tolerance and hydration are carried by their own atoms. Drift between the .proto and the slot-typed
metadata is a compiler bug.
ratified — see also: RDSC.5.8.3, RDSC.5.8.7
[LFAC.8.6] SchemaDef↔metadata round trip. A conforming compiler must be
exercised by a fixture that compiles each schema kind in the slot-
type matrix [RDSC.5.8.6] states, loads the resulting .dsc
artefact, and asserts that the SchemaDef atom's
proto_source agrees with the Slot atoms field-by-field
([LFAC.8.5]: the .proto describes slots only): every slot in the .proto
appears as a Slot atom whose kind takes the field's type
([RDSC.5.8.7]), and vice versa. The test fails on
any unidirectional entry (Slot without .proto
field, or .proto field without Slot). This makes
the [LFAC.8.5] invariant mechanically checkable
rather than asserted by inspection. Runtime-side
fixture lives at
[RDSC.5.8.6].
ratified — see also: LFAC.8.5, RDSC.5.8.6, RDSC.5.8.7
The ts slot [LFAC.9]#
[LFAC.9.1] A slot named ts is a Time. A schema may declare a slot named
ts and need not. If it does, the slot's type must be Time, not nullable. The
compiler must refuse a ts slot of any other type, Time? included, with
DS_VALIDATE_TS_NOT_TIME.
A construct that needs ts requires it of the schemas it reads: every adapter
schema declares it ([LADP.4.2.1]), and so does every schema in a then sequence,
the anchor latest pins among them ([LTHE.4.5]). Any other schema may declare it,
and there it is the slot this clause describes and nothing more.
ts is the engine's slot, outside identity and outside the no-op test. It
carries no key or mutable marker on any schema; on a logical schema it is
the one slot [LFAC.1.7.4]'s require-all does not reach, and the compiler must
refuse a marker on it with DS_VALIDATE_TS_MARKED. It takes no part in the
schema's identity key ([LFAC.1.7]) and no part in the no-op comparison
([LFAC.2.5.1]): a reassertion that differs from the live fact only in ts is
a no-op, and the live fact keeps the ts it was given when it entered
([LFAC.9.2]). In the artefact, on a logical schema, it carries the identity role
ENGINE ([RDSC.5.5.7]). Only a logical schema has a no-op test or an identity
key; on any other schema ts is a slot like the rest wherever two facts are
compared ([RFCS.23.7]), since it is what tells two events of one schema apart.
ratified — checks: alloy×4 — see also: LADP.4.2.1, LFAC.1.7, LFAC.1.7.4, LFAC.2.5.1, LFAC.9.2, LTHE.4.5, RDSC.5.5.7, RFCS.23.7
[LFAC.9.2] Where ts comes from. When a fact of a schema that declares
ts enters working memory, its ts is set by where the fact comes from:
for a fact a rule asserts (
emit), and for a fact a rule publishes, which enters no working memory here ([LTIE.4.3]), the engine must set it to the wall clock's current sample, as a UTCTime(RLOW.7.1.2). The engine must filltsbefore it evaluates any of the action's slot values. Where the wall clock has no value ([LTIM.2.8.3]), the fault it records is thetsfill's, whatever a slot value would have raised;for a fact an
initialblock places ([LGRA.24.3]), which supplies nots, the engine must set it to the wall clock's sample of the step that consumes it ([LTIM.2.8.4]);for a host input, the host must supply it ([NFCT.2.10]), and it is source time ([LADP.4.2.1]). The engine must not fill a host input's
ts.
A test input writes no ts ([LFAC.9.3]). The test runner must supply it, as a
host supplies source time: the test clock's wall sample at the input's at
coordinate, which is the coordinate's instant in absolute mode ([LTSL.3.2]) and
its offset from the Unix epoch in relative mode ([LTSL.3.1]).
ratified — checks: alloy×5 — see also: LADP.4.2.1, LFAC.9.3, LGRA.24.3, LTIE.4.3, LTIM.2.8.3, LTIM.2.8.4, LTSL.3.1, LTSL.3.2, NFCT.2.10, RLOW.7.1.2
[LFAC.9.3] ts is read-only to authors. An author may read ts wherever a
slot may be read, in patterns, expressions and test assertions, and must not
write it. The compiler must refuse a ts value supplied by a rule's emit or
publish, or by a test's constructed fact in inputs, initial or a response
reply ([LTSL.4.1]), with DS_VALIDATE_TS_READ_ONLY.
ratified — see also: LTSL.4.1
Slot values [LFAC.10]#
[LFAC.10.1] A slot holds a value, and the value is its fact's own. A fact
asserted or emitted with a value read from another fact holds that value
itself, not a reference to the other fact's slot. The engine must leave it
unchanged when the fact it was read from is retracted, superseded
([LFAC.2.5.3]) or expires, whatever the value's type, Json and Bytes
included.
A schema-typed slot is the one exception by design: its value is a fact reference ([LGRA.5.7a.2]), and what a read of it answers is [LEXP.7.20]'s.
ratified — see also: LEXP.7.20, LFAC.2.5.3, LGRA.5.7a.2
Terms [LFAC.11]#
A fact is one instance of a schema: a value for each of its slots. Working memory is the set of facts an engine holds live ([RARC.5.2.1]). An activation is a rule together with the particular facts that matched it: a firing owed until it fires, which stays, fired, while its match lasts ([LDET.5.3]).
see also: LDET.5.3, RARC.5.2.1