ADL 0.6.0 reference · Review draft 1 · November 14, 2026.
Contents · Source map · Evidence
The 0.6 edition note
A transition has several independent conditions: a source-state edge, ordinary transition authorization, role guards, expression guards, required fields, and any applicable policy. Passing one condition is not evidence that the others pass.
The calibration document grants submit, approve, and reject under permissions.transitions. Without an explicit transition grant, the runtime may inherit update authorization; naming a role in guards is not a substitute for that grant. Its approval guard reads the stored submitter, while protected fields prevent a caller from replacing that provenance through an ordinary write or transition body.
Immutable fields need an equally precise reading. In the handbook’s recorded transition case, a supplied replacement measurement was omitted while the transition succeeded. A successful HTTP response did not mean that every supplied field was written. Test resulting stored values as well as the response status.
The fresh Journey compilation check establishes static feasibility for the declared inspector and input state. The referenced HTTP evidence still shows self-review and missing training being refused. This is the boundary between the compiler’s model and live request checks. Declarative separation-of-duties shorthand from the Aegis design is not introduced here without an admitted grammar and an owning rule.
Retained reference detail
The numbered sections below are carried from 22-state-machines.md. Their original baseline and evidence remain attached to the source. Statements about “current” or “checked” behavior in this retained text refer to those original observations unless the edition note explicitly updates them. This is a consolidated draft, not a claim of complete re-verification.
22.1 Scope of this chapter
A state machine binds one resource field to a lifecycle: its initial value, recognized states, named transitions, conditions for moving, and effects of a successful move. An enumeration constrains the allowed values; a machine additionally constrains movement between values. ADL 11 owns enumerations. A resource can use a machine without declaring an enum on its controlled field, as the examples here do.
This chapter develops the
converted ADL 22 (v0.5.0, retired)
under Draft 05 §§8.4–8.5
and the signed rulings. Observed behavior refers to
revision 6e2a7790 and a fresh Release build of that checkout. Its parser,
executor, generated actions, local bus, and SQLite stores supply the
verification evidence. Observations
identify implementation gaps; they do not amend the language.
The inherited contract says named transitions and direct state writes enforce
the same rules. A PATCH that moves the state field runs the matching
transition: its guards, requiredFields, sets, transition-scoped rules, and
its name in history and state events (#1408). PUT now runs the same transition
work while retaining replacement defaults and NULLs (#1445). The
operation matrix in §22.6 makes the remaining boundaries explicit. A declared
machine is therefore not proof that every write path enforces its lifecycle.
ADL 21 owns authorization, including transition permissions; ADL 18 owns AEL. ADL 13 owns trait composition before the surviving machine executes. Hierarchical and parallel machines remain deferred by Draft 05 §22; nested states are not an alternative 0.5.1 machine grammar.
22.2 Declaration
Place stateMachine beside object in a resource. The complete
workflow.yaml defines an Order
with a string primary key, title, controlled status, ownership, approval fields,
and a five-state machine. This field fragment shows its central declarations:
object:
id: {type: string, primaryKey: true}
title: {type: string, required: true}
status: {type: string}
createdById: {type: string}
ready: {type: string}
resolution: {type: string}
approvedBy: {type: string}
approvedAt: {type: datetime}
copied: {type: string}
cleared: {type: string}
The following machine fragment shows the approval path. The complete file also has cancellation, rejection, parking, and a self-transition for comparison.
stateMachine:
field: status
initial: draft
states:
draft:
transitions:
submit: {to: review, guards: [authenticated]}
review:
metadata:
description: Awaiting a decision
onExit: [chapter22.exit]
transitions:
approve:
to: approved
guards: [admin, reviewer, 'hasField:resolution']
guard: "$record.ready == 'yes'"
requiredFields: [resolution]
sets:
approvedAt: now()
approvedBy: $user.id
copied: $record.resolution
cleared: null
approved:
final: true
onEnter: [chapter22.enter]
| Construct | Meaning and authoring form |
|---|---|
field | Name of the existing field controlled by this machine |
initial | Name of the initial state |
startStates | Further states a beforeCreate hook may start a record in (§22.2.1, #1540); optional |
states | Mapping of state name to state body |
transitions | Mapping inside a state; transition names are local to the source state |
to | Target state name in the same machine |
final: true | Refuse outgoing movement from that state |
metadata.description | Human-readable state description |
metadata.timeout | String metadata retained in the model; no timer behavior established here |
onEnter, onExit | Arrays of callback action names carried in state-event payloads (§22.5) |
The shorthand cancel: cancelled means a transition with to: cancelled and no
additional guard or effect declarations. A repeated transition name in several
states registers one route; the current record determines which source-state
definition applies. This is useful for the fixture’s cancel transition from
both draft and review.
22.2.1 Initial state and declaration checks
For ordinary create requests, the initial state overrides a client-supplied
state. The checked http and internal requests ask to create an approved order
but store draft. The trusted seeder label preserves the supplied approved
value. These are synthetic kernel transport labels; a client cannot acquire
that trust merely by placing transport in an HTTP request body.
A record does not always begin in the same place: a booking that needs no
confirmation starts accepted, a comment from a trusted author starts
approved. startStates lists the states, besides initial, that a create
may start in (#1540):
stateMachine:
field: status
initial: pending
startStates: [accepted]
Only a beforeCreate hook chooses, by returning the state field
(ADL 25 §25.4.2); the client’s value is still overwritten. A hook that returns
initial or a listed state starts the record there. One that returns any other
state is refused with 422 INVALID_START_STATE, and nothing is written.
Without startStates, a hook’s returned state is overwritten by initial as
before. Every name in the list must be a state of the machine, or the domain is
refused at submit.
Creation publishes the enter callbacks of the state the record actually
starts in, with transition (initial). That holds for a seeder-supplied state
too: a seeded approved order publishes approved.enter, not draft.enter.
The callback’s record contains the stored value (§22.5).
The parser rejects a nonempty field name that does not exist, a nonempty initial name outside the state set, and an explicit target outside the state set. Its validation is incomplete:
| Checked declaration | Current native result |
|---|---|
Omitted field or initial | Admitted with an empty value |
Empty stateMachine: {} | Admitted as an empty machine |
Transition without to | Admitted; that transition disappears from the model |
Scalar guards: admin | Admitted; no guard array retained |
Boolean guard: false | Admitted; no AEL guard retained |
final: true with a declared outgoing transition | Admitted; executor still refuses movement from the final state |
State-level description outside metadata | Ignored by the state-description reader |
Author the required names and correct collection shapes explicitly. Successful parsing alone does not prove that a requested condition or transition survived. The parser and typed machine model are the current implementation references.
A native lint warning identifies a noninitial state that is never a transition target. This is weaker than graph reachability: the checked isolated two-state cycle receives no warning because both states are targets. It does not follow that either state is reachable from the initial state.
22.3 Guards
A transition can declare a guards array, a scalar AEL guard, or both.
The array runs first; the expression must then pass as well. Neither form
replaces the operation’s applicable permission checks.
22.3.1 Role and presence guards
| Array entry | Current check |
|---|---|
authenticated | Nonempty caller user ID |
admin | Matches primary role or an entry in the caller’s roles vector (admin or administrator) |
owner | Caller ID equals the record value in the resolved owner field |
| Another role name | Matches primary role or an entry in the caller’s roles vector |
hasField:name | Value appears present on the existing record or in the request body |
Role entries are OR conditions: one matching role is sufficient. Presence entries are AND conditions: every listed field must pass. An array containing only presence guards has no role requirement. An empty array imposes neither.
The explicit permissions.ownerField in the fixture resolves ownership to
createdById. Owner guards use that resolved field and compare IDs, not
usernames; an empty resolved field never matches. Indirect owner hydration and
permission resolution remain ADL 21 §21.4
concerns. This chapter’s identity tests cover a local owner field.
Presence checks have two important limits. An existing nonempty value satisfies
hasField even if the body replaces it with null. Also, the current checker
rejects the text null but treats the store’s internal SQL-NULL sentinel as
present. Thus hasField alone is not a reliable post-update non-null constraint.
Zero in a submitted numeric field counts as present. These observations come
from the current machine executor,
with both direct checker cases and stored-record controls.
22.3.2 AEL guard context
Write the expression as a string, for example:
guard: "$record.ready == 'yes'"
The executor binds the existing record as $record and $this, binds the
caller as $user (and, equivalently, user) with id, username, role,
roles and claims (#1560), and evaluates in Guard scope. With the host setting
adl.claims.unknown: deny, a guard that names user.claims.<name> for a claim
the request lacks is not evaluated and the transition is refused with
403 GUARD_FAILED (ADL 21). Before ADL 0.102.75 only user was
bound, so $user.id evaluated to null and a separation-of-duties guard such as
"$user.id != $record.enteredById" passed for the record’s author (#1468). It does not merge request-body
changes into that record before evaluation. A guard requiring resolution new
therefore fails when the old value is old, even if the transition body submits
new. Set preconditions in a separate permitted update when the workflow
requires them to be true before the transition.
A false or unevaluable expression produces 403 GUARD_FAILED. The checked
unknown function and division by zero are admitted at load but refused at
execution; load-time checking does not catch every invalid expression. A
nonempty string result is truthy: the expression 'false' passes, while the
boolean expression false fails. YAML guard: false is a third case: it is a
boolean declaration value, ignored by the parser. Quote AEL text and use
boolean-valued expressions.
Since kalos_adl 0.123.1 (#1561) a guard may also read other resources with
the read functions of Validation scope: exists, count, lookup and the
other aggregates. The read runs under the caller’s own readCondition. Name
a resource of the same domain bare and another domain’s by its quoted address:
guard: "count(Vendor, id == $record.vendorId && excluded != true) > 0"
Counting the rows that pass, as here, fails closed: a vendor that is not on
file is refused too. Before 0.123.1 such a guard could not be evaluated and
refused every record. Check: tools/repro/aegis/guard_reads.py.
| State function | Observed transition-guard behavior |
|---|---|
inState('review') | Works for a conventional status field |
currentState() == 'review' | Works for a conventional status field |
Same inState expression with controlled field phase | False; the function checks conventional status/state names |
canTransition('approved'), where approved is a valid transition name | False; the guard wrapper supplies no transitions array |
The last case deliberately gives the transition and target state the same name to isolate missing runtime context from the separate composition reference check. Function availability in Guard scope does not guarantee that the host supplies the required machine metadata. See the state-function implementations and ADL 18.
22.4 Preconditions and effects
requiredFields lists fields that must be non-null and nonempty on the existing
record or in the transition body. A named transition with no qualifying value
returns 422 REQUIRED_FIELD before its database update. The check understands
SQL NULL, unlike the presence-array gap described in §22.3.1.
This is an either-source check, not validation of a merged final record. An
existing resolution of old satisfies it even when the body sends
resolution: null; the checked transition succeeds and clears the resolution.
A value supplied only in the body also satisfies it. A PATCH that moves the
state runs the same check against the record it will write, so an explicit
null in the body is not satisfied by a stored value.
22.4.1 sets assignments
On a named transition, sets values take precedence over matching body values.
The state change and assignments are assembled into one SQL UPDATE. A PATCH
that moves the state applies the same sets the same way: they override the
body, and validation, rules and hooks see them (#1408). Before, PATCH wrote
only the body, so a record reached a state without the fields that state
promises. The fixture
rejects a forged approvedBy: client by overwriting it with the caller ID.
Its copied assignment reads the old resolution, even when the same request
changes resolution to a new value.
| Written value | Current named-transition assignment |
|---|---|
now() | UTC timestamp text in ISO 8601 form |
YAML null, empty string, or literal string null | SQL NULL |
$user.id, $user.username, $user.role | Caller identity value |
$record.name | Existing value of the named record field |
| Other string | Literal text; arbitrary AEL is not evaluated here |
Non-string scalar such as integer 7 | Ignored by the parser; no assignment retained |
The effects boundary fixture
assigns note: $user.userId and amount: 7. The unknown user placeholder clears
note to SQL NULL; it does not reject the transition. The numeric assignment
is omitted from the native model, so the submitted amount: 5 wins. The
independent modeller retains the numeric assignment, a material disagreement.
Unknown $record fields or null record values also resolve to SQL NULL.
The warning for an unknown user placeholder is a source-level diagnostic, not
an error returned to the caller.
Two further boundaries prevent treating sets as a validated patch:
- An unknown target field is admitted, then the transition fails with
500 DB_ERRORwhen SQL names the nonexistent column. - An assignment to the controlled
statuscan override the transition’s own target. The checked approve transition storescancelledwhile publishing the declaredapproved.enterevent. Avoid writing the machine’s controlled field insets; use the transition’stotarget.
A named transition runs PATCH’s validation stage on the record it will write
(#1103). Field constraints apply to the body and the new state, so amount: -2
is refused with 422 VALIDATION_ERROR despite arriving in a transition body. The
resource’s validation: rules see the merged record after sets are applied.
A record that already breaks a rule therefore refuses its transitions until the
data is corrected. Field write permissions and field-value validation are
different checks. ADL 20 owns general validation coverage.
The named-transition handler
is the source for these effects and their execution order.
22.5 Hooks and state events
onExit and onEnter are state callback declarations. After the database update,
the handler publishes the old state’s exit callbacks, then the new state’s
entry callbacks. In the checked local bus, subscribers see the newly stored
state during both callbacks. A forced database update failure publishes neither.
A state event includes the callback action name, state name, transition name,
and updated record. An exit event names the old state but carries the
updated record. Named transitions carry their transition name, and so does
a PATCH that moves the state (#1408). Creation uses (initial).
For the default site/domain identity in the fixture, the observed channels are:
| Form | Example exit channel |
|---|---|
| Canonical | adl.workflow.workflow_v1.order.state.review.exit |
| Compatibility | adl.workflow.Order.state.review.exit |
With compatibility publication enabled, each callback is published canonically
and then on the legacy channel. Both exit publications precede both entry
publications. Payload channel names the canonical channel even on the legacy
publication. ADL 3 owns the bus identity contract;
bus identifier helpers
implement this dual publication.
22.5.1 Delivery is not a precondition
The native local bus invokes matching subscribers synchronously during publish. It catches their standard exceptions; a throwing subscriber does not roll back the stored state or change the successful transition response. Thus the inherited “fire-and-forget” description means that subscriber failures do not decide the transition outcome. It does not establish asynchronous queue delivery or a remote-delivery guarantee.
Merely naming an action in onEnter does not execute that action through the
kernel. The adapter registers the declared callback actions and observes zero
invocations while their names appear in bus events. A consumer must handle those
publications. This experiment covers the
in-process bus, not a deployed
external subscriber or plugin binding.
State callbacks also differ from resource lifecycle hooks. The current named
handler invokes beforeUpdate before its SQL write and afterUpdate afterward;
a resource before-hook can refuse the operation. Those synchronous lifecycle
checks are not the state onEnter/onExit mechanism. ADL 25
owns resource hooks, while ADL 23 owns rules evaluated during
transition processing. The fixture does not install either kind of application
rule or resource lifecycle hook.
22.6 Executing a transition
The checked registrar exposes this route for approval:
POST /api/v1/workflow/orders/o1/transitions/approve
Its native action ID is adl.workflow.workflow_v1.order.approve, with
adl.workflow.order.approve as the enabled compatibility ID. The ID is derived
from the named transition; it does not contain an extra .transition segment.
The route registrar
registers each distinct transition name once. HTTP decoding and authentication
are outside this chapter’s synthetic-kernel checks.
22.6.1 A complete lifecycle
Using the complete fixture and an admin caller:
| Step | Request body or action | Checked result |
|---|---|---|
| Create | {"id":"o1","title":"Order one","status":"approved"} | 201; stored state is draft |
| Submit | Named submit, with id: o1 | 200; state becomes review |
| Try to approve | Named approve, with id: o1 | 403 GUARD_FAILED; state stays review |
| Supply preconditions | PATCH ready: yes and resolution: accepted | 200; state stays review |
| Approve | Named approve, with id: o1 | 200; state is approved, caller/time/copy assignments applied |
| Approve again | Same named action | 422 FINAL_STATE; stored state unchanged |
Use JSON string "yes" for the ready field in the fourth step. The table is
an action sequence; the runner contains
its exact JSON requests and independent database reads.
22.6.2 Operation coverage
| Behavior | Named transition | PATCH of state field | PUT replacement |
|---|---|---|---|
| Find an edge from the current state | By transition name | First edge with matching target | First edge with matching target |
| Reject leaving a final state | Yes | Yes, except same-state no-op | Yes, except same-state no-op |
| Array and AEL guards | Checked | Checked for movement | Checked for movement |
Transition requiredFields | Checked | Checked for movement | Checked for movement |
Transition sets | Applied | Applied for movement (#1408) | Applied for movement (#1445) |
| Rules scoped to the transition | Run | Run for movement, with update rules (#1408) | Run for movement, with update rules (#1445) |
| State exit/entry callbacks | Published | Published for a changed state | Published for a changed state |
Ordinary field constraints and validation: rules | Checked on the merged record after sets | Checked in the example | Checked in the example |
PUT checks the effective replacement, including fields reset by omission. It
refuses an unknown state or a move out of a final state, applies the matching
transition’s assignments before hooks and rules, and records update, transition
and field-change history. A same-state replacement runs update rules and history
without replaying a transition. The older published chapter evidence predates
these fixes; tools/repro/adl/36_put_skips_transition.py and the native PUT
regressions cover the updated contract on current source.
Named transition authorization follows update authorization unless the transition has a grant of its own. With no explicit transition rule, the endpoint applies the resource’s update permission to the loaded row (#1213). ADL 21 §21.6 owns the full permission ordering.
22.6.3 Same-state writes and ambiguous destinations
PATCH of the current state is a no-op for the machine. It can still update
other fields, but does not run a self-transition’s guards, sets, or state
callbacks. The checked PATCH keeps a client-supplied note; the explicit touch
self-transition instead assigns touched and publishes exit/entry callbacks.
The executor even allows an unchanged unknown state through this no-op branch;
that is not validation of the stored state.
If two edges from one state have the same target, direct PATCH takes the first
matching transition in the resolved model. It does not search for a later edge
whose guards would pass. In the checked example, zAllow before aDeny permits
the PATCH; reversing them refuses it. Naming zAllow selects that edge directly.
Prefer named transitions where several actions share a destination.
22.6.4 Failure codes
| Condition | Observed result |
|---|---|
| Missing record ID | 422 VALIDATION_ERROR |
| Record ID not found | 404 NOT_FOUND |
| Entirely undeclared native action | 404 ACTION_NOT_FOUND |
| Named action exists, but no edge from this state | 422 INVALID_TRANSITION |
| Missing or empty current state supplied to the executor | 422 NO_STATE |
| Unknown current state on a named attempt, or unknown PATCH target | 422 UNKNOWN_STATE |
| Outgoing movement from a final state | 422 FINAL_STATE |
| Failed role/presence/AEL guard | 403 GUARD_FAILED |
Unsatisfied transition requiredFields | 422 REQUIRED_FIELD |
| Unknown effect column or the checked forced write failure | 500 DB_ERROR |
A nonfinal state with no outgoing edges is a dead end but has a different
failure reason: the fixture’s parked record returns INVALID_TRANSITION, while
an approved final record returns FINAL_STATE. The inherited claim that all
such failures are INVALID_TRANSITION is too broad. Applicable permissions can
refuse the caller before transition validity is considered.
22.6.5 Simultaneous transitions
A state move is written only if the record is still in the state the request
read. Of several requests that send the same move to one record at the same
instant, one is written and answers 200. Each of the others gets the answer
it would have had arriving second: 422 INVALID_TRANSITION, with
currentState, expectedState and targetState in the error data, or
404 NOT_FOUND if the record was deleted meanwhile. The loser runs no
effects: no sets:, no history event, no enter or exit event.
This holds for a named transition, a PATCH and a PUT that move the state. A named transition can therefore be used as a claim: the caller that gets 200 made the move.
A PATCH or PUT that sends the state the record is already in is not a move and still answers 200, because a client saving a whole record sends its state back. It cannot be used as a claim. A joined subtype, which writes through a view, is not covered: its state write is unconditional.
22.7 Composition and surviving-state references
A resource has one surviving state machine. A trait contributes its machine as
one indivisible unit; a resource’s explicit machine replaces that unit completely.
This includes the field binding, initial state, states, and transitions. Two
applied traits carrying machines are an error, TRAIT_STATEMACHINE_CONFLICT;
ordinary later-wins field precedence does not select between them.
The trait-machine fixture
inherits the complete workflow from Reviewable. The
replacement fixture
replaces it with an open → done machine on phase. The separately inherited
status field remains. Replacing a machine does not remove ordinary fields or
rewrite surviving permissions and scopes that mention the old state names.
ADL 13 §13.9 owns the
composition rules and compatibility spelling for flat trait machines. The
examples here use explicit stateMachine bodies.
Draft 05 §8.5 requires literal state references to name surviving states after
trait merging. The dangling-state fixture
retains a trait permission using inState('review') after replacing the machine
with open/done; the native parser rejects it with
TRAIT_STATE_REFERENCE_UNRESOLVED.
The current trait resolver
uses a limited regex over string leaves. Double-quoted inState("review")
and the checked currentState() == 'review' comparison evade this detection.
Descriptions containing matching text can also be treated as state references,
as documented in ADL 13. This is not a complete analysis of executable AEL.
There is also a vocabulary conflict: the state-reference scan treats the literal
argument to canTransition as a state, whereas the function implementation
expects a transition name. The fixture’s canTransition('approve') is
admitted without trait processing but rejected when a traits: [] list activates
the scan, because approve is not a state. This draft records the governing text
and the conflicting consumers without inventing a new function meaning. Avoid
using parser acceptance or a false runtime result as proof that this function
correctly validates the lifecycle.
22.8 Generated descriptions, export, and restoration
OpenAPI publishes a POST path for each distinct transition name with an ID
parameter and resource-shaped success response. It does not describe a
transition-specific request body or its required fields in the checked output.
The shared error-response set also omits the observed 403 GUARD_FAILED response.
Repeated names share one path; its generated summary can describe only one of
the source-state definitions. The OpenAPI operationId includes .transition.
and must not be substituted for the registered native action ID in §22.6.
ADL 32 owns the full generated interface.
The model exporter preserves the machine field, initial state, targets, guard
arrays, required fields, string/null assignments, and callback arrays. However,
it omits the scalar AEL guard and writes description/timeout at locations the
parser does not read as state metadata. Re-exporting and parsing the fixture
therefore loses its AEL approval condition, description, and timeout. Do not
use that exported document as a behavior-preserving replacement without review.
See OpenAPI generation
and model export.
Normal source-backed registry loading preserves the checked guard expression,
metadata, transition order, and recorded trait origins. Deliberately clearing
source in a disposable registry forces a fallback that loses the AEL guard and
metadata. It also changes the ambiguous fixture’s transition order from
zAllow, aDeny to aDeny, zAllow. Since PATCH chooses the first matching target,
that order is behaviorally significant. The experiment does not imply that an
intact registry normally discards its authored source.
Full trait transitions retain trait:Reviewable origins through the checked
restoration paths. Shorthand transitions in that trait carry an explicit tag
in the native model, a provenance limitation rather than a second composition
rule. Registry restoration
and ADL 13 own those model-origin details. Editing or replacing a machine on an
existing resource also requires review of records still holding old state values;
ADL 17 owns evolution and migration.
22.9 Verification and related chapters
The chapter includes eight complete YAML fixtures and 102 native cases: 35 parser/model cases, 14 guard-list cases, nine executor cases, and 44 disposable store sequences. 518 assertions and 74 existing focused tests pass. The assertions include expected errors and implementation gaps. Their success is not a declaration of complete ADL conformance.
The independent modeller produces eight document projections. It models the
basic graph, role/presence lists, required fields, and assignments, but its
transition model has no AEL guard member. It keeps the numeric assignment
ignored natively, and warns that trait keys are unused. Its acceptance of the
two-trait conflict and dangling-state documents does not validate native
composition. The evidence report records those
differences and the exact source/build provenance.
All execution uses synthetic caller identities, the local synchronous bus, and temporary SQLite state. No HTTP/JWT server, PostgreSQL backend, remote callback binding, concurrency race, crash durability, timer, or bulk/import path is tested. In particular, callback observations do not prove distributed delivery, and one SQL UPDATE does not make earlier rules or all application side effects one transaction. Source links point to actual repository files; the verification record stores paths, revisions, and hashes without copying production sources.
| Subject | Owning chapter |
|---|---|
| Execution identity and bus | ADL 3 |
| Field types and enumerations | ADL 10, ADL 11 |
| Trait composition and derivation | ADL 13, ADL 14 |
| Evolution of existing resources | ADL 17 |
| AEL, validation, and permissions | ADL 18, ADL 20, ADL 21 |
| Rules, history, and resource hooks | ADL 23, ADL 24, ADL 25 |
| Generated routes, errors, and schema | ADL 26, ADL 31, ADL 32 |