FullAgenticStack WhatsApp-first: RFC-WF-0018
Source: Dev.to
Abstract
This document specifies the State Model & Command Lifecycle (SMCL) for WhatsApp‑first systems. SMCL defines a normative finite‑state machine (FSM) for command execution and recovery, including:
- Allowed states
- Valid transitions
- Terminal conditions
- Evidence‑emission requirements
SMCL ensures that all components (command execution, security gating, observability, recovery/compensation, and auditing) use a consistent lifecycle model—preventing stage drift and enabling deterministic tooling and certification.
Index Terms – finite‑state machine, lifecycle states, command execution, recovery states, evidence emission, idempotency, distributed systems.
Relationship to Other RFCs
| RFC | Acronym | Scope |
|---|---|---|
| RFC‑WF‑0003 | CCP | Command envelopes & confirmation semantics |
| RFC‑WF‑0006 | EAS | Evidence artifacts |
| RFC‑WF‑0008 | RCP | Recovery actions |
| RFC‑WF‑0010 | IDS | Replay‑safe execution |
| RFC‑WF‑0017 | TVRS | Conformance‑test mapping (TVRS/CATS) |
Implementations often diverge on lifecycle stages and transition ordering, breaking interoperability and audits. SMCL provides a single normative lifecycle FSM that:
- Standardizes state naming
- Constrains valid transitions
- Defines terminal states
- Specifies required evidence for each transition
- Formalizes idempotent re‑entry behavior under duplicates/retries
NOTE: SMCL does not define internal workflow engines; it defines observable behavior only.
The usual RFC normative keywords (MUST, MUST NOT, SHOULD, SHOULD NOT, MAY) apply.
Terminology
| Term | Definition |
|---|---|
| Primary Command | The original command requested by the user. |
| Recovery Command | A command that retries, cancels, reprocesses, or compensates a primary command. |
| Lifecycle State | The current stage in the FSM. |
| Transition | Allowed movement from one state to another. |
| Terminal State | A state after which no further execution transitions may occur (except governed recovery). |
Primary‑Command Lifecycle States
| State | Description |
|---|---|
| S0 – received | Raw input received (pre‑envelope). |
| S1 – canonicalized | Envelope created and persisted; command_id first exists. |
| S2 – confirmation_required | Confirmation requested (if mutating). |
| S3 – confirmed | Human confirmation gate satisfied. |
| S4 – authz_pending | Authorization evaluation pending. |
| S5 – authorized | Authorization granted. |
| S6 – rejected | Validation, authz deny, policy deny, or ambiguity (terminal). |
| S7 – started | Execution started; side effects may begin. |
| S8 – executed | Execution completed successfully (terminal). |
| S9 – failed | Execution failed (terminal for primary execution; recovery may follow). |
| S10 – canceled | Execution canceled / halted (terminal). |
| S11 – compensated | Compensation completed (terminal). |
Notes
- Read‑only commands MAY skip confirmation states (S2/S3).
- Some implementations may merge
authz_pending/authorized; if so, they MUST still expose semantically equivalent evidence and ordering. receivedis pre‑envelope and MUST NOT mutate state.canonicalizedis the earliest point wherecommand_idexists.confirmedindicates the human confirmation gate is satisfied.authorizedindicates scope/step‑up gates are satisfied.startedindicates execution has begun and side effects may occur.executedindicates effects are completed and consistent.failedindicates execution ended with error; recovery may be possible.compensatedindicates compensation achieved a defined terminal correction.
Allowed Transitions
The following transitions MUST be enforced:
received → canonicalized
canonicalized → confirmation_required (if mutating and not auto‑confirmed by policy)
confirmation_required → confirmed
canonicalized → authz_pending (read‑only or pre‑confirm validation path allowed)
confirmed → authz_pending
authz_pending → authorized
authz_pending → rejected
authorized → started
started → executed
started → failed
started → canceled
failed → compensated (only if compensation executed successfully)
executed → compensated (allowed only if business‑defined compensation exists and is governed)
Invalid Transitions
If an invalid transition is attempted (e.g., executed → started), the system MUST:
- Reject the transition.
- Emit evidence indicating
invalid_transition_attempt. - Preserve the prior terminal state.
Additional constraints:
- For any mutating command,
startedMUST NOT occur unlessconfirmedhas occurred (except an explicit, policy‑declared “safe auto‑confirm” which MUST be auditable and rare). - For any mutating command,
startedMUST NOT occur unlessauthorizedhas occurred.
Idempotency & Duplicate Handling
-
If the same logical command is delivered multiple times (same
idempotency_key):- Terminal state (
executed|rejected|canceled|compensated): the system MUST replay the outcome and MUST NOT re‑enter execution. - Started: duplicates MUST return an
in_progressview and MUST NOT create parallel executions.
- Terminal state (
-
A primary command MUST NOT re‑enter
startedonce it has reachedexecuted,rejected,canceled, orcompensated.
Recovery‑Command Rules
Recovery commands follow the same FSM with the following additional rules:
- Reference the
target_command_id. - Emit evidence linking to the target.
- Respect authorization/confirmation/step‑up according to risk class (RCP/ACSM/PPGP).
Compensation Model
target_commandis infailedorexecuted(depending on business semantics).- A recovery command executes the compensation plan.
target_commandenterscompensatedonly when the plan succeeds and evidence confirms convergence.
- Compensation MUST be append‑only and auditable.
Evidence Emission
For each lifecycle transition, the system MUST emit an evidence artifact containing at least:
lifecycle.command_idlifecycle.transition(e.g.,received→canonicalized)lifecycle.timestamplifecycle.evidence_type(e.g.,state_change,invalid_transition_attempt)- Any additional context required by the dependent RFCs (CCP, EAS, RCP, IDS).
The exact schema is defined in RFC‑WF‑0006 (EAS).
Conformance
- Minimal conformance tests are mapped in RFC‑WF‑0017 (TVRS/CATS).
- Implementations MUST pass all TVRS test vectors that exercise each state, transition, terminal condition, and evidence emission requirement.
Security & Privacy Considerations
- All evidence artifacts MUST be signed and tamper‑evident.
- Sensitive fields (e.g., user identifiers) MUST be redacted or encrypted per the privacy policy defined in RFC‑WF‑0003 (CCP).
IANA Considerations
- No IANA actions are required.
References
- [RFC‑WF‑0003] Command Envelopes & Confirmation (CCP)
- [RFC‑WF‑0006] Evidence Artifacts (EAS)
- [RFC‑WF‑0008] Recovery Actions (RCP)
- [RFC‑WF‑0010] Replay‑Safe Execution (IDS)
- [RFC‑WF‑0017] Test Vector Reference Suite (TVRS/CATS)
Lifecycle State Mapping
| State | Corresponding Command / Event |
|---|---|
canonicalized | command.accepted |
confirmation_required | command.confirmation.requested |
confirmed | command.confirmation.satisfied |
authorized / rejected | authz.decided (allow / deny) |
started | execution.started |
executed / failed / rejected | execution.executed | execution.failed | execution.rejected |
compensated | compensation.compensated |
Trace bindings: (conversation_id, message_ids)
Security decisions: include authz, step‑up, and confirmation when relevant.
X. Observability Requirements (OoC Compatibility)
OoC MUST be able to report, at minimum:
- Current lifecycle state.
- Last transition timestamp.
- Terminal outcome (if the state is terminal).
- Reason for rejection / failure (policy / reason code).
- Next allowed recovery options (if any).
An SMCL‑compliant implementation MUST pass tests that validate:
- Invalid transition rejection – attempts to move to an illegal state are denied.
- Ordering invariants – e.g., no
startwithout priorconfirm+authorize. - Duplicate handling – re‑sending a command does not re‑enter execution.
- Evidence emission – required artifacts are emitted at each mandated transition.
These tests SHOULD be represented as TVRS (Test Vectors & Reference Scenarios) scenarios.
Related Specifications
| Spec | ID | Purpose |
|---|---|---|
| Conversational Command Protocol (CCP) | 0003 | Defines envelope creation and confirmation; SMCL fixes ordering / stages. |
| Evidence Artifact Schema (EAS) | 0006 | Defines artifact structure; SMCL defines when artifacts must be emitted. |
| Recovery & Compensation Protocol (RCP) | 0008 | Defines recovery operations; SMCL defines their lifecycle constraints. |
| Idempotency & Delivery Semantics (IDS) | 0010 | Defines replay‑safe execution; SMCL defines re‑entry rules. |
| Test Vectors & Reference Scenarios (TVRS) | 0017 | Supplies conformance scenarios for lifecycle behavior. |
Security & Consistency Notes
- Lifecycle inconsistencies (e.g., “start before authz”) can create bypasses.
- Implementations MUST enforce invariants and log invalid attempts as evidence artifacts.
- Terminal‑state protection is critical to prevent replay abuse and “double‑effect” attacks.
SMCL provides the deterministic backbone for “WhatsApp‑first” execution semantics: a canonical FSM that standardizes lifecycle states, transitions, evidence‑emission points, and idempotent re‑entry behavior. This prevents lifecycle drift across services and enables reliable observability, recovery, and certification tooling.
References
- RFC‑WF‑0003, Conversational Command Protocol (CCP).
- Evidence Artifact Schema (EAS).
- Recovery & Compensation Protocol (RCP).
- Idempotency & Delivery Semantics (IDS).
- Test Vectors & Reference Scenarios (TVRS).
Keywords: finite‑state machines, lifecycle invariants, terminal‑state protection, evidence emission mapping, idempotent re‑entry rules, recovery/compensation state modeling, conformance testing.