Call continuation clauses#
The on / timeout / error continuation clauses on the call action. Continuations let one
rule express a call together with the rules that match its
response fact and CallError. The compiler lowers each
continuation to a sibling rule against the underlying primitive
in [LCRS]; the surface is sugar,
the semantics are inherited.
Paired with:
[LCRS] for the call/response primitive, the response fact and the
CallErrorschema.[LGRA] for action grammar.
[LECC] for the standard hierarchy
error <pattern>:matches against.
What this is not#
Not a replacement for the two-sibling form. The two-sibling form remains legal and is required for cases continuations do not compose (§13).
Not a chained-async rewrite. Chains deeper than two calls use the explicit two-sibling form.
Not a runtime-implementation spec. The runtime side — capture-fact lifecycle and the lowering pipeline — is [RLOW].
Scope [LCCO.1]#
[LCCO.1.1] A continuation is an optional trailing clause on a
call action. Each continuation lowers to one sibling rule that
matches the original call's response fact ([LCRS.4.3.1]) or
CallError, joined by correlation.
see also: LCRS.4.3.1
[LCCO.1.2] Three continuation shapes exist: on, timeout, and
error. Each is independently optional; a call may carry zero
or more of each shape.
ratified
[LCCO.1.3] The two-sibling form (a call rule plus separate
matcher rules) per [LCRS.2.1] remains legal. Continuations are
sugar; the compiler must accept rules written in either form, and
must accept rules that mix forms within one file.
ratified — see also: LCRS.2.1
[LCCO.1.4] Continuation semantics are defined by the lowering in §3. The compiler's behaviour on a rule with continuations must be indistinguishable from its behaviour on the lowered two-sibling form, modulo synthetic rule names per §4.
Surface [LCCO.2]#
[LCCO.2.1] [LGRA.10.1]'s call_action takes optional continuations, each a
line of its block ([LGRA.10.8]):
<continuation> ::= "on" <constraint_expr> ":" <action_list>
| "timeout" <duration> ":" <action_list>
| "error" <code_pattern>? ":" <action_list>
<code_pattern> ::= <ident> ( "." <ident> )*
ratified — see also: LGRA.10.1, LGRA.10.8
[LCCO.2.2] An on clause introduces a predicate over the response
fact. A timeout clause names a duration; the clause is a case
label for the distinguished event "no response or error within
that duration." An error clause is a case label for "the call
returned a CallError," optionally narrowed by a hierarchical
code pattern per §8.
[LCCO.2.3] Clause ordering in source is presentational. The compiler must lower each clause independently; the runtime's all-match evaluation per [LCRS.6.5] applies. Continuations do not form a switch / case; multiple clauses whose events occur fire independently.
see also: LCRS.6.5
Lowering [LCCO.3]#
[LCCO.3.1] The compiler must rewrite a call with continuations
into one outer rule plus one synthetic sibling rule per
continuation clause, sharing one correlation string.
ratified
[LCCO.3.2] The outer rule retains the original LHS and the
original call action stripped of all continuation clauses. If
the author did not provide as "<corr>", the compiler must
generate a correlation string per §3.4 and attach it.
[LCCO.3.3] Each on <pred>: clause lowers to a synthetic rule
matching the called service's response schema ([LCRS.4.3.2]) on the call's
correlation, whose remaining where conjunct is the continuation predicate,
and whose RHS is the continuation's action list.
How the sibling learns the correlation depends on which kind it is. An
author-supplied as value is a constant the sibling matches directly —
r.corr == "<corr>" on the response fact r. A generated one is per
activation ([LCCO.3.4]) and therefore not a constant the sibling can carry:
the sibling joins the call's correlation fact ([LCCO.5.2]) and matches
r.corr == <that fact>.corr. The same applies to the error siblings
([LCCO.8]). A timeout sibling reads the correlation from its own timer, which
carries it whatever the kind ([LCCO.7.2]).
see also: LCCO.3.4, LCCO.5.2, LCCO.7.2, LCCO.8, LCRS.4.3.2
[LCCO.3.4] A generated correlation is per activation, not per call
site. Each firing of a call with no as, or whose as evaluates to ""
([LRST.1.2]), gets its own value ([LCRS.3.1]), of the form $<outer_rule_name>_c<N>_<u>, where <outer_rule_name>
is the name of the rule that issues the call, <N> is the source-order index of
the call action among the calls of that rule's own body, counting every call
whatever its as (zero for the first), and <u> is g<k>, the value the
firing takes from the engine's correlation counter ([LCCO.3.7]).
A call in an after body or a continuation body is issued by the synthesized
rule that runs that body ([RLOW.14.7]), not by the authored rule: its
<outer_rule_name> is that rule's name, $<rule>_after_<N> ([LTAC.8.1]) or
$<outer>_<kind>_<N> ([LCCO.4.1]), and its <N> counts the calls of that
body alone. So the first call in rule r's first after body is
$$r_after_0_c0_g<k>. The counter never repeats a value, so the correlation is unique
within the engine, and a replay takes values in the same order, so the same
recorded input yields the same correlation ([LDET.2.2]).
Any other as value overrides the generated form and passes through
unchanged.
A constant per call site cross-matches concurrent activations. Two
firings in flight at once share it, so one response satisfies both on
siblings, one activation's capture snapshot joins the other's response, and a
timeout sibling sees a sibling activation's answer and never fires. The
author wrote one call per activation and gets one reply per call.
ratified — checks: tla×3 idris — see also: LCCO.3.7, LCCO.4.1, LCRS.3.1, LDET.2.2, LRST.1.2, LTAC.8.1, RLOW.14.7
[LCCO.3.7] The correlation counter. Each engine holds one counter, which is
0 when the engine is created. Taking a value yields g<k>, with k the
counter's value in decimal, and advances the counter by one. The engine must
take values at these points only, and in this order:
When a rule fires, before any of its actions runs: one value for each
callin its RHS that has noasor a computedas([LRST.1.2]), in source order; then one for eachafterclause with noaswhose body reads a binding of the rule ([LTAC.3.5], [LTAC.3.6]), in source order.When a synthesized terminal fires — an
afterfollow-up or a continuation sibling ([RLOW.14.7]) — before any of its actions runs: one value for eachcallin its own body that has noasor a computedas, in source order. Acallwith a continuation in that body takes none: it carries a literalas, or the compiler refuses it ([LCCO.3.8]).
A value is taken whether or not it is used. A computed as that evaluates
to a non-empty key still takes one. A call that its cooldown gate holds back
([RLOW.4.6.6.1]), or that a NaN argument refuses ([RLOW.7.3.1]), still takes
one, because the value is taken before the gate decides and before the
arguments are evaluated.
The counter is engine state and is not recorded. A replay re-derives it, taking the same values in the same order from the same inputs ([LDET.2.2]).
ratified — see also: LCCO.3.8, LDET.2.2, LRST.1.2, LTAC.3.5, LTAC.3.6, RLOW.14.7, RLOW.4.6.6.1, RLOW.7.3.1
[LCCO.3.8] A continued call inside a synthesized body names its
correlation. A call that carries a continuation ([LCCO.2.1]) and is written
in the body of an after clause or of another call's continuation — a body a
synthesized terminal runs ([RLOW.14.7]) — must carry an as whose key is a
string literal. The compiler must refuse such a call with no as or with a
computed as, with DS_VALIDATE_NESTED_CONTINUED_CALL_AS.
Such a call takes no value from the correlation counter ([LCCO.3.7]). The same
call outside a synthesized body is unaffected: with no as or a computed as it
takes its value as [LCCO.3.7] item 1 says.
ratified — see also: LCCO.2.1, LCCO.3.7, RLOW.14.7
[LCCO.3.5] A call with no continuation clauses must lower
unchanged: no capture fact and no sibling rule. Its correlation is the one
every call carries ([LCRS.3.1]); continuations add none.
see also: LCRS.3.1
Synthetic rule names [LCCO.4]#
[LCCO.4.1] The compiler must name synthetic continuation rules
$<outer>_<kind>_<N>, where <kind> is response, timeout,
or error, and <N> is the source-order index among clauses of
that same kind within the outer rule. A synthetic name
([LLEX.10.6.1]) can't equal an author-written rule name.
ratified — see also: LLEX.10.6.1
[LCCO.4.2] The <kind> segment lets operators grep
__<outer>_timeout_ across logs to locate every timeout
continuation derived from a given outer rule without
cross-referencing source.
[LCCO.4.3] Source-order indexing is not stable across continuation insertion. An author inserting a new clause may shift the index of later clauses of the same kind. This is accepted; the cost is a one-time log-correlation annoyance after edits.
[LCCO.4.4] The operator log per [LDEB] surfaces synthetic rule names directly. Debug tooling may render the source location of the originating clause alongside the synthetic name.
Capture [LCCO.5]#
[LCCO.5.0] Capture facts are an engine-internal use of the
activation-scoped fact lifecycle defined at [LSCP.2.4]. The
runtime bookkeeping below is the same machinery scope activation uses for author-declared schemas; the difference is
that capture facts are engine-named ($CaptureBindings_…, a
synthetic name per [LLEX.10.6.1]) while the facts an author's
emit asserts are author-named.
see also: LLEX.10.6.1, LSCP.2.4
[LCCO.5.1] LHS bindings from the outer rule are in scope inside every continuation body. A continuation may reference any binding declared on the outer rule's LHS by name.
ratified
[LCCO.5.2] To make capture work across the outer rule's
firing-time and the continuation's matching-time, the compiler
must emit a synthetic capture fact alongside the lowered call:
$CaptureBindings_<outer>_c<N>
corr <corr>
<field>: <snapshot value> ...
The capture fact carries snapshot values of each LHS binding the
continuation bodies reference. Each on and error sibling must include this
fact in its LHS, joined on corr. A timeout sibling joins its timer instead,
which carries the correlation and the values its body reads ([LCCO.7.2]).
The fact is emitted for every call with continuations, even with nothing to
capture. A generated correlation is per activation ([LCCO.3.4]), and
so is an as whose value is computed from the firing — a binding, a slot read or
an interpolated string — so this fact is what carries the correlation from the
firing to the on and error siblings; a call whose continuation bodies reference no binding
emits it with the corr slot alone. Only a call whose as is a compile-time
constant, a plain literal or a const, may omit it when there is nothing to
capture, because the siblings then match that constant directly.
ratified — see also: LCCO.3.4, LCCO.7.2
[LCCO.5.3] The capture fact's lifetime must equal the maximum of
the ttl of each fact the call's continuations match — the service's
response schema ([LCRS.4.3.2]) and CallError ([LCRS.4.2.1]) — and the largest timeout
duration declared on the call. The compiler must compute this lifetime at
lowering time and assert it as the capture fact's TTL.
The largest timeout keeps the capture live until the call's last deadline, so
an answer that arrives before it can still join an on or error sibling
([LCCO.7.3]). No timeout sibling joins the capture ([LCCO.7.2]), so its
lifetime decides nothing about whether a timeout fires.
ratified — see also: LCCO.7.2, LCCO.7.3, LCRS.4.2.1, LCRS.4.3.2
[LCCO.5.4] Capture is snapshot-always. Continuation rules fire using the snapshot values regardless of whether the originating LHS facts remain in working memory at response time. An author who needs re-match-against-live-fact semantics must use the two-sibling form, where the matcher rule can include the live fact in its LHS directly.
ratified — checks: idris×3
[LCCO.5.5] The capture fact's slot names must mirror the
binding's dotted reference path. A reference t.entity_id in a
continuation body produces a t_entity_id slot on the capture
fact; nested paths flatten with _ separators.
[LCCO.5.6] If no continuation references any LHS binding, the
capture fact carries no snapshot slots. For a call whose correlation is
generated or computed, the compiler must still emit it, with the corr slot
alone, because it is what carries the correlation to the siblings; only for a
call whose as is a compile-time constant may the compiler omit it
([LCCO.5.2]).
ratified — see also: LCCO.5.2
on response clauses [LCCO.6]#
[LCCO.6.1] An on <constraint_expr>: clause fires when the call's
response fact ([LCRS.4.3.1]) arrives and its slots satisfy the constraint
expression.
ratified — see also: LCRS.4.3.1
[LCCO.6.2] The constraint expression has the same grammar and
typing rules as a where clause. response is a bound name
referring to the response fact, so response.<slot> reads a slot of the service's
response schema ([LCRS.5.5]). The clause's body sees the same fact under the same
name, as an error body sees error ([LCCO.8.4]).
Each name is bound in the body of the clause that matched it, and not in a
continuation of a call made inside that body ([LCCO.10.1]), which sees the rule's
LHS bindings ([LCCO.10.3]) and its own response or error. The compiler must
refuse a read of an enclosing clause's fact as an unknown binding
(DS_VALIDATE_UNKNOWN_BINDING).
ratified — see also: LCCO.10.1, LCCO.10.3, LCCO.8.4, LCRS.5.5
[LCCO.6.3] A response constraint must be type-checked against the service's response schema at compile time, as any slot access is ([LGRA.13.8]). A reference to a slot the schema does not declare is a compile error.
see also: LGRA.13.8
[LCCO.6.4] Multiple on clauses on the same call are
independent. Every on clause whose predicate matches the
arriving response fires its own action list.
timeout clauses [LCCO.7]#
[LCCO.7.1] A timeout <duration>: clause fires when no
response fact and no CallError for the call's correlation
arrives within the duration measured from the call's firing.
ratified
[LCCO.7.2] The compiler must lower each timeout clause to one synthetic
timer fact and one sibling rule, as [LTAC.3] lowers an after clause.
The outer rule's RHS asserts the timer fact after its immediate actions, with
fire_at: monotonic_ns() + <duration> ([LTIM.2.8.2]), corr the call's
correlation, and a snapshot of each outer binding the clause's body references.
The timer's schema is named $Timer_<outer>_timeout_<N>, with <N> as
[LCCO.4.1] counts it. It has [LTAC.3.2]'s two slots, then one slot per value the
body references, named as [LCCO.5.5] names a capture slot and holding the value
the call's capture fact holds for it ([LCCO.5.4]).
The sibling rule's LHS is that timer fact, the clock tick ([IRET.19.5]), and two
negated patterns constrained to corr equal to the timer's: one over the called
service's response schema ([LCRS.4.3.2]) and one over CallError. It joins no
capture fact: the body reads each outer binding from the timer's slot for it.
Its guard is monotonic_ns() >= fire_at. Its RHS is the clause's action list,
followed by the retraction of the timer and, on a call with one timeout clause,
of the call's capture fact on the timer's corr where the call has one
([LCCO.5.2], [LSCP.2.4.1]). Both response and error count as "the call
completed"; either suppresses the timeout.
A timer has no TTL ([LTAC.4.4]), so the sibling fires at the first pump at or
after fire_at, however late that pump comes and whatever the capture fact's
lifetime ([LCCO.5.3]).
ratified — see also: IRET.19.5, LCCO.4.1, LCCO.5.2, LCCO.5.3, LCCO.5.4, LCCO.5.5, LCRS.4.3.2, LSCP.2.4.1, LTAC.3, LTAC.3.2, LTAC.4.4, LTIM.2.8.2
[LCCO.7.3] Multiple timeout clauses on one call are independent. Each has
its own timer fact and sibling rule ([LCCO.7.2]) and fires at its own duration,
and a firing leaves the other clauses' timers in place. An author may declare
timeout 5_s: and timeout 30_s: on the same call to escalate.
When a call declares more than one timeout clause, a timeout firing must
not retract the call's capture fact ([LCCO.5.2]), so a late answer can still
join it. The capture ends by an on or error match ([LSCP.2.4.1]), by
supersedure ([LRST.4.1]) or at the end of its lifetime ([LCCO.5.3]). A later
clause's sibling reads its own timer and joins no capture ([LCCO.7.2]).
ratified — see also: LCCO.5.2, LCCO.5.3, LCCO.7.2, LRST.4.1, LSCP.2.4.1
[LCCO.7.4] A call with no timeout clause does not generate
a timeout rule. Absence of a timeout clause is the author's
explicit choice not to react to absence; the response fact's
lifetime per [LCRS.6] bounds how long a stale response
lingers in working memory, so no leaked-correlation concern
exists.
see also: LCRS.6
[LCCO.7.5] The compiler must not synthesise an implicit timeout default. An author who wants a timeout writes one.
ratified
[LCCO.7.6] An answer ends the call's timeouts. A response fact or
CallError on the call's correlation retracts every timer fact of that call,
whether or not an on or error clause matches it. No timeout body of the
call runs after the answer, including once the answer has expired or been
superseded.
The compiler must lower this to two synthetic rules per timeout clause,
$<outer>_timeout_<N>_answered and $<outer>_timeout_<N>_failed, with <N> as
[LCCO.4.1] counts it. Each joins the clause's timer fact on corr with the
service's response schema ([LCRS.4.3.2]) or with CallError respectively, and
its RHS is the retraction of the timer. Neither retracts the capture fact
([LCCO.5.2]): an on or error sibling of the same answer joins it.
ratified — see also: LCCO.4.1, LCCO.5.2, LCRS.4.3.2
error clauses [LCCO.8]#
[LCCO.8.1] An error [<code-pattern>]: clause fires when a
CallError arrives whose corr matches the call's correlation
and whose code matches the optional pattern per §8.3.
ratified
[LCCO.8.2] The clause lowers to a sibling rule whose LHS is
CallError error where error.corr == "<corr>" and <code-match-expr>,
where <code-match-expr> is the dot-prefix predicate built from
the declared pattern. A clause without a pattern produces a
sibling rule whose where carries the correlation test alone; it
matches every error for the call.
ratified
[LCCO.8.4] An error clause's body sees the matched
CallError bound as error, as an on body sees response ([LCCO.6.2]). No
other name is bound: the compiler must refuse a read of any other name for
it as an unknown binding. error is a reserved word ([LLEX.9.6]), so no binding
the author introduces can share the name.
ratified — see also: LCCO.6.2, LLEX.9.6
Hierarchical code matching [LCCO.8.3]#
[LCCO.8.3.2] A pattern <a>.<b>.<c> matches a code <x> iff the
pattern's segments are a prefix of the code's segments at segment
boundaries. request matches request.malformed and
request.unsupported. request.malformed matches only
request.malformed. request.malform does not match
request.malformed; matching is at segment boundaries, not
character prefix.
ratified — checks: alloy×3
[LCCO.8.3.3] An error: clause without a pattern matches every
error for the call's correlation, including codes whose top-level
segment is not in the standard hierarchy. The catch-all is
unconditional.
[LCCO.8.3.4] Multiple error clauses on one call are
independent. An error request: clause and an
error request.malformed: clause on the same call both fire
when request.malformed arrives;
all-match per [LCCO.2.3] applies.
see also: LCCO.2.3
One-step chaining [LCCO.10]#
[LCCO.10.1] A call action inside a continuation body may itself
carry continuation clauses. Such an inner call lowers as a
nested-but-flat structure: the inner call's continuation rules
are sibling rules sharing the inner call's correlation.
ratified
[LCCO.10.2] The compiler must reject a call with continuations
nested inside an inner continuation body. Chain depth is capped
at two outer/inner pairs; a third level is a compile error
naming the offending call.
ratified
[LCCO.10.3] At chain depth two, the inner call's continuations may reference outer LHS bindings, and each reads as the outer capture fact held it when the outer continuation fired ([LCCO.5.4]). The compiler must carry those values into the inner call's capture fact ([LCCO.5.2]), which the continuation that makes the inner call asserts, so the inner continuations join that one capture fact on the inner correlation.
ratified — see also: LCCO.5.2, LCCO.5.4
[LCCO.10.4] Chains deeper than two require the two-sibling form per [LCCO.1.3]. The compiler must not lower deep chains via implicit fan-out.
see also: LCCO.1.3
Compile-time validation [LCCO.11]#
[LCCO.11.1] The compiler must validate every continuation
predicate against the call target's response schema ([LCRS.5.5]). A reference
to a slot the schema does not declare is a compile error
(DS_VALIDATE_UNKNOWN_SLOT, [LGRA.13.8]).
ratified — see also: LCRS.5.5, LGRA.13.8
[LCCO.11.2] The compiler must reject continuation predicates
whose conjunctive constraints are provably unsatisfiable. Numeric
interval contradictions (x < 60 and x > 100) and enum-set
contradictions (x = "broken" against an enum
good | degraded | failed) are compile errors. Predicates that
can never match are dead code.
ratified
[LCCO.11.5] LHS bindings referenced in a continuation body must be declared on the outer rule's LHS. References to undeclared names produce a compile error.
ratified
Interactions [LCCO.12]#
Cooldown [LCCO.12.1]#
[LCCO.12.1.1] The cooldown: option per [LCRS.8] applies to the
outer call. Continuations do not have their own cooldown.
see also: LCRS.8
Correlation [LCCO.12.2]#
[LCCO.12.2.1] An author-supplied as "<name>" flows to all
continuations of that call. A compiler-generated correlation per
§3.4 is opaque to the author; an author who wants to match
responses from outside the continuation block must declare an
explicit as.
Response retain [LCCO.12.3]#
[LCCO.12.3.1] [LCRS.6.3] governs the response fact's lifetime, and [LCCO.5.3] the capture fact's. No per-continuation retain knob exists.
Multiple calls in one rule [LCCO.12.4]#
[LCCO.12.4.1] A rule's RHS may contain multiple call actions,
each with its own continuation block. The compiler must scope
continuation clauses to their immediately-preceding call. Each
call gets its own correlation per §3.4.
Hydration [LCCO.12.5]#
Deferred: not binding in this edition.
[LCCO.12.5.1] Continuation rules are ordinary sibling rules and may match hydrated facts per [LHYD] alongside the response. No syntactic surface for cross-fact joins inside the continuation exists; cross-fact joining at the continuation site uses the two-sibling form.
What does not compose [LCCO.13]#
[LCCO.13.1] Cross-call joins. A rule that matches multiple unrelated calls' responses simultaneously must use the two-sibling form. The continuation surface is per-call; it cannot express a join across distinct correlations.
[LCCO.13.2] Conditional request. A rule whose request is conditional on a prior response's contents must match that prior response in the request rule's LHS. Continuations carry no mechanism for the request to be conditional on earlier-call state.
[LCCO.13.3] Chains deeper than two. Per §10.4. Authors split into named rules.
[LCCO.13.4] In each of the cases above, authors mix continuation form and two-sibling form within one file freely. The compiler treats them as equivalent surfaces over the same primitive.