- is
Scheduledto run for the third time in an hour - is
Latebecause the associated worker process is not responding - was
Scheduledto run, but laterCancelledvia button in the UI - was
Cachedfrom a previous run instead ofRunningagain - has
CompletedafterRunningamong its fellow task runs - ended up
Failedbecause Claude left pydantic 1.x syntax in your code - ended up
Crashedbecause you Ctrl-C’d the process
Only runs have states:
Flows and tasks are templates that describe what a system does;
only when we run the system does it also take on a state.
State types
Prefect states have names and types. A state’s name is often, but not always, synonymous with its type. For example, a task run that is running for the first time has a state with the name Running and the typeRUNNING. However, if the task retries,
that same task run will have the name Retrying and the type RUNNING.
State types drive orchestration logic, whereas state names provide visual bookkeeping.
The full list of states and state types includes:
State transitions
When a flow run changes states, you can often tell if it is behaving normally or not. Here are some common state transitions and what they mean:Final state determination
The final state of a flow or task run depends on a number of factors; generally speaking there are three categories of terminal states:COMPLETED: a run in anyCOMPLETEDstate did not encounter any errors or exceptions and returned successfullyFAILED: a run in anyFAILEDstate encountered an error during execution, such as a raised exceptionCRASHED: a run in anyCRASHEDstate was interrupted by an OS signal such as aKeyboardInterruptor an unexpectedSIGTERM
States are represented by their name, with boxes behind states clarifying their underlying type. Dotted lines lead to terminal states.
Task return values
A task will be placed into aCompleted state if it returns any Python object, with one exception:
if a task explicitly returns a Prefect Failed state, the task will be marked Failed.
return_state flag:
Flow return values
The final state of a flow is determined by its return value. The following rules apply:- If an exception is raised directly in the flow function, the flow run is marked as
FAILED. - If a flow returns a manually created state, it is used as the state of the final flow run. This allows for manual determination of final state.
- If a flow returns an iterable of states, the presence of any
FAILEDstate will cause the run to be marked asFAILED.
COMPLETED.
State change hooks
State change hooks execute code in response to client side changes in flow or task run states, enabling you to define actions for specific state transitions in a workflow. State hooks have the following signature:Further reading
- See examples of how to execute code in response to entering states in your flows and tasks.