Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions docs/features/sagas.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ also provide no cleanup window.

The separate [experimental timeout-cleanup option](./timeouts.md#timeout-cleanup)
can reserve time for an interruption-driven compensation handler inside the
original hard cap. It is experimental embedded queue support, available in
Workflow 2.29.0 and later with no backward-compatibility promise yet; service
and poll-mode starts refuse it. It does not make compensation automatic or
guarantee an effect when workers are unavailable.
original hard cap. It is experimental, with no backward-compatibility promise
yet. Embedded queue workers support it from Workflow 2.29.0 (embedded poll-mode
starts refuse it), and service mode supports it from native Server 3.30.0 with
supporting SDK workers. It does not make compensation automatic or guarantee an
effect when workers are unavailable, and a `completed` cleanup outcome
[does not prove cleanup code ran](./timeouts.md#timeout-cleanup).

Use an earlier application deadline when timeout should undo completed work.
This embedded workflow reserves a resource, then waits up to 30 seconds for a
Expand Down
83 changes: 65 additions & 18 deletions docs/features/timeouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,19 @@ or run deadline. See [Cancel and Terminate](./cancel-and-terminate.md) and

## Experimental deadline-triggered cleanup {#timeout-cleanup}

**Experimental embedded support.** Available in Workflow 2.29.0 and later for
embedded queue workers only; service and poll-mode starts refuse it. The option
**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](../compatibility.md#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, 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.
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.

```bash
php artisan migrate
Expand Down Expand Up @@ -199,8 +201,8 @@ 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`. Compatible workflow code receives
`WorkflowTimeoutCleanupRequested`, a subtype of
`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
Expand All @@ -210,10 +212,23 @@ Cleanup has a separate `timeout_cleanup.outcome`:

| Outcome | Meaning |
|---|---|
| `completed` | Workflow cleanup returned or rethrew the timeout interruption before its deadline. A returned value does not become the business result. |
| `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()` interrupted cleanup; the corresponding cancellation/termination outcome remains terminal. |
| `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
Expand All @@ -224,18 +239,50 @@ 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. Control-plane describe output and the run summary carry
no cleanup outcome, and run detail shows at most a note such as "Timeout
cleanup failed." (nothing for `preempted`).
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.

This increment supports embedded queue workers only. Poll-mode and service
starts refuse the option, and bridge workers cannot claim an opted-in embedded
run. Native admission and SDK runtime delivery remain pending under
[Server #1201](https://github.com/durable-workflow/server/issues/1201); parser
support alone does not implement timeout cleanup.
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](../polyglot/cancellation.md).

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](https://github.com/durable-workflow/workflow/blob/main/docs/architecture/timeout-cleanup.md).

**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 {#workflow-task-lease}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Aktivitäten laufen mindestens einmal. Ein vorwärts gerichteter Aufruf kann dah

Bei der standardmäßigen harten Timeout-Regel gilt: Ein von der Engine durchgesetztes [Workflow-Zeitlimit](./timeouts.md#timeout-outcome-and-cleanup) schließt den Lauf, bevor Workflow-Code Kompensation ausführen kann. Ein `catch`- oder `finally`-Block ändert dies nicht. Auch die unmittelbaren Befehle `cancel()` und `terminate()` bieten kein Aufräumfenster.

Die separate [experimentelle Timeout-Cleanup-Option](./timeouts.md#timeout-cleanup) kann innerhalb der ursprünglichen harten Grenze Zeit für einen durch Unterbrechung ausgelösten Kompensationshandler reservieren. Sie ist experimentelle Unterstützung für Embedded-Queue-Worker, verfügbar ab Workflow 2.29.0 und noch ohne Zusage zur Abwärtskompatibilität; Service- und Poll-Starts lehnen sie ab. Sie macht Kompensation nicht automatisch und garantiert bei fehlenden Workern keine Wirkung.
Die separate [experimentelle Timeout-Cleanup-Option](./timeouts.md#timeout-cleanup) kann innerhalb der ursprünglichen harten Grenze Zeit für einen durch Unterbrechung ausgelösten Kompensationshandler reservieren. Sie ist experimentell und hat noch keine Zusage zur Abwärtskompatibilität. Embedded-Queue-Worker unterstützen sie ab Workflow 2.29.0 (Embedded-Poll-Starts lehnen sie ab), der Service-Modus ab nativem Server 3.30.0 mit unterstützenden SDK-Workern. Sie macht Kompensation nicht automatisch und garantiert bei fehlenden Workern keine Wirkung, und ein Cleanup-Ergebnis `completed` [beweist nicht, dass Cleanup-Code lief](./timeouts.md#timeout-cleanup).

Verwenden Sie eine frühere Anwendungsfrist, wenn bei Ablauf bereits erledigte Arbeit zurückgenommen werden soll. Dieser eingebettete Workflow reserviert eine Ressource und wartet danach höchstens 30 Sekunden auf ein Bestätigungssignal. Bei Ablauf wird Workflow-Code fortgesetzt, der die Reservierung vor Rückgabe des fachlichen Ergebnisses `expired` freigibt:

Expand Down
Loading