Overview
Long-running workflows can accumulate large event histories that impact performance.continue_as_new() solves this by completing the current workflow and immediately starting a fresh execution with clean event history.
Fresh Event History
Each continuation starts with a clean event log.
Chain Tracking
Workflow runs are linked via
continued_from_run_id and continued_to_run_id.State Preservation
Pass state to the new execution via arguments.
Unlimited Duration
Run workflows indefinitely without unbounded history growth.
When to Use Continue-As-New
continue_as_new() is ideal for:
Basic Usage
Callcontinue_as_new() with the arguments for the new execution:
continue_as_new() never returns - it raises an internal signal that the executor catches. Any code after it will not execute.How It Works
Whencontinue_as_new() is called:
- Current run is marked as
CONTINUED_AS_NEW - A
WORKFLOW_CONTINUED_AS_NEWevent is recorded - A new run is created with
continued_from_run_idset - The new run starts executing with the provided arguments
- New run has fresh, empty event history
Patterns
Polling Workflow
Recurring Task with Sleep
Bounded Iterations
Tracking Workflow Chains
Useget_workflow_chain() to retrieve all runs in a continuation chain:
- Python API
- CLI
Workflow Run Schema
TheWorkflowRun schema includes continuation tracking fields:
Important Behaviors
Arguments Are Required
continue_as_new() requires at least one argument:
Child Workflows Are Cancelled
When a parent workflow continues as new, all running child workflows are cancelled:Cancellation Takes Precedence
If a workflow is cancelled,continue_as_new() will raise CancellationError instead:
Status is Terminal
CONTINUED_AS_NEW is a terminal status like COMPLETED or FAILED:
Events
The continuation is recorded as aWORKFLOW_CONTINUED_AS_NEW event:
Best Practices
Use for unbounded workflows
Use for unbounded workflows
Any workflow that could run indefinitely (polling, queues, recurring tasks) should use
continue_as_new() to prevent unbounded event history growth.Pass minimal state
Pass minimal state
Only pass the state needed for the next execution. Large payloads increase storage and serialization costs.
Include progress tracking
Include progress tracking
Include counters or timestamps to track overall progress across the chain:
Handle the final iteration
Handle the final iteration
Always have a termination condition that returns normally:
API Reference
continue_as_new()
Raises:
ContinueAsNewSignal- Internal signal caught by the executorValueError- If no arguments are providedRuntimeError- If called outside a workflow contextCancellationError- If workflow is being cancelled
get_workflow_chain()
Returns: List of
WorkflowRun objects ordered from first to last in the chain.
Next Steps
Sleep
Learn about durable sleep for delays.
Hooks
Wait for external events in your workflows.
Fault Tolerance
Automatic recovery from worker crashes.
CLI Guide
Manage workflows from the command line.