Storage planes#

The three storage planes DS rules interact with: facts, samples, and cache. This document describes only the author-visible surface and the semantic guarantees the language relies on. Backend choices, wire protocols, connection topology, queueing, federation, and deployment shape are runtime concerns, out of scope.

Paired with:

  • [LGRA.10] — the action grammar for cache, cached(...), cache_delete, and the call storage;* service-invocation form.

  • [LSER] — series declarations; the persist: kwarg there is the author-facing samples-write knob.

  • [LLOG] and [LFAC] — fact lifecycle, orthogonal to persistence.

What this is not#

  • Not an implementation spec. Backends (append-only log, TSDB, in-memory KV), wire protocols, queueing policies, shedding mechanisms, federation, and deployment shape belong with the runtime that hosts the storage adapter.

  • Not an SQL / external-query surface. External consumers (dashboards, ad-hoc queries) talk to backends directly; DS rule-facing access goes through the typed primitives below.


The three planes [LSTO.1]#

[LSTO.1.1] One surface, three planes, each tuned to a different question. The facts and samples planes are deferred ([LSTO.2], [LSTO.3]); in this edition the cache plane alone binds.

Facts

Samples

Cache

Answers

"what happened?"

"what did we sense?"

"what is?"

Primitive

a fact working memory held ([LSTO.2.1])

(ts, value) per (entity, field)

key → value

Shape

discrete, sparse

dense, continuous

mutable, current-only

Write

call record_fact

persist: on series

cache key: value

Read

call hydrate_facts (async; the facts return to working memory)

call hydrate_samples (async; the samples return as facts)

let v = cached("key") (sync)

Loss

must-not-lose

drop-oldest acceptable

must-not-lose

see also: LSTO.2.1, LSTO.2, LSTO.3

[LSTO.1.2] Authors pick the plane that matches the data shape; the engine preserves the listed semantics regardless of how each plane is implemented.


Facts plane [LSTO.2]#

Deferred: not binding in this edition.

[LSTO.2.1] Discrete facts, stored when something worth remembering happens. Append-only, long retention. A record is a fact working memory held: the language owns its encoding, and the store keeps it opaque, selecting records only by what it is given beside each one — the schema, the time the fact entered working memory, and a count.

Write [LSTO.2.2]#

[LSTO.2.2.1] A rule stores a fact by calling record_fact with it: the service's one kwarg is declared Schema and takes a pattern binding ([LADP.8.6.1]). The service declares no response ([LADP.8.4.2]), so a stored fact produces nothing and a failed store produces a CallError ([LCRS.17.1]). A rule that wants a fact both in working memory and stored emits it and stores the binding a later rule matches.

see also: LADP.8.4.2, LADP.8.6.1, LCRS.17.1

[LSTO.2.2.2] Adapters that assert facts worth storing store them through the same service (adapter-side, not author-facing).

Read [LSTO.2.3]#

[LSTO.2.3.1] call hydrate_facts … — async; the stored facts return to working memory as hydrated facts ([LHYD.2.1]). It is the only read of the facts plane: the store cannot see inside a record ([LSTO.2.1]), so a rule counts or aggregates hydrated facts in working memory.

see also: LHYD.2.1, LSTO.2.1

Loss [LSTO.2.4]#

[LSTO.2.4.1] Must-not-lose. A stored fact is durable against engine restarts and tolerated delays. The storage service must assert a CallError for every write it cannot make durable ([LCRS.17.1]); a rule can assume a stored fact is durable unless a CallError says otherwise, and a rule that must act on a lost write matches that CallError.


see also: LCRS.17.1

Samples plane [LSTO.3]#

Deferred: not binding in this edition.

[LSTO.3.1] Dense continuous (ts, value) streams per (entity, field). Declared through the persist: kwarg on a series, not through a separate write action.

Write [LSTO.3.2]#

[LSTO.3.2.1] persist: <dur> on a series declaration forwards every sampled value to the samples plane. <dur> is the raw retention window; older samples are downsampled or archived per runtime policy. Without persist:, the series stays live-only. The integrator wires the actual sample destination via a dedicated callback per [NSTG.5]; the engine does not assume a specific backend shape.

see also: NSTG.5

[LSTO.3.2.2] Multiple series against the same (entity, field) collapse to one underlying sample stream; persistence takes the maximum declared retention.

Schema marker [LSTO.3.3]#

[LSTO.3.3.1] Adapters that emit sampled state mark the relevant slot sampled on the schema.

[LSTO.3.3.2] The sampled marker tells the engine to route writes on this slot into the samples plane. Slots without the marker are working-memory facts and nothing more.

Read [LSTO.3.4]#

[LSTO.3.4.1] call hydrate_samples … — async; the samples return as HydratedSample facts ([LHYD.2.2]), which rules aggregate or pick from in working memory. The samples plane has no other read.

see also: LHYD.2.2

Loss [LSTO.3.5]#

[LSTO.3.5.1] Drop-oldest acceptable. During surges, the samples plane may shed samples rather than block. Rules must not assume every sample is present when reasoning over long windows. Series aggregations (mean(s) etc.) operate over whatever samples arrived. Authors who need exactness store facts instead.


Cache plane [LSTO.4]#

[LSTO.4.1] Mutable key-value store with the only synchronous read in the storage surface. Suited for small current-state keys that rules need to read inside the fire loop without a round-trip.

Ownership [LSTO.4.7]#

[LSTO.4.7.1] The engine owns the cache. The authoritative current value of every key is engine state, held in an in-engine key-value map alongside working memory. cached() ([LSTO.4.3.1]) is an engine-local read — a peer of now() / monotonic_ns() — served from that map with no callback and no round-trip. The integration owns only durability ([LSTO.4.5.2]): an optional write-through that persists the engine's cache and re-seeds it on startup.

ratified — see also: LSTO.4.3.1, LSTO.4.5.2

[LSTO.4.7.2] The engine's cache is authoritative and must be mutated only by cache / cache_delete on the deterministic input stream, a TTL expiry ([LSTO.4.6.1]), an initial block's cache item ([LGRA.24.3]), and the startup hydrate ([LSTO.4.5.2]). The write-through hook is outbound only (engine → external store); an out-of-band write to a cached key — an external writer mutating the store behind the engine's back — is unsupported. This constraint is load-bearing: it is what lets cached() be a pure internal read that leaves the recorded-input set ([RARC.5.7.9] / [RFCS.15.7] / [LFST.9.2]).

see also: LFST.9.2, LGRA.24.3, LSTO.4.6.1, LSTO.4.5.2, RARC.5.7.9, RFCS.15.7

[LSTO.4.7.3] The cache is not reified into working memory: it is not rule-matchable and the engine does not fire on cache change ([LSTO.4.2.1]). No store is shared between engines ([LTIE.5.2]).

see also: LSTO.4.2.1, LTIE.5.2

[LSTO.4.7.4] The "startup hydrate" of [LSTO.4.7.1] / [LSTO.4.7.2] is realised at the integration boundary by the cache-seed operation ([IARC.12] / [NSTG.9]): a setup-only, direct cache-store write that restores persisted entries before the engine's first stream event ([NLFC.9.1]). It is not a rule's surface — no rule or expression seeds the cache; a rule writes the cache with cache / cache_delete and reads it with cached(). An initial block's cache item seeds a key as the host's seed does ([LGRA.24.3]). (The .dstest initial: cache arrange, [LTSL.5.2], drives the same primitive, but that is test scaffolding, not the authored program.)

see also: IARC.12, LGRA.24.3, LSTO.4.7.1, LSTO.4.7.2, LTSL.5.2, NLFC.9.1, NSTG.9

[LSTO.4.7.5] The cache may be bounded. An integration may bound the cache by the number of its live keys and by the total bytes of its values. Neither bound is set by default, and an unbounded cache refuses no write. A bound binds the writes and seeds that follow its setting and evicts nothing; it never changes during a pump.

A cache write of a key the cache does not hold, when it already holds as many live keys as the key bound allows, or a write that would leave more value bytes than the byte bound allows, is a bounds refusal ([LERR.1.5]). The engine must not perform the write. It records a BoundsError naming the bound and stops the firing at the write, by the prefix rule of [LNUL.11.1]: the actions before it stand, and the actions after it do not run. The pump goes on and returns DS_ERR_CONTRACT_BREACH, and a later cached() reads the cache as it was before the refused write.

A cache seed ([LSTO.4.7.4]) is charged against the same bounds. A seed past either bound is refused with DS_ERR_CONTRACT_BREACH and leaves the cache unchanged.

A bound changes what cached() reads, so it is engine configuration that a replay must reproduce ([LDET.2.7]).

ratified — see also: LDET.2.7, LERR.1.5, LNUL.11.1, LSTO.4.7.4

Write [LSTO.4.2]#

[LSTO.4.2.1] cache key: <key> value: <value> on the RHS of a rule. Values are opaque to the engine — whatever the underlying fact model can serialise. The engine does not version, inspect, or trigger rule matches on cache change.

Read [LSTO.4.3]#

[LSTO.4.3.1] cached("<key>") is always synchronous at the language surface. Every implementation of cached() MUST return the value inline, in the same rule activation, without a call/response round-trip.

[LSTO.4.3.1a] cached() is allowed in where clauses — the one exception to the read-function placement rule ([LGRA.9.8.2]). The cache is read-only during pattern matching — no rule RHS can execute while patterns are being evaluated — so the value is stable for the duration of a single activation. This enables cache-keyed refraction: a rule can skip firing when the relevant cache state has not changed since the last dispatch, by testing a fact's revision against the cached value from the prior dispatch and writing the new value back on the same firing.

The read key may be interpolated: [LGRA.2.9.6.8] makes a cached(…) key an interpolation-eligible position, and every segment of it must be non-nullable and non-absent. A cache write's key is a literal ([LGRA.10.3.7]), so a rule writes its value back to one fixed key. An interpolated key is filled by the host's seed or an initial cache item ([LGRA.24.3]).

A cache miss returns null ([LSTO.4.3.1b]). Because null propagates through the != comparison (Kleene 3-valued null semantics, [LNUL]), a bare inequality test against the cached value would be null on a miss and so would not fire; an explicit cached(...) is null disjunct — the total null test ([LNUL.4.4]) — catches the miss, so the first dispatch always fires. Each later hit then refracts (an unchanged value compares false) and a changed value re-fires.

The miss-catching disjunct must be is null. Spelling it cached(...) == null is a compile error ([LNUL.4.4]) — and the reason it is refused is exactly the reason the idiom needs it: == propagates, so on a miss that disjunct would be null too, and the whole or would be null rather than true. The rule would then never fire on a cold cache, which is the one case the idiom exists to handle.

ratified — see also: LGRA.10.3.7, LGRA.2.9.6.8, LGRA.24.3, LGRA.9.8.2, LNUL.4.4, LSTO.4.3.1b

[LSTO.4.3.1b] cached() in a where clause is classified as sync_impure for let-binding purposes (multiple references within the same let body bind once at RHS start), but the restriction to let-RHS only does not apply. Pattern matching happens before any RHS executes, so the cache value is guaranteed stable during the entire where-clause evaluation.

[LSTO.4.3.2] The engine holds the cache in both shapes; they differ only in whether the integration persists it, declared via dialect (see [LSTO.4.3.4]):

Volatile. No persistence hook. The engine's in-memory cache answers every read (sub-microsecond) and cold-starts empty on every process restart. This is the default shape.

Persisted (write-through). The integration wires an optional write-through hook: after each cache / cache_delete mutates the engine's cache, the write propagates to an external store, and a startup hydrate re-seeds the engine's cache from that store. Reads still come from the engine's in-memory cache (sync); the external store is the durability backing, never the read path.

ratified — see also: LSTO.4.3.4

[LSTO.4.3.3] There is no cache-read (cached) callback. The engine serves cached() from its own in-engine map ([LSTO.4.7.1]); no integration code runs to serve a read. A read that meets an expired entry removes it, and that removal fires the integrator's removal callback ([NSTG.2.4.2]). A read cannot fail for want of a registered callback — a miss reads as null ([LSTO.4.3.1a]).

see also: NSTG.2.4.2, LSTO.4.3.1a, LSTO.4.7.1

Integration cache-type declaration [LSTO.4.3.4]#

[LSTO.4.3.4.1] The integration declares whether it persists the engine's cache, so the runtime honours startup hydration and emits accurate observability signals. The declaration is a dialect-level flag:

Dialect flag

Meaning

cache_in_process

Volatile — the engine's cache is not persisted; cold-starts empty on restart

cache_write_through

Persisted — the integration wires the outbound write-through + startup-hydrate hooks

Deferred: not binding in this edition.

[LSTO.4.3.4.2] An integration that declares cache_write_through is responsible for:

  • Persisting every cache and cache_delete to the external store through the outbound write-through hook (the engine has already mutated its own cache; the hook carries the write onward).

  • Hydrating the engine's cache from the external store on engine startup.

  • Never writing back into the engine's cache out-of-band: the external store is a durability backing, not a second writer ([LSTO.4.7.2]).

see also: LSTO.4.7.2

[LSTO.4.3.4.3] The runtime does not enforce or verify persistence. The declaration is informational — it enables the runtime to surface the right metrics (cache_type="write_through" label) and to trigger startup hydration when configured. A write-through hook that drops or reorders writes is a silent durability bug in the integration: the engine's own cache stays correct in-session, but cross-restart recovery is only as good as the hook.

Delete [LSTO.4.4]#

[LSTO.4.4.1] cache_delete key: <key> invalidates the key.

Loss [LSTO.4.5]#

[LSTO.4.5.1] In-session must-not-lose — an engine guarantee. The cache is engine state ([LSTO.4.7.1]), as durable as working memory within a session: a written key stays readable (subject to TTL, [LSTO.4.6]) until cache_delete or a superseding write. A cache write does not silently drop.

see also: LSTO.4.6, LSTO.4.7.1

[LSTO.4.5.2] Cross-restart durability — an integration hook, opt-in. The engine's cache is in-memory, so a restart cold-starts it empty. Surviving a restart is the cache_write_through shape ([LSTO.4.3.2]): the integration persists writes and hydrates the cache on startup. Under the default volatile shape the cache does not survive a restart, and rules must not assume a pre-restart key is present (a miss reads as null, [LSTO.4.3.1a]).

see also: LSTO.4.3.1a, LSTO.4.3.2

TTL [LSTO.4.6]#

[LSTO.4.6.1] Optional per-write via ttl: <dur> on cache; expired keys read as not-found. No TTL means durable until explicit cache_delete. Nothing evicts it.

The compiler must refuse a ttl: expression whose type is not Duration with DS_VALIDATE_TYPE_MISMATCH, as it refuses a retain: expression ([LDTL.4.1]), and an un-narrowed Duration? expression with DS_VALIDATE_NULLABLE_UNNARROWED ([LNUL.5.1]). A TTL of zero is no TTL, and the entry does not expire. That includes a Duration expression that saturates to zero ([LTIM.1.3.1]).

That a key with no TTL stays is worth an author's attention because the opposite would be easy to assume. A cache under a memory cap does not make room by discarding an entry: a write that would breach the cap fails, and everything already cached stays ([RTCT.7.1]). So a key with no TTL is durable in guarantee and not merely in intent, and a rule may rely on reading back what it cached.

The cost lands on the writer instead. Under pressure it is the cache action that fails, not a silent loss the reader discovers later — which is the trade DS wants, since a rule whose behaviour depended on how full the cache was would not be reproducible ([LDET.2.1]).


ratified — see also: LDET.2.1, LDTL.4.1, LNUL.5.1, LTIM.1.3.1, RTCT.7.1

Synchronous versus asynchronous [LSTO.5]#

[LSTO.5.1] cached() is the only storage read in this edition, and it is synchronous.

Operation

Sync?

Why

cached("k")

always sync

cache = fast local read; async would eliminate the point

cache

sync

an engine-local write ([LSTO.4.7.1]); only the write-through is out of band

cache_delete

sync

same

see also: LSTO.4.7.1

[LSTO.5.2] The sync read is what makes current-state reads tractable inside a single rule activation. A rule that needs "is the system armed?" answers with let armed = cached("armed-state") — one expression, no sibling rule, no response-fact pattern.

[LSTO.5.3] Implementation constraint. Because cached() is always sync, the read path must never leave the engine: the engine serves it from its own in-engine cache ([LSTO.4.7.1]), so no read blocks the rule-firing loop. Durability is the integration's, via the optional write-through shape ([LSTO.4.3.2]); a rule that needs a remote store queried on demand uses call storage.* instead.


see also: LSTO.4.3.2, LSTO.4.7.1

Loss semantics as author contract [LSTO.6]#

[LSTO.6.1] Each plane's loss policy shapes how authors should reason about it:

  • [LSTO.6.2] The cache is must-not-lose in-session. Rules can assume that cached("key") finds a key written earlier in the same session (subject to TTL). Across a restart the cache is durable only under the cache_write_through shape ([LSTO.4.5.2]); under the default volatile shape it cold-starts empty.

see also: LSTO.4.5.2

  • [LSTO.6.3] Samples are drop-oldest. Rules reasoning over long sample windows must tolerate missing datapoints. Aggregations handle this by operating on whatever arrived; authors who need exactness store facts ([LSTO.3.5.1]).

Deferred: not binding in this edition.

see also: LSTO.3.5.1

[LSTO.6.4] These are the author-facing guarantees. Runtime implementations must preserve them but may achieve them through different mechanisms (durable logs, replication, snapshot-persisted in-memory state) — implementation detail, not author contract.


How the planes compose [LSTO.7]#

[LSTO.7.1] Rule-author idioms that mix planes. None require implementation-specific knowledge; they're composition patterns over the primitives above.

Cache-memoised sample aggregations [LSTO.7.2]#

Deferred: not binding in this edition.

[LSTO.7.2.1] Expensive sample aggregations can be result-cached when authors want sync-read access: a rule hydrates the samples ([LSTO.3.4.1]), a rule aggregating them stores the result in the cache ([LSTO.4.2.1]), and later rules read it back synchronously via cached() ([LSTO.4.3.1]).

see also: LSTO.3.4.1, LSTO.4.2.1, LSTO.4.3.1

[LSTO.7.2.2] Samples are ground truth; cache is the sync-readable memoisation. The engine does not auto-cache aggregations over hydrated samples — authors decide what to memoise and when.

Event-driven cache updates [LSTO.7.3]#

[LSTO.7.3.1] Rules processing discrete events write the derived current state into cache ([LSTO.4.2.1]), so a later rule can read the latest state synchronously via cached() ([LSTO.4.3.1]) without re-deriving it from the event stream.

see also: LSTO.4.2.1, LSTO.4.3.1

[LSTO.7.3.2] Any subsequent rule reads via let s = cached("armed-state") synchronously. History lives in the facts plane; current value lives in cache.

Samples promoted to stored facts [LSTO.7.4]#

Deferred: not binding in this edition.

[LSTO.7.4.1] Anomalous samples detected by rules become stored facts — dense stream in, sparse-and-significant out: a rule matching a series aggregation crossing a threshold emits a fact, and a rule matching that fact stores it ([LSTO.2.2.1]), converting a continuous sample stream into a sparse record.

see also: LSTO.2.2.1

Warming cache from samples on startup [LSTO.7.5]#

Deferred: not binding in this edition.

[LSTO.7.5.1] Warmup queries may run at engine start, seeding cache from recent samples. Warmup is integrator configuration, not language surface. The author-visible contract is the one an author must write against: cache may hold values derived from samples at boot.


Interactions with other language features [LSTO.8]#

Series [LSTO.8.1]#

[LSTO.8.1.1] Series aggregations (mean(s), p95(s), etc. — see [LSER]) operate over the live backing structures in working memory, not the samples plane. The samples plane is the durable write-through; aggregations stay in-memory for bounded cost and predictable latency. Backing-structure choice is compiler-driven from the observation triples per [LSER.18.1]; the samples plane is independent of that choice.

see also: LSER.18.1

[LSTO.8.1.2] Authors who need to aggregate over historical samples beyond the live series window hydrate them ([LSTO.3.4.1]) and aggregate the HydratedSample facts in working memory.

Deferred: not binding in this edition.

see also: LSTO.3.4.1

Hydration [LSTO.8.2]#

Deferred: not binding in this edition.

[LSTO.8.2.1] Hydration ([LHYD.1]) brings historical facts from the facts plane back into working memory. Of the storage planes it reads the facts plane only — the samples plane is sample-shaped, not fact-shaped, and doesn't participate in hydration. Series aggregations over hydrated facts follow the rules in [LSER] / [LLOG].

see also: LHYD.1

Logical facts [LSTO.8.3]#

Deferred: not binding in this edition.

[LSTO.8.3.1] Logical facts (see [LLOG]) live in working memory — orthogonal to persistence. Authors who want durable records of derived state store the derived fact ([LSTO.2.2.1]).

see also: LSTO.2.2.1

Call / response [LSTO.8.4]#

Deferred: not binding in this edition.

[LSTO.8.4.1] All async storage reads (call storage.*) use the call / response correlation model (CALL_RESPONSE, pending port). Cache is the exception in language semantics — cached("key") is sync-intent and the read sits inside a let rather than going through a response-fact pattern. A sync-intent read completes in-rule: the engine answers it from its in-memory cache per [LSTO.4.3.2] at RHS entry.


see also: LSTO.4.3.2

Storage commitments [LSTO.9]#

  • [LSTO.9.1] Three planes, not two. Facts + samples + cache ([LSTO.1.1]). Cache carries a sync-read affordance the other two do not, and it is load-bearing for current-state reads inside a single rule.

see also: LSTO.1.1

  • [LSTO.9.2] persist: on series is the sole author-facing samples-write knob. Not a separate samples-write action; not adapter-side configuration. Author declares the series with the retention they want; persistence follows.

Deferred: not binding in this edition.

  • [LSTO.9.3] Raw samples only. The samples plane stores raw values; pre-computed stats are derivable via aggregation queries, not stored as denormalised stat tables.

Deferred: not binding in this edition.

  • [LSTO.9.4] sampled slot marker on schema fields marks a slot as participating in the samples plane. Inline on the schema declaration; cleaner than a separate block.

Deferred: not binding in this edition.

  • [LSTO.9.5] Cache values are opaque. Engine does not inspect, version, or react to cache change. Cache is sideband state; facts remain the reactive primitive.

  • [LSTO.9.6] TTL optional on cache. ttl: <dur> kwarg allowed; without it, the key is durable until cache_delete — nothing evicts it under memory pressure, because a write past a cap fails instead ([LSTO.4.6.1]).

see also: LSTO.4.6.1

  • [LSTO.9.7] Sync intent at cached() only. Every other storage operation is async (fire-and-forget for writes, via call/response for reads). Deliberate — collapsing the sync-intent affordance would require every rule needing current-state access to route through call/response.

  • [LSTO.9.8] Drop-oldest is engine-enforced via metric+log on cb failure. Sample-emission cb returning a non-OK status (or being NULL) drops the sample, emits the ds.samples.dropped_total counter, and proceeds — rules see DS_OK regardless. Author-facing drop-oldest semantics are preserved; operator-facing observability comes from the metric. Integrator wiring at [NSTG.5.6].

Deferred: not binding in this edition.

see also: NSTG.5.6

The storage library [LSTO.13]#

Deferred: not binding in this edition.

[LSTO.13.1] The storage library's services. The storage library is the .ds library the reference compiler ships for the storage adapter ([LIMP.3.3.1]). It declares these services, as any adapter library does ([LGRA.23.1]), and no others:

Service

Declared kwargs

Response

record_fact

fact: Schema required ([LADP.8.6.1])

no response

hydrate_facts

schema: String literal required, window: Duration required, limit: Int

response HydrationComplete ([LHYD.5.1])

hydrate_samples

entity: String required, field: String required, window: Duration required, limit: Int

response HydrationComplete

retain:, as and cooldown: on a hydration call are the call site's, not declared kwargs ([LCRS.14.13]). Neither hydration service declares filter_fields, so neither takes filter: ([LHYD.8.1]).

hydrate_facts serves whichever stored schema a call names, so it declares no hydrates: list; in place of [LHYD.9.4.3] the compiler must check that its schema: names a schema in scope, and that schema is a hydration target ([LHYD.4.1.7]).

see also: LADP.8.6.1, LCRS.14.13, LGRA.23.1, LHYD.4.1.7, LHYD.5.1, LHYD.8.1, LHYD.9.4.3, LIMP.3.3.1