Skip to content

Workflow and Context ​

Workflow, Operation, Work, Event, and Query are the durable contracts. WorkflowExecution<E> is passed to a workflow handler and exposes the complete operation layer directly.

Construction ​

APICreates
Workflow<I, O, E>(...)Workflow definition backed by three Schema values
Operation<I, O, E>(...)Automated-operation definition backed by three Schema values
Work<I, R>(...)Assigned-work request and response contract
Event<P>(...)External-event contract
WorkflowDocument.compileJson(document)Compiled JSON document
document.compile()Compile an existing WorkflowDocument
QueryTyped read-only query contract

Schema construction ​

Schema<T> is the workflow-facing wrapper. Build its jsonSchema with package:json_schema_builder, which owns Draft 2020-12 types, constraints, composition, references, formats, and validation. Use @JsonSerializable(createJsonSchema: true) when the Dart model should generate its codec and structural schema from one declaration.

The wrapper is enforced, not merely published for tooling. Schema.decode validates incoming JSON before constructing a Dart value; Schema.encode validates generated JSON before it can be persisted or returned. The runtime applies this rule to workflows, operations, work, events, queries, expected failures, and child workflows. Failures report the schema key, encode/decode direction, and JSON Schema violations.

Custom Schema<T> declarations must provide jsonSchema; there is no implicit permissive schema. Schema.identity is for JSON-native values and accepts an explicit structural schema. Its omitted-schema form deliberately means unconstrained JSON. Schema.never declares the impossible failure seam of an infallible workflow or operation.

Context Actions ​

ActionMeaning
performAutomated side effect with retry, timeout, idempotency, and annotations
requestRequest assigned durable work and wait for a response
waitForEventWait for a named typed external event
sleepDurable timer
parallel / race / quorumStructured concurrency
forEachKeyed durable fan-out
sagaReverse-order compensation
workflow / spawn / joinChild workflows
queryPublish a typed read-only snapshot
continueAsNewClose and create the successor

continueAsNewSuggested is true once history reaches the soft limit.

See Also ​