<ContinueAsNew> solves this by closing the current run cleanly and immediately starting a fresh one, optionally carrying state across the boundary.
The new run begins with a clean history. From the outside it looks like the same workflow is still running. Inside, the state you passed arrives as ctx.input.__smithersContinuation.payload.
Import
continueAsNew(state?) is a convenience helper that returns a <ContinueAsNew> element. Both forms are identical in behavior.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
state | unknown | undefined | Optional JSON-serializable payload carried into the next run as ctx.input.__smithersContinuation.payload. |
Basic usage
Unconditionally hand off to a fresh run:Carrying state into the next run
Pass a JSON-serializable object via thestate prop. The next run receives it at ctx.input.__smithersContinuation.payload:
Conditional continuation
Most workflows only continue-as-new under certain conditions — for example, after a fixed number of iterations or when a sentinel value signals the end of input:Combined with Loop
A<Loop> is the right tool when the number of iterations is bounded and known at design time. Use <ContinueAsNew> when the workflow genuinely needs to run indefinitely or when total iteration count is unknown:
MAX_PER_RUN iterations via the loop, then hands off to a fresh run, keeping event history bounded in both dimensions.
Behavior
- When the scheduler encounters
<ContinueAsNew>, it signals the current run to close with statuscontinued. - The engine emits a
RunContinuedAsNewevent and immediately starts a new run of the same workflow. - If
stateis provided, it is serialized to JSON. Non-serializable payloads fail the run synchronously at render time. - The new run receives the payload at
ctx.input.__smithersContinuation.payload. - Any tasks or nodes rendered after
<ContinueAsNew>in the same sequence do not execute — the handoff happens immediately. - The workflow id is preserved across continuations. Only the run id increments.
Rendering
<ContinueAsNew> renders as a smithers:continue-as-new host element.
Notes
- Use
<ContinueAsNew>for workflows that run indefinitely (daemons, pollers, event processors). For bounded iteration,<Loop>is simpler. - The
statepayload must be JSON-serializable. Classes, functions,undefinednested inside objects, and circular references are not supported. - Access the carried payload via
ctx.input.__smithersContinuation.payload. Type-cast as needed since the input type does not include this field by default. - Temporal imposes a maximum event history size (default 50,000 events / 50 MB).
<ContinueAsNew>before approaching this limit is the recommended mitigation. - The
continueAsNew(state?)helper is interchangeable with<ContinueAsNew state={state} />— choose whichever reads more clearly in context.