Timeouts
Workflow-level timeouts let you bound how long a workflow is allowed to run. There are two timeout scopes:
- Execution timeout — caps the total wall-clock time across all runs of a workflow instance, including continue-as-new transitions. The deadline is computed once at start and carried forward unchanged.
- Run timeout — caps a single run. The deadline is recomputed each time a new run begins (including continue-as-new).
Both are optional and can be combined.
Configuration
Timeouts are configured through StartOptions when starting a workflow:
use Workflow\V2\StartOptions;
use Workflow\V2\WorkflowStub;
$workflow = WorkflowStub::make(MyWorkflow::class, 'order-123');
$workflow->start(
$orderId,
StartOptions::rejectDuplicate()
->withExecutionTimeout(7200) // 2 hours across all runs
->withRunTimeout(3600), // 1 hour per run
);
Execution timeout
The execution timeout spans the entire workflow instance. If the workflow uses continue-as-new, the deadline stays the same across every run in the chain.
StartOptions::rejectDuplicate()->withExecutionTimeout(86400); // 24 hours
The timeout value is stored on the WorkflowInstance model and the computed deadline is snapped on every WorkflowRun.
Run timeout
The run timeout applies to a single run. When a workflow continues as new, the new run gets a fresh deadline computed from the current time plus the configured run timeout.
StartOptions::rejectDuplicate()->withRunTimeout(1800); // 30 minutes per run
Validation
Timeout values must be at least 1 second. Passing zero or a negative value throws a LogicException:
// Throws LogicException: "Workflow v2 execution timeout must be at least 1 second."
StartOptions::rejectDuplicate()->withExecutionTimeout(0);
Control plane
Timeouts can also be set when starting a workflow through the control plane:
$controlPlane->start('my-app.order-workflow', 'order-123', [
'execution_timeout_seconds' => 7200,
'run_timeout_seconds' => 3600,
]);
The describe response includes timeout and deadline fields:
$description = $controlPlane->describe('order-123');
$description['execution_timeout_seconds']; // 7200
$description['run']['run_timeout_seconds']; // 3600
$description['run']['execution_deadline_at']; // ISO 8601 timestamp
$description['run']['run_deadline_at']; // ISO 8601 timestamp
Waterline
When timeouts are configured, the run detail view in Waterline displays the timeout durations and their computed deadlines.
History
The WorkflowStarted history event payload includes timeout and deadline fields when configured:
{
"execution_timeout_seconds": 7200,
"run_timeout_seconds": 3600,
"execution_deadline_at": "2026-04-12T14:00:00+00:00",
"run_deadline_at": "2026-04-12T13:00:00+00:00"
}
Continue-as-new
When a workflow continues as new:
- The execution deadline is carried forward unchanged from the previous run.
- The run timeout value is carried forward, but the run deadline is recomputed from the current time.
This means the execution timeout always measures from the original start, while each new run gets its own fresh run-timeout window.
Enforcement
Workflow-level timeouts are enforced at two points:
- At workflow task start — every workflow task checks
deadlineExpired()before executing the workflow. If the deadline has passed, the run is immediately timed out. - By the TaskWatchdog — the watchdog scans for non-terminal runs whose execution or run deadline has passed but that have no open workflow task. When found, it creates a deadline-expired workflow task and dispatches it, which triggers the timeout on the next task execution.
When a timeout fires, the engine:
- Cancels all open tasks (activity, timer, workflow) except the current one
- Cancels all open activity executions with
ActivityCancelledhistory events - Cancels all pending timers with
TimerCancelledhistory events - Records a
WorkflowFailurewithfailure_category = timeoutand aWorkflowTimeoutException - Records a terminal
WorkflowTimedOuthistory event withtimeout_kindset toexecution_timeoutorrun_timeout - Applies parent-close policy to any open child workflows
- Notifies parent workflows if this was a child run
The failure row stores Workflow\V2\Exceptions\WorkflowTimeoutException as the exception class, carrying the timeout_kind and the deadline timestamp for programmatic inspection.
Timeout outcome and cleanup
With the default hard-timeout policy, a workflow deadline closes the run with status failed and
closed_reason = timed_out. WorkflowTimedOut is the terminal history event.
The runtime records WorkflowTimeoutException as failure data. It does not
throw that exception into the workflow body or resume workflow code for cleanup.
Workflow catch and finally blocks and registered saga compensations do not
run when the engine enforces this deadline.
Cancelling an activity's durable execution does not undo an external side effect or prove that its callback stopped. Use idempotent operations and application-owned reconciliation for effects that may already have committed.
When cleanup must follow an application deadline, use a shorter durable timer or timeout-backed wait that lets workflow code run compensation before closure. Leave time for activity retries, worker scheduling and cleanup before either the run or execution deadline. The engine timeout remains the final backstop. A delayed worker can reach that backstop before compensation finishes.
The immediate cancel() and terminate() commands also close the run without
a workflow cleanup window. The separate cooperative requestCancellation()
operation can deliver bounded cleanup to a compatible worker while the run is
still active. A workflow timeout does not automatically become a cooperative
cancellation request, and a cancellation shield does not extend an execution
or run deadline. See Cancel and Terminate and
Cooperative Cancellation.
Experimental deadline-triggered cleanup
Experimental. Embedded queue workers support this option from Workflow
2.29.0; embedded poll-mode starts refuse it. Service mode supports it from
native Server 3.30.0 with supporting workers, as described below. The option
is an experimental surface under the
stability levels, with no
backward-compatibility promise yet. Runs that do not opt in keep the default
hard-timeout behavior above.
Before enabling this option in embedded mode, install Workflow 2.29.0 or later,
run the application migrations, and deploy compatible embedded queue workers.
The new migration adds workflow_runs.timeout_cleanup_work_deadline_at; it
does not opt existing runs in. Do not enable the option before the migration
completes.
php artisan migrate
Reserve a finite part of the existing hard timeout when starting a run:
use Workflow\V2\StartOptions;
use Workflow\V2\WorkflowStub;
WorkflowStub::make(MyWorkflow::class, 'order-123')->start(
$orderId,
StartOptions::rejectDuplicate()
->withExecutionTimeout(70)
->withTimeoutCleanup(10),
);
Chain withTimeoutCleanup() after withExecutionTimeout() or
withRunTimeout(); calling it first throws because no hard timeout is set yet.
timeoutCleanupSeconds: is the constructor alternative. The allowance must be
1–86400 seconds, requires an execution or run timeout, and must be smaller than
every configured hard timeout. Passing null leaves the default policy.
In this example, ordinary work gets 60 seconds and cleanup may use the last 10 seconds inside the original 70-second hard cap. The allowance never adds time after that cap. If both hard deadlines apply, the earlier one bounds cleanup. Late detection, retries, worker replacement and lease renewal do not refresh any deadline. Continue-as-new and redrive preserve the admitted allowance and original execution clocks; each run derives its own run clocks.
When a worker observes the work deadline, the run enters cleanup once and
records WorkflowTimeoutCleanupStarted. If no worker observes it before the
hard deadline, that event is never written and the expired outcome has no
started_at. At its next unresolved durable wait, compatible workflow code
receives WorkflowTimeoutCleanupRequested, a subtype of
WorkflowCancellationRequestedException with cancellation cause: timeout.
Handle that interruption to run registered saga compensation or protected
cleanup; compensate() uses its cancellation shield. The shield does not
extend the hard cap. See Sagas.
Cleanup has a separate timeout_cleanup.outcome:
| Outcome | Meaning |
|---|---|
completed | Workflow code returned, or rethrew the timeout interruption, before the cleanup deadline. It does not prove cleanup code ran. A returned value does not become the business result. |
failed | Cleanup threw another exception; failure_id links the cleanup failure. |
expired | The hard cap arrived before cleanup finished, including when no worker could run it. |
preempted | Immediate cancel() or terminate(), or a hard deadline before the cleanup deadline, interrupted cleanup; the preempting outcome remains terminal. |
completed does not prove that cleanup code ran, in embedded and service mode
alike. The interruption is delivered at the next durable wait (activity,
timer, child, signal, condition or selection) whose result was not already in
history when cleanup started, never in a side effect or inside
cancellationShield(). If the wait the workflow is blocked on had already
resolved, for example a timer that fired or an activity that completed,
workflow code can return without receiving the interruption, and the outcome
is still completed. History then shows WorkflowTimeoutCleanupStarted with
no CooperativeCancellationDelivered after it. Make compensation that must
always run idempotent, and run it on every path that can return after the work
deadline, for example by comparing workflow time with the deadline the run was
admitted with, not only in the interruption handler.
Completed, failed or expired cleanup still ends with business status failed,
closed_reason = timed_out and WorkflowTimedOut. Successful compensation does
not turn that timeout into a successful workflow. When cleanup completes early,
the run closes right away, but the timed-out message still cites the original
hard-deadline time.
Read the cleanup outcome from history. The timeout_cleanup payload on the
terminal WorkflowTimedOut, WorkflowTerminated or WorkflowCancelled event,
also included in php artisan workflow:v2:history-export output, is the
authoritative record. From Workflow 2.40.0, and on native Server 3.30.0 and
later, describe reports the recorded state under run.timeout_cleanup, and run
detail and the bounded run observation that Waterline reads report it as
top-level timeout_cleanup. While cleanup is open, it shows outcome: running
with cause: timeout, the timeout kind, the detection time and the work and
cleanup deadlines. After closure, it shows the terminal outcome, with
failure_id for failed. The field is omitted when no cleanup was recorded.
List views do not show the cleanup state yet, so open run detail.
Unavailable or delayed workers cannot guarantee an external cleanup effect; keep compensation idempotent and reconcile uncertain effects in your application.
In embedded mode, bridge workers cannot claim an opted-in run; the claim
returns timeout_cleanup_not_supported without taking the lease.
Service mode. Native Server 3.30.0 and later accepts
timeout_cleanup_seconds on service starts and start_child_workflow
commands, with the same limits as the embedded allowance, and advertises
timeout_cleanup: {supported: true, version: 1}. It admits an opted-in start
only when a live worker on the task queue advertises the capability.
Otherwise it answers 422 timeout_cleanup_not_supported, writes nothing and
never falls back to a plain hard timeout. Workers with cooperative
cancellation enabled advertise the capability from PHP SDK 3.31.0 (3.32.0 for
the stricter marker rule below), Python SDK 2.24.0 and Rust SDK 4.25.0.
Workflow code receives the SDK's cooperative-cancellation interruption with
cause: timeout. See Cooperative Cancellation.
For SDK authors: a service worker reports an uncaught or rethrown cleanup
interruption with fail_workflow.failure.interruption: "timeout_cleanup", and
only for the interruption it delivered for the run's root timeout request (no
parent request, no scope). Anything else, including an application-built or
wrapped interruption, records failed. Server accepts the marker only while
the run's engine-owned timeout request is active and only from a claim that
negotiated timeout_cleanup. Workflow 2.42.0 states this rule in the
portable contract.
Mixed queues. Admission checks only that at least one live worker on the
task queue advertises timeout_cleanup; any worker on the queue can claim the
cleanup turn. Server refuses the marker from a worker that did not advertise
the capability, so an interruption that escapes there is recorded as failed
or expired. But such a worker may never deliver the interruption: if its
workflow code returns, the run records cleanup completed although no cleanup
ran. Before starting opted-in runs on a queue, upgrade every worker on it to a
supporting SDK with cooperative cancellation enabled.
Workflow-task lease
A workflow task is one worker turn that replays committed history and produces durable commands. It is not the entire workflow. Waiting on a durable timer, queued activity or signal does not hold one workflow task for the whole wait. A later task resumes the run.
| Deployment | Default seconds | Setting |
|---|---|---|
| Embedded Laravel | 300 | DW_V2_WORKFLOW_TASK_LEASE_SECONDS |
| Server | 60 | DW_WORKFLOW_TASK_TIMEOUT |
The embedded setting maps to workflows.v2.workflow_task_lease_seconds. Server maps its own setting into that package key at boot, so use the Server setting on Server. This is runtime configuration, not a StartOptions or per-start activity timeout. See Publishing Config and the Server configuration reference.
Heartbeats and execution
Service-mode workers use task heartbeats to renew an in-progress workflow-task claim. Server validates the task, attempt and lease owner. An acknowledged renewal uses the effective lease duration, subject to applicable cancellation-cleanup bounds. It does not change the original run/execution deadlines or activity timeouts. Worker-registration heartbeats keep the registration fresh. A stale registration can invalidate a Server claim before the task lease expires. These heartbeats do not renew that task lease. A queued activity's heartbeat reports activity progress and does not replace a workflow-task renewal.
Synchronous embedded workflow code cannot periodically renew while blocked. Keep workflow code deterministic and short. Put long I/O or CPU work in activities. The lease is not a hard process or CPU execution limit.
Embedded local activities retain the hosting workflow task. Their $this->heartbeat() can also renew its lease while the original activity attempt and workflow-task claim remain valid.
Lease expiry
An expired, unfinished claim becomes eligible for recovery. Matching/watchdog or repair clears the expired claim and redispatches work so a compatible worker can replay committed history. Recovery requires running recovery processes, an available database and an eligible worker. Expiry does not kill the old process or guarantee immediate redelivery. On Server, an expired or replaced claim cannot submit new commands; a rejected renewal must be treated as lost authority.
Repair does not reopen a closed run, grant extra business retries or reset original deadlines. Activity startToCloseTimeout instead bounds one activity attempt under its recorded retry policy. Run and execution timeouts bound the workflow lifetime. Workflow-task renewal or replay does not extend them.
Activity timeouts
Activity timeouts let you bound how long individual activity executions are allowed to take. There are four activity timeout scopes:
- Schedule-to-start — caps the time from scheduling to the first worker claim. Enforced while the activity is
Pending. - Start-to-close — caps the time from when a worker claims the activity to when it must complete. Resets on each retry attempt.
- Schedule-to-close — caps the total wall-clock time from scheduling to completion across all retry attempts. This is always terminal — retrying would not help because the overall deadline has passed.
- Heartbeat — caps the time between heartbeats. For long-running activities that call
$this->heartbeat(), the engine requires a heartbeat within the configured interval or the activity is considered unresponsive.
All are optional and can be combined. Configure them through ActivityOptions when calling an activity:
use function Workflow\V2\activity;
use Workflow\V2\Support\ActivityOptions;
$result = activity(
LongRunningActivity::class,
new ActivityOptions(
scheduleToStartTimeout: 30, // must be claimed within 30s
startToCloseTimeout: 300, // each attempt has 5 minutes
scheduleToCloseTimeout: 600, // total 10 minutes across all retries
heartbeatTimeout: 15, // heartbeat well before this 15-second window expires
maxAttempts: 3,
),
$input,
);
In service mode, PHP SDK 3.9.0 and later accept a string such as '5 minutes' or a DateInterval or CarbonInterval for activity timeouts and for child workflow execution and run timeouts, as well as seconds. Those timeouts must be at least one second. See PHP SDK durations.
In service mode, closing an activity attempt does not forcibly stop SDK application code. Python SDK 2.9.0 reports a refusal at the next heartbeat; code that never heartbeats can run until it returns, and a physical thread slot remains occupied until exit. See Python heartbeat refusals and callback exit.
Schedule-to-start timeout
The deadline is computed when the activity is scheduled. If no worker claims the activity before the deadline, the TaskWatchdog enforces the timeout. If retry attempts remain, a new activity task is scheduled with the snapped backoff and the schedule-to-start deadline is recomputed relative to the retry's available-at time — each retry gets a fresh window. If no scheduleToStartTimeout was configured, the deadline is cleared on retry. If all attempts are exhausted, a terminal ActivityTimedOut history event is recorded and the workflow is woken.
Start-to-close timeout
The deadline is computed when a worker claims the activity task. Each retry gets a fresh start-to-close deadline. If the activity does not complete before the deadline, the current attempt is closed. If retry attempts remain, the execution returns to Pending with a reset schedule-to-start deadline (if configured) so the retried task is not immediately re-timed-out. If all attempts are exhausted, a terminal timeout is recorded.
Schedule-to-close timeout
The deadline is computed once at scheduling time and never resets. When it expires, the activity is immediately failed as terminal — even if retry attempts remain, because the total allowed wall-clock time has passed. This is useful for bounding the overall cost of a flaky activity that might otherwise retry indefinitely within its per-attempt limits.
Heartbeat timeout
For a queued activity, the first deadline starts when the runtime claims it, before task delivery and user code. Each accepted heartbeat sets the deadline to its recorded runtime timestamp plus the configured timeout. It does not add time to the previous deadline or start a fresh window when the caller receives the response. Leave room for delivery, bounded work, scheduling pauses, request latency and transport retries. Send heartbeats well before the window expires. An expired or replaced attempt cannot regain authority by sending a late heartbeat. If retry attempts remain, a new attempt is scheduled with a reset schedule-to-start deadline (if configured). Otherwise a terminal timeout is recorded.
Moving the deadline adds no history. A heartbeat writes an ActivityHeartbeatRecorded event only when its progress changed, at most once per recording interval, so you can heartbeat as often as this timeout needs. See Heartbeats.
use Workflow\V2\Activity;
class LongRunningActivity extends Activity
{
public function handle($input)
{
foreach ($items as $item) {
$this->heartbeat(['processed' => $count]);
// ... process item ...
}
}
}
Enforcement
Activity timeouts are enforced by the TaskWatchdog on each worker-loop pass. The watchdog scans for executions whose deadline columns have passed and delegates to ActivityTimeoutEnforcer. Each enforcement records:
- A terminal
ActivityTimedOuthistory event withtimeout_kindset toschedule_to_start,start_to_close,schedule_to_close, orheartbeat - A
WorkflowFailurerow withfailure_category = timeoutandpropagation_kind = timeout - A workflow resume task to wake the parent workflow so it can observe the failure
Waterline displays the retry policy including all configured timeout types in the activity detail view. The timeline shows the timeout kind in the activity timed-out event message.
What is not yet covered
The following are planned but not yet implemented:
- Retry policies at the workflow level
Structural limits
Typed structural-limit failures for payload size, pending fan-out counts, and metadata size ceilings are enforced by the engine. See Structural Limits for the full limit contract, configuration, and failure taxonomy.