Skip to main content

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

Call continue_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

When continue_as_new() is called:
  1. Current run is marked as CONTINUED_AS_NEW
  2. A WORKFLOW_CONTINUED_AS_NEW event is recorded
  3. A new run is created with continued_from_run_id set
  4. The new run starts executing with the provided arguments
  5. New run has fresh, empty event history

Patterns

Polling Workflow

Recurring Task with Sleep

Bounded Iterations

Tracking Workflow Chains

Use get_workflow_chain() to retrieve all runs in a continuation chain:

Workflow Run Schema

The WorkflowRun schema includes continuation tracking fields:

Important Behaviors

Arguments Are Required

continue_as_new() requires at least one argument:
Unlike some workflow systems, PyWorkflow does not automatically use the original arguments. You must explicitly pass all arguments needed for the next execution.

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 a WORKFLOW_CONTINUED_AS_NEW event:
View continuation events with the CLI:

Best Practices

Any workflow that could run indefinitely (polling, queues, recurring tasks) should use continue_as_new() to prevent unbounded event history growth.
Only pass the state needed for the next execution. Large payloads increase storage and serialization costs.
Include counters or timestamps to track overall progress across the chain:
Always have a termination condition that returns normally:

API Reference

continue_as_new()

Complete the current workflow and start a new execution with fresh event history. Raises:
  • ContinueAsNewSignal - Internal signal caught by the executor
  • ValueError - If no arguments are provided
  • RuntimeError - If called outside a workflow context
  • CancellationError - If workflow is being cancelled

get_workflow_chain()

Get all workflow runs in a continuation 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.