﻿# Temporal Continue-As-New carries state after handlers finish

Temporal Continue-As-New starts a fresh run and history under the same Workflow ID; pass the needed state explicitly and finish message handlers before the transition.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/guide-temporal-continue-as-new-handlers/
Language: en

## Identify why the process needs a new run

A research coordinator processes repeated requests for the same project and accumulates a long history. The [Python Continue-As-New guide](https://docs.temporal.io/develop/python/workflows/continue-as-new) provides a transition that closes the current execution successfully and starts a new run with fresh history. This can keep a long-lived logical process manageable. It does not mean the application should forget every decision or restart the user's completed work.

## Carry the required state through parameters

The guide asks the workflow author to design input parameters that can receive current state from the preceding run. Decide which project configuration, pending work and deduplication information the next run needs. Ordinary local variables do not become a new input contract merely because the code calls Continue-As-New. Keep the carried structure explicit and reviewable so a later schema change does not silently lose the facts needed to resume the logical task correctly.

## Drain message handlers before leaving

The [message-passing guide](https://docs.temporal.io/develop/python/workflows/message-passing) notes that an asynchronous Signal or Update handler may still be awaiting an Activity when the main workflow returns or continues. Closing then can interrupt important work and prevent clients receiving Update results. The documented pattern waits for `workflow.all_handlers_finished`. Perform the transition from the main workflow after handlers finish, rather than calling it from inside a handler and assuming its remaining work will migrate automatically.

## Keep workflow and run identities distinct

The [identity guide](https://docs.temporal.io/workflow-execution/workflowid-runid) describes a chain retaining its Workflow ID while run identity changes. An interface following the project should distinguish that logical identity from a specific run's evidence. Record which run handled an Update and which run now owns the ongoing process. A fresh event history is an operational boundary, not evidence that earlier artifacts or external operations disappeared.

## Test the handoff before production-length history

The Python guide recommends a small test threshold so the transition can be exercised without waiting for a naturally long execution. Use a harmless pending request and verify carried state, completed handler results and the new run's next action. [Task contracts](/journal/learn-codex-task-contract/) identify the continuity required; [tool observations](/journal/learn-codex-tool-observation/) establish what crossed the boundary. A successful test demonstrates deliberate continuation rather than simply observing that another run exists.
