Fix timer usage inside workflow functions. Search `"use workflow"` functions for `setTimeout`, `setInterval`, `timers/promises`, polling loops, or `AbortSignal.timeout()`. Replace workflow delays with `await sleep("5s")`, `await sleep("24h")`, or `await sleep(date)` from `workflow`. For polling, use a workflow loop that calls a `"use step"` helper to check external state and then `await sleep(...)` between attempts. If a step itself needs a short in-process delay, keep that timer inside the `"use step"` function only. Verify the workflow can replay and resume after the durable sleep.
This error occurs when you try to use setTimeout(), setInterval(), or related timing functions directly inside a workflow function.
Timeout functions like "setTimeout" and "setInterval" are not supported in workflow functions. Use the "sleep" function from "workflow" for time-based delays.
Workflow functions run in a sandboxed environment where timing functions like setTimeout() and setInterval() are not available. These functions rely on asynchronous scheduling that would break the deterministic replay guarantees that workflows depend on.
When a workflow suspends and later resumes, it replays from the event log. If timing functions were allowed, the replay would produce different results than the original execution.
Use the sleep function from the workflow package for time-based delays. Unlike setTimeout(), sleep is tracked in the event log and replays correctly.
Before:
workflows/delayed.ts
export async function delayedWorkflow() { "use workflow"; // Error - setTimeout is not available in workflow functions await new Promise(resolve => setTimeout(resolve, 5000)); return 'done';}
After:
workflows/delayed.ts
import { sleep } from 'workflow';export async function delayedWorkflow() { "use workflow"; // sleep is tracked in the event log and replays correctly await sleep('5s'); return 'done';}