v4 State Machines¶
Status: Proposed for v4 implementation
Last updated: 2026-07-29
Every transition is persisted with operation/idempotency id and emits the named secret-free audit event. “Failure state” is durable when external mutation may have occurred; otherwise the operation returns to its pre-state.
Key lifecycle¶
stateDiagram-v2
[*] --> PENDING
PENDING --> PRIMARY: provider confirmed + CAS
PENDING --> DISABLED: abandon + provider confirm
PRIMARY --> DECRYPT_ONLY: replacement primary confirmed
DECRYPT_ONLY --> PRIMARY: explicit rollback + CAS
DECRYPT_ONLY --> DISABLED: retention elapsed
DISABLED --> DECRYPT_ONLY: approved recovery
DISABLED --> DESTROYED: destroy gates + provider confirm
DESTROYED --> [*]
Transition |
Preconditions / operation |
Success / failure state |
Retry safety, audit, rollback |
|---|---|---|---|
create → |
Idempotency key; provider accepts create |
|
Retry only provider-idempotent request; |
|
Exact version enabled, wrap/unwrap capable; no competing primary; generation CAS |
Sole |
Same CAS id safe; |
|
No envelope uses version; provider confirms disable |
|
Idempotent disable; |
|
New primary already confirmed; CAS |
Old |
Idempotent by generation; |
|
Policy/dual control; provider enabled; no competing primary |
|
CAS-safe; |
|
Retention/inventory gates; not sole required decrypt version |
|
Provider-idempotent; |
|
Not destroyed; recovery approval; provider re-enabled |
|
Reconcile provider state; |
|
Earliest time, inventory, retention, dual approval, audit checkpoint |
terminal |
Never blind retry; |
PRIMARY → DESTROYED, multiple primaries, any transition from DESTROYED, and
promotion from local metadata alone are invalid and audited as denied.
Envelope processing¶
stateDiagram-v2
[*] --> FRAMING
FRAMING --> STRUCTURED: fixed preamble and limits pass
STRUCTURED --> POLICY_ACCEPTED: canonical header and policy pass
POLICY_ACCEPTED --> KEY_READY: fresh or unwrapped DEK
KEY_READY --> CONTEXT_BOUND: keyed commitment created or verified
CONTEXT_BOUND --> PROCESSING
PROCESSING --> AUTHENTICATED: final record verifies
AUTHENTICATED --> COMMITTED
FRAMING --> REJECTED
STRUCTURED --> REJECTED
POLICY_ACCEPTED --> REJECTED
KEY_READY --> REJECTED
CONTEXT_BOUND --> REJECTED
PROCESSING --> REJECTED
Transition |
Preconditions / operation |
Success / failure |
Retry, audit, rollback |
|---|---|---|---|
start → |
Fixed input handle/bytes |
bounded preamble; invalid → |
Read-only retry safe; |
|
Checked lengths within hard limits |
restricted deterministic-CBOR model; malformed → rejected |
Deterministic; |
|
Version/suite/critical/quota/context requirements/provider allowed |
accepted; denial → rejected before provider |
Re-evaluate only same policy id; |
|
Seal generates fresh DEK; open unwraps pinned version using protected-header bytes |
internal DEK; transient provider failure remains retryable pre-processing |
RFC-0006 retry; |
|
Canonical caller context; derived context-binding key |
Seal stores keyed commitment then wraps with completed header; open constant-time verifies commitment; mismatch rejected |
New seal DEK on retry; |
|
|
records processed; any auth/order/I/O/cancel → rejected |
Open read retry safe; call idempotent sink abort |
|
Final record/manifest verified |
authenticated uncommitted sink; failure rejected |
No retry from partial state unless sealed resumable profile later; |
|
Sink and output policy checks pass |
sink commit or one-shot bytes return; commit failure enters typed I/O failure |
Exactly-once commit; |
Streaming encryption¶
States are INIT → SINK_OPEN → DEK_READY → CONTEXT_COMMITTED → KEY_WRAPPED → HEADER_WRITTEN → CHUNKS → FINAL_AUTHENTICATED → COMMITTED. Before
CONTEXT_COMMITTED, policy and immutable provider version must pass and a fresh
DEK must exist. Context is canonicalized and committed with a DEK-derived key;
provider wrapping then binds the completed protected-header bytes. Each
CHUNKS transition reads at most the policy chunk, increments exactly one
index, authenticates index/length/final flag/header digest, and performs one
bounded sink write.
Final authentication is followed by exactly one sink commit. Authentication,
context, quota, cancellation, provider, or I/O failure invokes idempotent abort;
existing destination remains unchanged. A retry is a new envelope with a new
DEK/idempotency key unless no provider mutation occurred. Events:
stream.seal.started, per-policy coarse progress, stream.seal.completed or
stream.seal.failed. Rollback never deletes caller source.
Streaming decryption¶
States are INIT → SINK_OPEN → HEADER_ACCEPTED → KEY_UNWRAPPED → CONTEXT_VERIFIED → CHUNKS_STAGED → FINAL_AUTHENTICATED → COMMITTED.
Provider unwrap binds the protected-header bytes without receiving context.
After unwrap, the derived keyed commitment is recomputed from caller context and
compared in constant time; mismatch aborts before plaintext writes. Each record
must be the next index, within declared/actual limits, and nonempty unless final.
Missing/duplicate/reordered/trailing records transition to FAILED.
Plaintext remains uncommitted in the TransactionalSink through
CHUNKS_STAGED; exactly one commit follows FINAL_AUTHENTICATED. Every failure
or cancellation invokes idempotent abort and leaves pre-existing output
unchanged. Open is read-only/provider-idempotent and may restart from byte zero;
partial plaintext is never resumed. Events:
stream.open.started/completed/failed.
Rotation¶
stateDiagram-v2
[*] --> PLANNED
PLANNED --> CREATED_PENDING
CREATED_PENDING --> CONFIRMED
CONFIRMED --> PROMOTED
PROMOTED --> OLD_DEMOTED
OLD_DEMOTED --> REWRAPPING
REWRAPPING --> OBSERVING
OBSERVING --> COMPLETE
CREATED_PENDING --> RECONCILING
CONFIRMED --> RECONCILING
PROMOTED --> RECONCILING
Transition |
Preconditions / operation |
Failure and retry |
Audit / rollback |
|---|---|---|---|
plan → pending |
Policy, approvals, unique operation/generation |
Creation ambiguity → reconcile; retry only idempotent |
|
pending → confirmed |
Fresh provider description exact version/capability |
Stay/reconcile; never local promotion |
|
confirmed → promoted |
CAS makes sole primary |
CAS loser reconciles to winning primary |
|
promoted → old demoted |
New primary independently confirmed |
Block completion if demotion uncertain |
|
demoted → rewrapping |
Durable inventory/idempotency queue |
Per-envelope failures retained, bounded retry |
|
rewrapping → observing → complete |
Required coverage/soak/retention met |
Remain observing; no premature disable/destroy |
|
Rewrap¶
States: PARSED → POLICY_ACCEPTED → SOURCE_DEK_UNWRAPPED → DESTINATION_VERSION_CONFIRMED → DESTINATION_WRAPPED → RECIPIENT_AUTH_UPDATED → VERIFIED → COMMITTED.
Preconditions are canonical v4 envelope, allowed source/destination providers,
immutable versions, and idempotency key. Ciphertext records are copied exactly.
Same source/destination version returns the canonical original and is idempotent.
Any failure before commit returns the original unchanged and releases the DEK.
Ambiguous destination wrap reconciles through provider semantics; it is never
blindly duplicated. VERIFIED checks recipient/header integrity, exact
ciphertext digest equality, and metadata; content status is “preserved, not
reverified” unless actually verified. Events are
rewrap.started/completed/failed; rollback discards the new envelope.
Migration¶
stateDiagram-v2
[*] --> INVENTORIED
INVENTORIED --> DRY_RUN_VALID
DRY_RUN_VALID --> BACKUP_CONFIRMED
BACKUP_CONFIRMED --> STAGED
STAGED --> REENCRYPTED
REENCRYPTED --> VERIFIED
VERIFIED --> PROMOTED
PROMOTED --> RECEIPTED
RECEIPTED --> COMPLETE
STAGED --> FAILED_RESUMABLE
REENCRYPTED --> FAILED_RESUMABLE
VERIFIED --> FAILED_RESUMABLE
PROMOTED --> RECONCILE
Transition |
Preconditions / operation |
Failure/retry |
Audit/rollback |
|---|---|---|---|
inventory/dry run |
Named format, source digest, quotas, deadline, context/key capacity |
Quarantine malformed; retry read-only with same digest |
|
backup → staged |
Caller backup confirmation; destination/link policy; durable id |
Collision fails; same id/digest resumes |
|
staged → reencrypted |
Declared legacy decrypt then v4 seal |
Auth/provider/cancel → resumable/failed, no promotion |
|
reencrypted → verified |
Independent v4 reopen and keyed stream digest/length compare |
Verification failure quarantines output |
|
verified → promoted |
Fsync and atomic same-filesystem replace |
Ambiguous crash → reconcile filesystem/digests |
|
promoted → receipted/complete |
Durable receipt and audit checkpoint |
Mandatory sink failure → reconcile, not false success |
|
Source deletion is not a transition in this machine.
Provider health¶
States are UNKNOWN, HEALTHY, DEGRADED, UNAVAILABLE, and
MISCONFIGURED. Explicit health check maps successful full check to HEALTHY,
partial/rate-limited dependency to DEGRADED, transient reachability to
UNAVAILABLE, permanent credential/config to MISCONFIGURED, and cancelled/
unclassifiable to UNKNOWN. Checks are read-only and retry only under RFC-0006.
provider.health records safe state/latency bucket. Health transitions have no
cryptographic rollback and never override actual call/policy results.
Release maturity¶
ALPHA → BETA → RC1_FROZEN → AUDITED → REMEDIATION_VALIDATED → SOAKED → STABLE follows RFC-0010. Any failed gate remains at the prior state;
format/API freeze exception returns to BETA for affected evidence. Promotion
requires linked artifacts/approvals and is not retryable by workflow alone.
release.promoted records commit/artifact digests and approvers; rollback
withdraws/quarantines artifacts but never reuses a version.