The lifecycle is short: draft becomes submitted; submitted becomes certified or rejected. Certified and rejected are final states. The graph is easy to draw. The useful engineering work is identifying what each edge reads, authorizes, and writes.
Submission records the authenticated actor. Approval compares the current actor with that stored submitter and records the approver. The measured content already belongs to an immutable saved candidate. A rejection records a terminal decision without pretending that a corrected measurement is the same candidate.
Read the edge as a command
This fragment describes approval from submitted:
approve:
to: certified
guards: [inspector]
guard: "user.id != $record.submittedBy"
sets: { approvedBy: $user.id }
The role guard and expression guard have different subjects. The first requires inspector authority. The second requires an identity distinct from the stored submitter. The assignment records the identity that actually performed the approved operation. The separate permission map in Chapter 6 authorizes this named transition without reopening generic updates.
The command still depends on the integrity of submittedBy. If another write can replace Alice with Bob before Alice approves, the inequality can pass while the business rule fails. Protecting the field is therefore part of the independent-review argument, not an optional audit improvement.
Bind approval to content
Distinct identities do not establish what was reviewed. Alice could submit revision 1 and Bob could approve a later revision 2 if the content changed between their actions. Our example avoids that ambiguity by making instrument, revision, and offset immutable from creation.
A richer application might support editable drafts and a protected snapshot created on submission. Then approval must bind to that snapshot, and the service must reject a stale expected revision at commit. Merely showing the revision number in the interface does not perform this check.
The current transition path supports optimistic version checks through its version-control mechanism, but whether that mechanism is active depends on the resource configuration. This example does not claim to test every concurrent approval or versioned-update case. Chapter 14 develops the concurrency obligation separately.
Treat transition bodies as writes
An approval request can carry a body. That body may contain legitimate review fields, but it can also try to replace provenance or measurement values. A state-machine endpoint is therefore another mutation surface.
The inspected implementation checks field write restrictions on the transition body, excludes immutable measurement fields from body writes, resolves transition assignments, and validates the effective resulting record. These are consequential engine behaviors. Their presence explains why testing only PATCH would leave an important gap.
The lab includes an attempted offset replacement during approval and checks the stored offset afterward. The expected property is preservation of the submitted measurement. A successful approval with the immutable replacement ignored can satisfy that property; a test demanding a particular refusal would describe a different API contract.
Final states are local to the machine
A final state prevents outgoing movement through that state machine. It does not automatically prohibit every database update, administrative import, recovery script, or extension action. The example also refuses generic updates outside draft and gives no ordinary delete authority.
When extending the domain, review every new operation capable of changing state or measured content. An emergency approval action can invalidate an otherwise sound argument even if the ordinary approval edge remains perfectly guarded. A second route to certified is part of the same property.
Explain the proof obligation in ordinary language
At creation, no record is certified. For every operation that can make a record certified, the actual submitter must already be protected, the approver must be authenticated and distinct, and the reviewed content must remain the same. Every operation afterward must preserve those facts or explicitly end the certification’s meaning.
That is the shape of an invariant argument. The runtime lab supplies concrete observations about selected operations. It is not an exhaustive proof over every privileged path in Kalos. The distinction lets a reader use both testing and formal reasoning without confusing their scope.
See ADL 22 and action_sm.cpp for the current contract and implementation.
Workshop
Design a correction flow. Decide whether rejection is followed by a new record, whether the new record refers to its predecessor, and whether an existing certification can be revoked. State what remains true about the historical approval after each event.