call and responses#
The async call / response primitive. A rule issues a call, the target adapter performs
whatever external operation it bridges, and the response
arrives as a fact of the service's declared response schema (or as a
CallError) that a sibling rule pattern-matches.
Paired with:
[LGRA.10] for the
callaction grammar and mandatory-cooldown rule.[LADP] for adapter- published service manifests and response schemas.
[LHYD] for the hydration-specific endpoint family built on this mechanism.
[LSTO] for the storage-adapter calls (
call record_fact,call hydrate_*).[LFAC] for the
ttllifecycle that response facts andCallErrorlive under.
What this is not#
Not a proposal for making all actions return values.
emit,publish,logandcachestay fire-and-forget, as does a call to ano responseservice.Not a generic RPC framework. The shape must fit DS's fact plane — responses are facts, not opaque return values.
Not sync bind-to-variable for external calls. That's rejected (see §Async only for external calls below). The sync-intent affordance stays on
cached()only — the cache read expression callable from aletRHS per LGRA.9.8.2.Not an implementation spec for the adapter wire protocol, dispatch-table construction, backpressure queuing, or adapter handshake format. Runtime concerns, out of scope. The runtime-side spec lives in [RLOW].
What call is for [LCRS.1]#
[LCRS.1.1] Things rules cannot do without call / response:
[LCRS.1.2] Consume data-returning HA services.
weather.get_forecasts,calendar.get_events,climate.get_hvac_modes, etc. A rule asks for the value at fire time.
[LCRS.1.3] React to clamped state.
light.turn_on brightness: 255may actually set 200 if the driver caps it. Rules wanting to log "asked for 255, got 200" need the response, not the cached state that eventually arrives via a separate state-changed event.
[LCRS.1.4] See failures. A failed service call is invisible to the rule that fired it. Response-as-fact makes the failure matchable by a sibling rule.
[LCRS.1.5] Chain decisions on fresh values. "Read current brightness → compute delta → set new value" is one rule.
[LCRS.1.6] Invoke external ML / MCP / HTTP adapters. Any adapter that issues a response becomes queryable from rules.
Async only for external calls [LCRS.2]#
[LCRS.2.1] The mechanism is strictly async: rule fires call, the RHS
completes without blocking, the response arrives on a later
cycle as a fact, and a sibling rule matches the response.
Correlation [LCRS.3]#
[LCRS.3.1] Every call carries a correlation. It is the value of the
call's as binding ([LRST.1.1]), or, for a call with no as or whose as
evaluates to "" ([LRST.1.2]), the value generated for each firing
([LCCO.3.4]). A correlation is a String,
never null and never empty, whatever the call's service. It threads through
to every answer the call receives: its response fact ([LCRS.4.3.1]) and its
CallError ([LCRS.3.2]).
ratified — checks: tla idris×2 — see also: LCCO.3.4, LCRS.3.2, LCRS.4.3.1, LRST.1.1, LRST.1.2
[LCRS.3.2] The adapter does not interpret the correlation; it just
stamps it onto the response fact ([LCRS.4.3.1]) or the CallError as its
corr slot.
see also: LCRS.4.3.1
[LCRS.3.3] Author responsibility for uniqueness. It's the author's job to pick correlation values that don't collide with live correlations from other rules that still have outstanding responses. The same rule reusing a value supersedes its earlier call ([LCRS.6.2.1]).
checks: tla — see also: LCRS.6.2.1
[LCRS.3.5] Correlation is not a timestamp and not global. It's meaningful only between the calling rule and the response-matching sibling rule(s). Two different call sites can reuse the same correlation value at different times with no interaction, provided their response facts don't overlap in the working memory.
Response and error fact schemas [LCRS.4]#
CallError [LCRS.4.2]#
[LCRS.4.2.1] The CallError schema is ttl-scoped at 5_min. The adapter
asserts it instead of the response fact ([LCRS.4.3.1]) when it could not
fulfil the request.
Slot |
Type |
Meaning |
|---|---|---|
|
String |
correlation from the call's |
|
String |
error kind ([LCRS.4.2.3]) |
|
String |
human-readable detail |
|
Time |
when the error was received ([LFAC.9.2]) |
ratified — checks: tla idris×7 — see also: LCRS.4.2.3, LCRS.4.3.1, LFAC.9.2
[LCRS.4.2.2] Exactly one of the response fact ([LCRS.4.3.1]) or a
CallError is asserted per call to a service declaring response T, a superseded
call aside ([LCRS.6.2.4]); a call to
a no response service produces at most a CallError ([LCRS.17.1]). Rules that
need both paths write two matcher rules.
checks: tla×6 idris×3 — see also: LCRS.6.2.4, LCRS.17.1, LCRS.4.3.1
[LCRS.4.2.3] code values are dotted lower-snake-case namespaces
matched hierarchically per [LCCO.8.3]. The standard families and
leaves adapters emit are normative in
[LECC]; this doc owns the fact schema,
that doc owns the code value space.
see also: LCCO.8.3
[LCRS.4.2.4] An adapter reports a failure of the system it fronts
under the adapter family ([LECC.2.2]).
see also: LECC.2.2
The response fact [LCRS.4.3]#
[LCRS.4.3.1] A response is a fact of the service's response schema. When a
call to a service declaring response T ([LADP.8.4.2]) succeeds, the adapter
must assert exactly one fact of schema T, with its corr slot set to the
call's correlation ([LCRS.3.1]). That fact is the call's response fact.
checks: idris — see also: LADP.8.4.2, LCRS.3.1
[LCRS.4.3.2] A response schema is ttl and declares corr. corr is a
slot name the language gives a meaning: the correlation of the call that
brought a fact into working memory. A schema need not declare it; a response
schema must. A schema named in a response_decl
([LGRA.23.1]) is a response schema, and must be ttl ([LFAC.1.3]) and
declare corr as a non-nullable String. The compiler must reject a response
schema that is not ttl (DS_VALIDATE_SERVICE_RESPONSE_NOT_TTL) and one
without such a slot (DS_VALIDATE_SERVICE_RESPONSE_NO_CORR). The compiler adds
no slot to a response schema.
Because a response schema is ttl, every response is its own fact: two calls
never share one, and corr is never an identity key ([LFAC.1.7.6]).
ratified — checks: tla idris×9 — see also: LFAC.1.3, LFAC.1.7.6, LGRA.23.1
[LCRS.4.3.3] CallResponse is a reserved name. No schema may be declared
with it, and a pattern or reference naming it is a compile error
(DS_VALIDATE_CALL_RESPONSE_RETIRED) whose message directs the author to the
response schema of the service called ([LCRS.4.3.2]).
ratified — see also: LCRS.4.3.2
[LCRS.4.3.4] A rule asserts no answer. A fact of a response schema
([LCRS.4.3.2]) and a CallError ([LCRS.4.2.1]) are a call's answer. The adapter
asserts them ([LCRS.4.3.1], [NCBK.6.4]), and a rule does not. The compiler must
reject an emit or a publish whose schema is CallError or is named in a
response_decl ([LGRA.23.1]) of the program, with
DS_VALIDATE_ANSWER_EMIT_FORBIDDEN. A response schema declared ambient is
refused as [LSCP.2.5.1] states, with that clause's code.
A rule may match an answer. A program that wants a rule to produce a fact of the same shape declares a schema of its own and matches both.
ratified — see also: LCRS.4.2.1, LCRS.4.3.1, LCRS.4.3.2, LGRA.23.1, LSCP.2.5.1, NCBK.6.4
Reading a response [LCRS.5]#
[LCRS.5.5] A rule reads a response as it reads any fact. It matches the
response schema ([LCRS.4.3.2]), constrained on corr to the call's
correlation, and reads that schema's slots; the compiler must check those reads
as it checks any slot access ([LGRA.13.8]). A slot of the response schema
declared Json is read as any Json slot is.
ratified — see also: LCRS.4.3.2, LGRA.13.8
Response fact lifetime [LCRS.6]#
[LCRS.6.1] Response facts ([LCRS.4.3.1]) and CallError facts live in
working memory once asserted. Two mechanisms govern their retraction:
superseding correlation ([LCRS.6.2]) and the schema's TTL ([LCRS.6.6]).
Per-call retain: is refused ([LCRS.6.3.3]).
checks: tla×7 — see also: LCRS.4.3.1, LCRS.6.2, LCRS.6.6, LCRS.6.3.3
1. Superseding correlation (default) [LCRS.6.2]#
checks: idris×8
[LCRS.6.2.1] When a rule fires call S ... as K, the engine must first
retract every live fact of S's response schema ([LCRS.4.3.2]) whose corr is
K and every live CallError whose corr is K, and only then issue the
request. A call to a no response service ([LCRS.17.1]) has no response schema
and retracts CallError facts alone. Responses of other services are
untouched, whichever rule or clause position issued the call. A call its
cooldown suppresses ([LCRS.8.1]) is not issued and retracts nothing. Every
call has a correlation ([LCRS.3.1]), so every issued call sweeps. Natural for
refresh-on-trigger rules — only the latest response for a given service and
correlation is live at any time.
ratified — checks: tla×6 idris×67 — see also: LCRS.17.1, LCRS.3.1, LCRS.4.3.2, LCRS.8.1
[LCRS.6.2.4] An arriving answer supersedes as the call does. A call that fires again before its earlier request is answered finds no live answer to retract ([LCRS.6.2.1]), and both replies arrive. So the engine must apply the supersede again when an answer is asserted ([NCBK.6.4]), before the answer itself:
A fact of a response schema
T([LCRS.4.3.2]) withcorrK: the engine retracts every live fact ofTwhosecorrisKand every liveCallErrorwhosecorrisK.A
CallErrorwithcorrK: the engine retracts every liveCallErrorwhosecorrisKand every live fact of every response schema whosecorrisK. ACallErrornames no service ([LCRS.4.2.1]), so its correlation spans services, as it does in [LCRS.6.2.1].
An answer whose corr is the empty String supersedes nothing. The
empty key is no key ([LRST.1.2]), and such an answer answers no call, since a
call's correlation is never empty ([LCRS.3.1]).
The retractions precede the answer in working memory. The stream records the
answer's FactAssert first and the withdrawals after it, as for any host
assert ([RFCS.6.7]).
A rule asserts no answer ([LCRS.4.3.4]), so this assert is how every answer
enters working memory. For each non-empty correlation, therefore, either one
CallError is live and no response fact is, or no CallError is live and at
most one fact of each response schema is. Each live answer is the last of its
kind asserted with that correlation. Replies of different services that share a
correlation are live together, as [LCRS.6.2.1] leaves them.
The engine does not know which request a reply answers ([NCBK.6.3]), so when replies arrive out of order the answer to the earlier request is the one that stays. An author who needs the newer request's answer carries an ordering value in the response and matches on it.
ratified — checks: tla×5 idris×22 — see also: LCRS.3.1, LCRS.4.2.1, LCRS.4.3.2, LCRS.4.3.4, LCRS.6.2.1, LRST.1.2, NCBK.6.3, NCBK.6.4, RFCS.6.7
[LCRS.6.2.2] Supersedure here is one consumer of the unified
as correlation surface; the broader semantics (per-fact
supersedure, capture-fact lifecycle under supersedure) are
normative in [LRST.2] and [LRST.4].
[LCRS.6.2.3] Positionally, as <expr> is the trailing clause of
every call action — it follows all kwarg / flag
action_args and precedes only the line terminator. A kwarg appearing
after as is a parse error. Multi-line author convention places
as "<corr>" on its own line at the bottom of the call block.
ratified
2. Per-call retain: — refused [LCRS.6.3]#
[LCRS.6.3.3] No call in this edition honours retain:: the hydration calls
that take it are deferred ([LHYD.6.2]). The validator must reject it on every
call with DS_VALIDATE_RETAIN_UNWIRED — a specific loud code rather than the
generic unknown-kwarg DS_VALIDATE_BAD_KWARG, and never a silent skip,
because retain is a reserved modifier name.
Response-fact lifetime is governed by superseding-call retraction ([LCRS.6.2]) and by the schema's TTL ([LCRS.6.6]).
3. The schema's TTL [LCRS.6.6]#
[LCRS.6.6.1] A response fact or CallError that no superseding call
retracts ([LCRS.6.2.1]) expires at its schema's TTL ([LFAC.1.3.3]): the
duration the response schema declares ([LCRS.4.3.2]), and 5_min for CallError
([LCRS.4.2.1]). The engine must apply no other lifetime to them; no site
setting shortens or extends it.
ratified — checks: tla×8 — see also: LCRS.6.2.1, LFAC.1.3.3, LCRS.4.3.2, LCRS.4.2.1
Multiple matchers [LCRS.6.5]#
[LCRS.6.5.1] Response facts are not single-use. Multiple rules may match the same response fact until it's superseded or retained-out. Any rule matching the corr sees the same slots.
Timeouts [LCRS.7]#
[LCRS.7.1] A call's timeout continuation ([LCCO.7]) fires when no answer
arrives. A rule outside the call reacts to absence with a negated pattern over
the response schema, bounded by within, constrained to the call's correlation.
see also: LCCO.7
[LCRS.7.2] More commonly the timeout rule carries no positive matcher for the response at all — the negated pattern alone, triggered by whatever the author wants to check it against.
[LCRS.7.3] The adapter is responsible for not sending a response after its own deadline; rules are responsible for writing an absence matcher if the absence matters.
[LCRS.7.4] If no timeout rule exists and the adapter never responds,
the correlation leaks in the sense that the call's side
effects (the cooldown window) persist normally, but no rule fires
because nothing matches. Adapters should publish
service-level deadlines (e.g., HA-bridge fails calls not
answered by HA in 10_s and emits CallError) so rules that
forget timeout matchers at least get a CallError.
Mandatory cooldown [LCRS.8]#
[LCRS.8.1] Every call action must state its rate expectations. The
compiler rejects any call that carries neither cooldown: <dur> nor the
nocooldown flag (DS_VALIDATE_CALL_RATE_MOD).
ratified — checks: tla
[LCRS.8.2] The engine suppresses a call carrying cooldown: <dur> when the
same call site has issued the call within <dur> for the same key: the values of
the declared key slots of each logical fact the activation binds, as
rule-level cooldown is keyed ([LCDB.3.3.1]). A ttl or event fact contributes
no slot ([LCDB.3.3.3]) and a call takes no by: ([LCRS.8.1]), so where the
activation binds no logical fact with a key slot the key is empty, and the
call site has one window across all its activations. An author who needs
a window per entity over such a fact writes a rule-level cooldown with by:
([LCDB.3.3.4]). Each call site has its own window,
so two calls in one rule cool independently, and a suppressed call does not stop
the rule's other actions. nocooldown issues the call every time the rule fires;
the adapter's own argument-dedup LRU still fires as a safety net.
ratified — checks: tla×9 idris×21 — see also: LCDB.3.3.1, LCDB.3.3.3, LCDB.3.3.4, LCRS.8.1
Batching [LCRS.9]#
[LCRS.9.1] Some services (notably HA ones like light.turn_on,
switch.turn_on, climate.set_temperature) accept bulk
entity_id arguments. A rule firing three light.turn_on calls for
three lights ships one batched call rather than three.
[LCRS.9.2] Adapter-opportunistic coalescing. Authors write per-call
actions; the adapter opportunistically batches on the
outbound path. No grammar for batch; the author-visible
contract is that each call produces its own
response fact ([LCRS.4.3.1]) or CallError.
see also: LCRS.4.3.1
[LCRS.9.3] The adapter may coalesce into one outbound call if and only if:
[LCRS.9.4] Same service.
[LCRS.9.5] All non-target args identical (brightness, colour, transition, etc.).
[LCRS.9.6] A coalescing time-window is satisfied (site config, typically ≤ 10_ms).
[LCRS.9.7] The response paths remain individuated:
[LCRS.9.8] Batch succeeds → adapter asserts three response facts, one per correlation.
[LCRS.9.9] Batch fails → adapter emits three
CallErrorfacts, samecodeandmessageper fact, one per correlation.
[LCRS.9.10] Rules match on their own correlation; coalescing is invisible to author code.
[LCRS.9.11] Atomic batch is out of scope. "Turn all three on in the
same instant or none" is an atomicity guarantee the rule
language does not provide. An author needing it makes the
batch the integrator's unit of work and fires it with a
single call, so the atomicity is the adapter's to keep.
Dispatch resolution [LCRS.10]#
[LCRS.10.1] Every adapter that accepts call requests declares its
service surface in its .ds library file. The compiler
resolves call references against those declarations and
carries the service set in the .dsc; the adapter's binary
registers a callback per service at engine init. Nothing is
announced at connect time ([RARC.9.4.2]).
see also: RARC.9.4.2
[LCRS.10.2] A call ([LGRA.10.1]) has one author-facing form: the bare
service name <domain>.<method>, which the compiler resolves against every
service in the import closure ([LGRA.10.1.6]). No form names the adapter.
see also: LGRA.10.1, LGRA.10.1.6
Compile-time resolution rules [LCRS.10.4]#
[LCRS.10.4.1] Unique match. Exactly one declaration in the compilation's import closure offers the service, and the call resolves to it ([LADP.8.2.2]).
see also: LADP.8.2.2
[LCRS.10.4.2] No match. No adapter offers the service. Compile error: "unknown service
light.turn_on; known: [list]" (DS_VALIDATE_UNKNOWN_SERVICE).
ratified
[LCRS.10.4.4] A call's whole dotted name is the service's name, resolved against the one global service namespace ([LGRA.10.1.6]), whichever libraries the file imports.
ratified — see also: LGRA.10.1.6
A call target is never ambiguous [LCRS.10.5]#
[LCRS.10.5.2] A service name names one declaration in a compilation ([LCRS.14.9]), so the dotted name a call carries reaches exactly one service. No call needs qualifying to be routed.
see also: LCRS.14.9
Adapter unreachable [LCRS.10.6]#
[LCRS.10.6.1] The engine has no concept of a disconnected adapter
([NADP.5.1.1]). If a rule fires a call whose adapter cannot
reach whatever it fronts, the callback returns CallError
with an adapter.* code whose leaf the adapter chooses ([LECC.4.3]) — DS
ships no adapters and specifies no leaf for this. Rules that want to
react match on that code; rules that don't get the standard
timeout idiom.
see also: LECC.4.3, NADP.5.1.1
Tier scope and dialects [LCRS.11]#
[LCRS.11.1] call availability is dialect-gated. The reference
runtime's specific topology and which tiers enable call
lives in [RARC].
[LCRS.11.2] The language-level contract: any dialect can enable or
disable the call form (see
[LFCA]). Tiers that run
under frame-rate clocks, or whose rules can't absorb
response latency by design, run dialects that disable
call. Those rules reach external state via
cached(...) reads (the let-RHS expression form per
LGRA.9.8.2) against values a higher tier has written
through.
see also: LGRA.9.8.2
Interactions [LCRS.12]#
With logical emit [LCRS.12.1]#
[LCRS.12.1.1] logical emits that match a response fact ([LCRS.4.3.1])
inherit the response's ttl lifetime. A logical fact justified by a
response fact retracts when the response fact retracts, by supersedure or at
its schema's TTL ([LCRS.6.1]).
see also: LCRS.4.3.1, LCRS.6.1
With hydration [LCRS.12.2]#
Deferred: not binding in this edition.
[LCRS.12.2.1] Hydration endpoints (hydrate_facts,
hydrate_samples, and any other adapter's
hydrate_*) use the same call / response model —
the hydration-specific extensions (retain:, limit:,
filter: kwargs; the HydrationComplete signal fact) are
spec'd in [LHYD.6].
see also: LHYD.6
With the cache plane [LCRS.12.3]#
[LCRS.12.3.1] Orthogonal. cache / cached(...) /
cache_delete are the sync-intent key-value surface; call /
response is the async typed-call surface. Rules commonly\nbridge the two.
With series [LCRS.12.4]#
[LCRS.12.4.1] Orthogonal. Series operate on live facts in working memory; call / response facts are working-memory facts too, so a series can in principle be declared over response-slot values — but this is rare and not the intended use of series. See [LSER].
With storage [LCRS.12.5]#
[LCRS.12.5.1] Author-controlled auditing. A rule that wants a completed call stored writes a sibling rule that matches the response fact and calls the storage service.
[LCRS.12.5.2] The mechanism does not implicitly audit every call — that would force one event shape and record-every-lookup, which is the wrong default.
Calls to a no response service [LCRS.17]#
[LCRS.17.1] Success is silence. A call to a service that declares
no response ([LADP.8.4.2]) asserts nothing when it succeeds: no
response fact exists for it, so none is retained ([LCRS.6.6.1]). When it
fails, the adapter asserts a CallError ([LCRS.4.2.1]) as for any call. An
adapter that learns of the failure only after the call has returned asserts the
CallError then.
Silence is never mistaken for a timeout: the engine tracks no pending call ([LCRS.10.6.1]), and a timeout is a continuation or an absence pattern the author writes ([LCRS.7.1]).
checks: tla×3 idris×4 — see also: LADP.8.4.2, LCRS.10.6.1, LCRS.4.2.1, LCRS.6.6.1, LCRS.7.1
[LCRS.17.2] as binds; nothing continues. A call to a no response
service may bind as ([LCRS.3.1]), so that its CallError carries the
correlation. It may not open a response continuation ([LCCO.2]): nothing comes
back to continue on. The compiler must reject one
(DS_VALIDATE_NO_RESPONSE_CONTINUATION).
Nor may it open a timeout continuation. With nothing ever coming back, the
timeout would fire on every call that does not fail; an error continuation
already covers failure, and after covers a delay. The compiler must reject
one (DS_VALIDATE_NO_RESPONSE_TIMEOUT).