ADL 0.6.0 reference · Review draft 1 · November 14, 2026.
Contents · Source map · Evidence
The 0.6 edition note
This chapter retains the detailed language contract and its source-specific observations. Its chapter number and numbered sections remain stable. The 0.6 additions do not by themselves change this subject’s defaults or supply fresh execution evidence for it.
Reverification should cover rule timing, caller identity, recursion, and failure atomicity. Use the original examples and evidence links below to recover the earlier test context. The new edition’s source map records this chapter as inherited detail; the current draft does not claim those historical tests were rerun.
Retained reference detail
The numbered sections below are carried from 23-rules-engine.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.
23.1 Scope of this chapter
A rule evaluates a policy condition during a record operation. When its condition
is true, the rule fires: it rejects the operation, adds a warning, or records
the result. The condition describes the violation or situation of interest.
For an upper limit of 100, amount > 100 fires above the limit; writing
amount <= 100 reverses that policy.
| Construct | Main question | Owning chapter |
|---|---|---|
| Validation | Does the candidate record satisfy its field and record constraints? | ADL 20 |
| Permission | May this caller perform this operation? | ADL 21 |
| State-machine guard | May this transition proceed from the current state? | ADL 22 |
| Rule | Does this operation match a policy that should reject, warn, or log? | This chapter |
A rule is not an authorization grant. A regulation string names an external
policy; it neither implements that policy by itself nor proves compliance.
The examples use a fictional amount policy without monetary or legal semantics.
This chapter develops the reduced v0.3.1 rules chapter (retired) with the fuller inherited declaration account (v0.3.1, retired), Draft 05 §§13–14 and §18 item 24, and the signed A3 ruling. The historical source and native test suite call this subsystem “Phase 22”; its manual identifier is ADL 23.
Observed behavior below comes from revision d260eca2, a fresh matching
Release build, and the verification record.
Parsing, firing, persistence, and event publication are checked separately.
Implementation gaps do not amend the language contract.
23.2 Declaring a rule
Declare named rules under the domain’s rules mapping. The rule’s nested
trigger selects the resource and events. This fragment comes from the complete
policy.yaml:
rules:
hardLimit:
description: Illustrative policy for Order
trigger:
resource: Order
events: [create, update]
condition: amount > 100
action: reject
message: Amount {amount} exceeds policy
severity: error
regulation: Example policy CAP-100
priority: 10
history:
event: blocked
label: Blocked amount {amount}
The complete domain also defines Order, a warning above 50, and a log rule
for positive amounts. It includes explicit permissions and a small state
machine so the operation comparisons use the same record shape.
23.2.1 Rule properties
The inherited declaration contract calls for description, trigger,
condition, action, message, and severity. Write them explicitly. Current
parser defaults and omissions are more permissive than that authoring contract.
| Property | Authoring form and purpose | Current default or limit |
|---|---|---|
description | String describing the policy | Empty string |
trigger | Mapping described in §23.2.2 | Missing mapping leaves no selectable resource/events |
condition | String containing AEL; true means fire | Empty expression never fires |
action | reject, warn, or log | Missing action becomes reject |
message | String with {field} placeholders | Empty string |
messageData | Mapping of placeholder name to AEL string | Empty mapping; numeric values are ignored |
severity | error, warning, or info for presentation | error; the checked critical value also admits |
regulation | Informative policy reference | Empty string |
enabled | Boolean declaration default | true; runtime controls have the limitation in §23.7.2 |
priority | Integer; lower first within an action partition | 100 |
dependsOn | Name of a rule whose firing suppresses this rule | Empty string |
group | Organizational group name | Empty string; no group enforcement |
history, notification | Side-effect declaration mappings | Absent; expansion is described in §23.6 |
protected participates in derivation rules; ADL 14 owns that
contract. It is separate from enabling a live rule for an operation.
23.2.2 Trigger properties and the events rename
| Trigger property | Meaning |
|---|---|
resource | Exact resource name; Order in the example |
events | Operation name or array: create, update, delete, transition |
fields | Array of watched fields; for update, evaluate only if any changed |
transition | Named transition to match when evaluating a transition event |
condition | AEL pre-filter; false skips the main condition |
The current spelling is trigger.events. Draft 05 §18 item 24 retired
trigger.on; the retired-trigger example
is rejected with KEY_RENAMED. Quoting the old on key does not restore it.
The trigger mapping has a closed key set: the checked event typo and true
artifact reject under strict parsing.
Closed keys do not imply checked event values. events: [udpate] is admitted
and never selected for an actual update. An empty events array, a missing
trigger, or an unknown resource also admits; the live checks show no firing.
A scalar events: create is accepted. In a mixed array, non-string entries
are discarded.
The reduced inherited example places resource and on directly under the
rule. That flattened form does not populate the current trigger. Use the nested
mapping above; changing only the word on to events is insufficient.
23.2.3 Strict submission and compatibility parsing
The unknown-action example
uses action: wanr. Strict authoring rejects it, and domain submission returns
422 PARSE_ERROR with the unknown action and legal values in the message.
This supersedes the reduced chapter’s unconditional claim that unknown actions
silently become rejects.
Compatibility parse_and_resolve(..., strict=false) still returns a warning
and retains the reject fallback. That behavior supports older stored documents;
it does not make wanr an accepted spelling for new submissions. The current
parser and
rule model define these boundaries.
23.2.4 Resource-local declarations
The resource-policy example places
rules inside Order. The native parser hoists those rules into the domain
configuration and supplies Order when trigger.resource is omitted. The
checked local limit then rejects an excessive create.
This path also produces an “unknown key ‘rules’ in resource ‘Order’” warning; the key sweep and the hoisting implementation disagree. The independent modeller has no resource rule model (§23.9). Prefer domain-level declarations for a clear portable account of the target.
Hoisted rules keep their names. A local and a domain rule with the same name both survive the checked parse. Use distinct rule names across the domain: management lookup, enable state, dependencies, and rule-history selection all use the rule name, without a separate local namespace.
23.3 Conditions and messages
Rules execute AEL in Validation scope. ADL 18 owns expression syntax, coercion, function scopes, target addresses, and query semantics.
23.3.1 Bindings and failure behavior
| Evaluation point | Record bindings | Other supplied context |
|---|---|---|
| Main condition | $record, $this, and bare field names | $previous when the caller supplies it; query handler and domain scope on live writes |
| Trigger pre-filter | $record, $this, and bare field names | No previous record or query handler |
messageData expression | $record, $this, and bare field names | Query handler when available; no previous record |
On a live write the main condition binds the caller as $user, with id,
username, role, roles and claims (#1560). A bare user is not bound: in
a rule a bare name is a field of the record. The trigger pre-filter, the
messageData expressions and the condition test endpoint (§23.7.1) have no
caller, so $user.id == 'admin-1' does not fire there. With the host setting
adl.claims.unknown: deny, a condition that names $user.claims.<name> for a
claim the request lacks counts as one that could not be evaluated, so a reject
rule refuses the write (ADL 21). Guard functions such as inState are
outside Validation scope. A rule inspecting its candidate state can compare
status directly; a guard function’s existence is not evidence that this host
allows it.
An empty main condition is false. An empty trigger condition passes its filter. These defaults differ intentionally.
A condition that cannot be evaluated is not a pass (#1401). Examples are a
division by zero, a null operand in arithmetic (null * 20 is a type error,
1102), an unknown function, or an unresolved query target. What happens
depends on the action:
| Action | Evaluation error in the condition or trigger pre-filter |
|---|---|
reject | The write is refused with 422 RULE_EVALUATION_FAILED. The message names the rule and the error; details carries rule, severity, regulation and error |
warn | The write proceeds. The warning entry carries the error under error |
log | The write proceeds |
Every evaluation error is written to the rules log, with fired false and a
message naming the rule and the error. With explanation enabled, the trace
reads Result: ERROR (...), not PASSED. The dry-run test action returns
the error under error.
A reject rule is a control: one that cannot decide refuses, as resource
validation, permissions and transition guards already do (ADL 18).
That makes a null in arithmetic matter. A reject rule over an optional field
should guard it, as in $record.held != null && $record.held * 20 > $record.total,
or use ??. Otherwise every write that leaves the field empty is refused.
Load checking does reject selected address and aggregate errors: the checked
legacy sum(Order, 'amount', true) form returns AEL_AGGREGATE_ARITY, and an
address containing an empty segment rejects. This selective checking does not
cover every expression error. A nonempty string result is truthy: the AEL
expression 'false' fires. Use a boolean-valued policy expression and verify
both firing and nonfiring examples.
23.3.2 Live queries and additive functions
The query-policy example uses:
condition: "sum('adl.policy.policy.Order.amount', true) > 100"
The quoted address selects a field in this bare domain’s AEL identity. It is
not the bus action identifier, which includes _v1. See ADL 7
for addressing and ADL 18 for aggregates.
This particular condition intentionally examines already stored rows. Its first create of 150 succeeds because the store is empty during evaluation; a second create is rejected because the stored sum is now 150. The submitted candidate is not automatically added to a query result. A policy about the prospective total must account for the candidate and, on update, avoid counting the old row twice. The example demonstrates the query boundary, not a complete concurrent aggregate invariant.
The management test endpoint has no query handler. For this same rule it
reports fired: false where the later live create fires. Trigger pre-filters
also have no query handler. The
current query adapter
reads stored rows and caps its result at 1,000; it is not a caller-filtered
resource list request. Since kalos_adl 0.120.0 a count, sum, avg, min
or max whose condition the store can answer is one statement over every
row and is not capped (ADL 18 §18.5.1). General query visibility and result limits remain in
ADL 18 and ADL 20.
The calendar-policy example verifies an additive function from Draft 05 §14.5:
condition: "networkdays('2026-09-07', '2026-09-11') == 5"
action: warn
It fires on the checked create. These fixed dates count five weekdays, with no holiday list supplied. The example establishes function execution inside this rule host; it does not import a regional holiday calendar.
23.3.3 Message interpolation
message substitutes exact {field} keys from the candidate record. Null or
missing values render as empty strings. Non-string values use their JSON text.
The checked rule-message {$record.amount} placeholder is also empty: this
interpolator does not strip the $record. prefix. The checked history
interpolator has the same boundary; see
ADL 24 §24.4.2.
messageData evaluates named AEL strings first and overlays their successful
results on the interpolation data. It does not update the record. An entry
amount: "42" replaces only the displayed amount; double: "amount * 2" still
reads the original record amount. For input 150, the checked message becomes
A=42.0; D=300.0; X=; N=; P=. The missing value and failed expression render
empty; they do not reject the operation. Numeric declaration values in
messageData are ignored by the native parser.
23.4 Actions and evaluation order
| Action | Rule outcome | Current response boundary |
|---|---|---|
reject | Stop at the first firing rejection, or at the first that cannot be evaluated | 422 RULE_VIOLATION, message and rule/severity detail; regulation when present. 422 RULE_EVALUATION_FAILED when the condition errors (§23.3.1) |
warn | Continue, collect warning, and log firing | Create and PATCH return _warnings; named transition and delete omit them |
log | Continue and log firing | No rule warning in the response |
Severity is presentation metadata, not the action. A warn rule with severity
error still permits the write. The checked transition variant demonstrates
that distinction. A log row records the action and message; the current log
schema does not include a separate severity column.
For one resource operation, the rules engine:
- Selects declared-enabled rules matching the resource and operation, ordered by increasing priority.
- Partitions them into rejects, then warns, then logs. Priority orders within a partition; it does not let a warn outrun a reject.
- Checks runtime enable state and skips a rule if its
dependsOnname already fired during this evaluation. - Applies the transition-name filter, watched-field filter, and trigger condition.
- Evaluates the main condition, records the applicable log entry, and performs the action. The first firing reject ends evaluation.
In the main fixture, recordPolicy has priority 0, reviewAmount has 1, and
hardLimit has 10. An amount of 150 reports only hardLimit; the lower-priority
warn/log rules do not execute. An amount of 75 fires reviewAmount before
recordPolicy. Equal-priority order is not specified by this chapter; give rules
explicit distinct priorities where order matters.
dependsOn is suppression after firing, not a requirement that a prerequisite
pass. When recordPolicy depends on reviewAmount, a warning suppresses the log;
a nonfiring warning does not. Depending on a rule evaluated later has no effect
on the current rule. There is no dependency-graph scheduler in this execution.
For update field filters, any unequal watched field or a field present on only one side counts as changed. A change must still pass the pre-filter and main condition. The watched-update example ignores a note-only PATCH and rejects an amount increase from 20 to 30.
23.5 Where rules run
The execution surface matters as much as the declaration. The checked operations use generated actions with synthetic caller identity; they do not run through an HTTP server or JWT authentication.
| Operation | Rule event | Candidate seen by the rules engine |
|---|---|---|
| Create | create | Request data before initial-state assignment, generated key/default processing, and insertion |
| PATCH | update; also transition when it moves the state | Existing record merged with body fields and, when the state moves, the transition’s sets, excluding the request id |
| Named transition | transition | Existing record with target state, transition assignments and authorized hook-returned fields (#1534) |
| Delete | delete | Existing record; no previous-record binding |
| PUT | update; also transition when it moves the state | Effective replacement, including defaults/NULLs, preserved columns and transition assignments (#1445) |
Import with features.dataImport: true | None in the checked handler | Field checks run, but rules are bypassed |
| Bulk create | Per-item create | Delegates to the generated create action |
The main fixture rejects amount 150 on create, PATCH and PUT. Enabled import
continues to store it without rule firing. PUT runs transition-scoped rules
when the replacement moves the state, and preserves rule warnings in its
response (#1445). An explicit internal or seeder transport label
on the generated create still runs rules; the inherited blanket seeder
exemption does not describe this handler. Direct SQL bypasses the action layer.
This evidence does not cover every independent seeding utility.
A PATCH that moves a state field runs the matching transition (ADL 22), so it
is an update event and that transition’s transition event. Rules for
either run, each once, in priority order. The checked PATCH to approved is
refused by a rule filtered to transition approve, as the named transition is
(#1408). Before, PATCH ran only update rules, so a transition-scoped reject
rule could be stepped around by PATCHing the state.
23.5.1 Timing affects the candidate
On create, a rule comparing status == 'approved' sees that client-supplied
value and rejects, even though a successful ordinary create would force draft.
Conversely, a rule comparing status == 'draft' does not fire when the request
omits status, although draft is stored afterward.
On a named transition, a rule looking for note == 'approved by effect' does
not fire when that value will be assigned by sets. The transition succeeds
and stores the note later. The
transition-policy example instead
checks the simulated target state and amount before permitting approval.
The handlers place rules before their main record write, but there is no single
universal ordering of all checks and hooks. Source inspection shows create/PATCH
before-hooks ahead of rules, and named-transition/delete before-hooks afterward.
Named transitions evaluate machine guards before rules and transition
requiredFields afterward. PATCH evaluates its rules before the later machine
state-write check. ADL 25 owns hook contracts; these fixtures do
not install application lifecycle hooks.
23.5.2 A rejected record write can still have effects
The checked create fails ordinary field validation or permission checks before firing rules. A rule rejection prevents that operation’s record write. It does not mean that no database change or publication occurred: the rules log is written before the rejection response, and history can be recorded for an existing record (§23.6).
A warning followed by a forced SQLite UPDATE failure leaves the original amount
10 in place, while rule log entries and history about proposed amount 75 remain.
The checked X-Kalos-Dry-Run: true PATCH similarly keeps the record unchanged
but records rule log/history effects. Use the management condition test with its
limited semantics (§23.7.1) when evaluating without those write-handler effects.
Bulk create supplies a further boundary. Its first item of 75 publishes a review history event; its second item of 150 rejects. The shared SQLite transaction rolls back both the record and persisted rule/history rows, but the already observed bus event remains. That event is evidence of evaluation during the attempt, not proof that the enclosing bulk operation committed.
23.6 History and notification declarations
A rule’s history and notification blocks expand into ordinary history events
and notification subscriptions. They are not arbitrary actions executed by the
rules engine.
A history.event supplies the event name. Without it, a notification-bearing
rule gets a derived rule_<ruleName> event. The event has trigger rule and
selects the firing rule by name. Its default label comes from the rule message,
with the rule name as a fallback. Explicit history metadata can override it.
The parser derives capture fields from the label/detail, notification templates,
and recipient field references, while retaining explicit captures. In the checked
notification projection, the resulting capture is [amount, notifyUser, title].
The notification subscribes with source: history to rule_policyRule. This
chapter verifies that expansion; it does not deliver email or exercise a
notification provider. ADL 24 owns history and
ADL 35 owns notifications.
23.6.1 What the checked timeline records
| Situation | Observed rule-history behavior |
|---|---|
| Rejected create | No record timeline entry or history event: no persisted record to attach it to |
| Successful warning create | History uses the inserted record ID; subscriber sees the stored amount |
| Rejected PATCH or named transition | History records the proposed values on the existing record’s timeline |
| Successful warning PATCH/transition | Rule history publishes before the record update; subscriber still sees the old row |
| Warn/log delete | History publishes while the row exists, before deletion |
The rules log is separate. Create log entries have an empty recordId, even
when a successful create later has ID o1. A rejected create can therefore
have a rule-log entry but no record-history event.
For the fixture, the blocked PATCH publishes canonically on
adl.policy.policy_v1.order.history.blocked, then on compatibility channel
adl.policy.order.history.blocked. Both payloads name the canonical channel.
These are two publications of the same history event, not two timeline rows.
The history engine
and bus helpers implement
the observed behavior; ADL 3 owns bus identity.
A proposed value in a history event need not equal the stored record at publication or after the operation. Read it together with the event meaning, rule result, and operation outcome. The checks establish local ordering, not remote delivery, crash durability, or a complete audit guarantee.
23.7 Runtime controls and the rules log
When the domain has rules, six management routes are registered. The fixture’s
base is /api/v1/policy/rules.
| Method and suffix | Purpose |
|---|---|
GET / | List rules and reported runtime enable state |
GET /{name} | Read one rule and its condition/trigger information |
POST /{name}/enable | Store enabled state for the name |
POST /{name}/disable | Store disabled state for the name |
POST /{name}/test | Test the main condition against a supplied record |
GET /log | Read rule-log entries |
All six require admin or administrator. The checked ordinary user is refused
with 403 FORBIDDEN; a caller with admin in its roles vector is admitted.
The native list action is adl.policy.policy_v1.rules.list; the enabled
compatibility action is adl.policy.rules.list. Other suffixes follow the same
pattern. ADL 26 owns the generated route contract.
23.7.1 The condition test is narrower than a live operation
For example:
{"name":"hardLimit","record":{"amount":150}}
The test returns the rule name, fired, interpolated message, and action.
It does not write a record, rule log, or history in the checked calls. It also
does not apply event/resource selection, runtime enable state, trigger pre-filter,
watched-field filtering, transition-name filtering, or dependencies. It supplies
neither $previous nor a live query handler.
A disabled rule with a false trigger pre-filter can thus report fired: true
in this endpoint while an actual create does not fire it. A query-dependent
rule can report false here and reject a live write. Treat this endpoint as a
main-condition check with its supplied bindings, not as a simulation of the
complete operation.
Unknown names return 404 NOT_FOUND from get/test. Missing names produce
422 VALIDATION_ERROR; missing test-record objects produce
400 MALFORMED_REQUEST. These are distinct from a policy rejection during a
record write.
23.7.2 Enable state and persistence limits
A runtime disable survives the checked domain resubmission at version 1.0.1. For a rule declared enabled, disabling permits the excessive write and enabling restores rejection.
However, RulesConfig::rules_for excludes a rule declared enabled: false
before runtime overrides are consulted. The checked enable call succeeds and
get reports enabled: true, but the rule still does not fire on create. Its
condition test does fire. This is a current implementation gap in the promised
runtime override, not a second meaning of enabled.
Enable and disable also accept unknown names and create state rows for them; a later get still reports that the rule does not exist. They do not verify successful storage: after the disposable state table is removed, disable returns 200 but the rule remains effectively enabled and rejects the next create. The management handlers are the implementation reference. A success response alone does not prove the reported state governs live evaluation.
23.7.3 Log contents and settings
The rules log records firing rule name, action, message, regulation, resource, record ID, actor ID, operation, and timestamp. The actor is the identity supplied to the request; these synthetic tests do not authenticate it.
rulesConfig:
logAllEvaluations: true
logRetentionDays: 365
By default only firing rules are logged. logAllEvaluations also records main
conditions that evaluate false, with fired: 0 and an empty message. A rule
skipped by event selection, enable state, dependency, or pre-filter has not
reached that evaluation point; “all” does not log every declared rule on every
request. The checked amount-10 create logs two false conditions and one firing
log rule when the setting is enabled.
logRetentionDays is retained as configuration, but the inspected runtime has
no reader that enforces this retention period. It does not schedule deletion
of old rows. The log reader supports ruleName, boolean fired, action, and
since filters. Its default limit is 100; positive integer limits through 1,000
are accepted. totalCount counts returned rows, not an independent unbounded
count. Results are ordered by descending timestamp.
23.7.3.1 When the log row cannot be written
What happens when a log row cannot be stored depends on whether the rule names
a regulation (#1393):
| Rule | The row cannot be written |
|---|---|
Names a regulation | The operation is refused with 500 RULES_LOG_FAILED, for every action (reject, warn, log). details carries rule and regulation. Nothing is written |
No regulation | The row is lost and evaluation goes on. A reject still returns RULE_VIOLATION; a warn or log rule lets the write through |
A regulated rule’s row is the record that the check ran, so a write that cannot
be shown to have been checked is not allowed through. This applies only when a
row would have been written: a rule that fired, a rule whose condition could not
be evaluated, or any evaluated rule under logAllEvaluations. A regulated rule
that did not fire writes no row by default and so cannot fail this way.
A regulated reject rule that fires while the log is unwritable answers
RULES_LOG_FAILED, not RULE_VIOLATION: the write is blocked either way, and
the response says that the blocked attempt went unrecorded.
For rules without a regulation, do not infer exhaustive logging from a declaration or a successful evaluation.
23.8 Groups, generated descriptions, and restoration
The groups example declares:
rules:
_groups:
caps:
rules: [hardLimit, reviewAmount]
enabled: false
This fragment accompanies the named rules in the complete file. The native
model retains the member names, but group enablement has no runtime effect;
hardLimit still rejects. The linter reports DECLARED_NOT_IMPLEMENTED at
rules._groups. No group enable/disable routes are registered. The inherited
claim that groups receive no diagnostic is therefore stale, although their
runtime limitation remains.
Generated descriptions and storage have separate limits:
- The actual route registrar exposes the six management routes, but the checked
offline OpenAPI document contains no
/rulespaths. AdlExporter::to_jsonrefuses a domain with rules usingNotImplemented, explicitly identifying its unsupported subsystem projection.- Normal registry loading reparses stored source and preserves the checked rules, conditions, and generated history declarations.
- The registry’s model-only projection for this domain contains provenance but no reconstructible domain body. Clearing both stored source texts in the disposable registry makes loading return no model, rather than a usable model with its rules preserved.
The exporter and registry are the source references. Keep the registry’s actual stored source intact. This is runtime persistence, separate from documentation source snapshots: this manual links to production files and stores their revision/hash provenance without copying them.
23.9 Verification and related chapters
Nine complete YAML files support 105 native cases: 30 parser/model cases, 31 direct evaluator cases, and 44 isolated generated-action sequences. 755 assertions and 30 focused native tests pass on the matching build. Assertions include expected rejection and documented implementation gaps; they do not establish complete language conformance.
The independent modeller produces nine document projections. It still reads
trigger.on, so current events declarations produce RULE_NEVER_FIRES errors
while the retired-trigger fixture is accepted. Its resource type has no local
rules member, and the local-rule example produces no corresponding error.
No coverage notes identify these discrepancies. This is disagreement between
consumers, not a reason to restore the retired grammar.
The evidence report and example instructions describe reproduction, source hashes, assertion boundaries, and the native/Python differences. Execution uses temporary SQLite stores, synthetic identities, and the synchronous local bus. It does not verify PostgreSQL, HTTP/JWT, real notification delivery, concurrent aggregate correctness, crash recovery, or full server reboot behavior. The resubmission and registry-loading checks identify their narrower boundaries.
| Subject | Owning chapter |
|---|---|
| Execution identity and bus | ADL 3 |
| Addressing and AEL | ADL 7, ADL 18 |
| Derivation and evolution | ADL 14, ADL 17 |
| Validation, permissions, and machines | ADL 20, ADL 21, ADL 22 |
| History and resource hooks | ADL 24, ADL 25 |
| Routes and generated schema | ADL 26, ADL 32 |
| Notifications | ADL 35 |