Skip to content
Merged
20 changes: 20 additions & 0 deletions docs/polyglot/php.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,26 @@ same parser as the embedded package.
The [PHP SDK duration reference](https://php.durable-workflow.com/build/workflows-activities/#durations)
lists every unit.

## Replay-safe workflow time {#replay-safe-workflow-time}

`WorkflowContext::replayNow()` returns replay-safe UTC business time as a
`DateTimeImmutable`. At ordinary entry it is the run's start (for a redrive successor, the original run's start) from the task's
`replay_clock` (Server 3.6.0 and later). After each supported consumed durable
step (activities, timers, child workflows, condition waits, validated groups)
it is that step's recorded time. Repeated reads between durable steps return
the same value, and every replay returns the same values.

Where the SDK cannot prove the time, it throws
`DurableWorkflow\Exception\ReplayClockUnavailable`. That includes side effects,
version markers and local activities, which stay unavailable until Core defines
a persisted time for them. A clock read right after such a step is not portable
across runners or mixed fleets; see
[Clock reads after inline steps are not portable](./python.md#inline-step-clock-reads).
Query and update handlers read history snapshots and never rebuild the workflow
body. See the
[cross-SDK clock semantics](./python.md#advancing-replay-clock) for the full
list, release status and the upgrade note.

## Entry compatibility and recovery {#entry-compatibility-and-recovery}

**Released support.** PHP SDK 2.5.4 introduced the entry safeguard below, with routing and recovery support in Server 2.9.9. These are minimum feature versions; install current stable releases for security fixes.
Expand Down
2 changes: 1 addition & 1 deletion docs/polyglot/polling-patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ Register `PollDemo` and `check_status` in the same [Python worker](./python.md),

The two examples were exercised on published Server **2.9.7 / Core 2.7.2**, with normally installed Python **2.6.1** and test input `[2, 1]`. Both completed two real checks across two runs. Continue-as-new resets run history, adds run/link overhead and preserves the original execution deadline. It does not provide an unlimited lifetime.

Use relative durable waits here. Python's advancing clock and replay-stable history-budget reads remain separate [clock](https://github.com/durable-workflow/.github/issues/215) and [budget](https://github.com/durable-workflow/workflow/issues/859) work. This recipe does not branch on `ctx.now()` or recomputed history length. Do not treat `DW_MAX_HISTORY_EVENTS` as an enforced automatic rollover: [Server #504](https://github.com/durable-workflow/server/issues/504) tracks that gap.
Use relative durable waits here. `ctx.replay_now()` (Python SDK 2.15.0+) advances with consumed durable steps, and from Python SDK 2.24.0 it also has a value at entry (see [Advancing replay clock](./python.md#advancing-replay-clock)); replay-stable history-budget reads remain separate [budget](https://github.com/durable-workflow/workflow/issues/859) work. This recipe does not branch on `ctx.now()` or recomputed history length. Do not treat `DW_MAX_HISTORY_EVENTS` as an enforced automatic rollover: [Server #504](https://github.com/durable-workflow/server/issues/504) tracks that gap.

## Interrupt and reconcile {#interrupt-and-reconcile}

Expand Down
114 changes: 106 additions & 8 deletions docs/polyglot/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,7 @@ The `WorkflowContext` passed to `run` provides deterministic operations:
| `ctx.upsert_search_attributes(attrs)` | Update search attributes |
| `ctx.continue_as_new(*args)` | Restart the workflow with new input |
| `ctx.now()` | Persisted workflow-start time, fixed for this run |
| `ctx.replay_now()` | Advancing replay-safe UTC time: the run's start at entry, then each consumed durable step's recorded time |
| `ctx.random()` | Seeded random generator |
| `ctx.uuid4()` | Deterministic UUID |
| `ctx.logger` | Logger that is silent during replay |
Expand Down Expand Up @@ -921,23 +922,118 @@ UTC timestamps with monotonic values, or subtract monotonic readings from
different processes or hosts. `ctx.now()` subtraction measures neither active
processing time nor elapsed wall time in Python.

#### Advancing replay clock {#advancing-replay-clock}

`ctx.replay_now()` is an additive UTC clock that moves with consumed history.
The Rust (`WorkflowContext::replay_now()`) and PHP service-mode
(`WorkflowContext::replayNow()`) SDKs provide the same clock.

- At ordinary workflow entry, before any durable step, it returns the run's canonical start (for a redrive successor, the original run's start). Server 3.6.0 and later sends that instant on each workflow
task as `replay_clock`. History insertion, dispatch and lease times are never
used instead.
- After a supported durable step it returns that step's recorded time:
activities, timers and child workflows in every SDK, signal and condition
waits where the SDK supports them, and validated groups.
- Repeated reads between durable steps return the same value, and every replay of the run returns the same values. The clock is not guaranteed to be monotonic: a later proved boundary can carry an earlier recorded time.

A deadline loop around a durable timer therefore terminates, and the
difference between reads after two durable steps measures their recorded
elapsed time:

```python
from datetime import timedelta

from durable_workflow import workflow


@workflow.defn(name="poll_until_deadline")
class PollUntilDeadline:
def run(self, ctx):
deadline = ctx.replay_now() + timedelta(minutes=10)
while ctx.replay_now() < deadline:
yield ctx.schedule_activity("check_status", [])
yield ctx.start_timer(60)
return "deadline reached"
```

Where the SDK cannot prove the time, `ctx.replay_now()` raises
`ReplayClockUnavailable` rather than using any other time:

- at entry on a task without the carrier: Servers before 3.6.0, or a run whose
start Server cannot prove;
- after inline and local operations, such as side effects, version markers,
memo and search-attribute updates, and local activities. These stay
unavailable until Core defines a persisted time for those steps;
- after other group modes and in cancellation scopes;
- in query handlers: always in PHP, and in Python and Rust unless the queried history ends at a supported scalar boundary (grouped boundaries give no query time).

An unhandled `ReplayClockUnavailable` fails the workflow like any other
exception.

##### Clock reads after inline steps are not portable {#inline-step-clock-reads}

Inline steps are side effects, version markers, memo and search-attribute
updates, and local activities. Until Core defines a persisted time for them, a
clock read immediately after one is not portable across runners or mixed
fleets:

- The service-mode SDKs (Python, Rust and the PHP SDK) report the clock as
unavailable there.
- On the embedded engine, `Workflow::now()` moves to the step's recorded time.
- On the external-worker runner (the embedded package's worker-protocol
`WorkflowFiberRunner`, which external PHP workers use through the bridge),
side effects, memo and search-attribute updates, and version markers behave
alike: a first execution keeps the previous boundary time, while a replay
reads the step's recorded time. For version markers this divergence is kept
deliberately: superseding the pinned `repeated-version-legacy-clock-boundaries`
replay fixture would change the replay output of runs already in flight.
- The read therefore differs whenever the first execution ran on the
external-worker runner, including in a fleet of only external workers, and
whenever a run may move between runners, because embedded and external first
executions read different times.

Do not rely on a clock read immediately after an inline step: read the clock
after the next durable step.

Python and Rust rebuild the workflow from history to answer a query or a
pre-accept update validation. If the rebuilt workflow reads the clock at entry
and the task has no `replay_clock`, which Servers before 3.30.0 never send
on those tasks, the query or validation fails rather than
answering with state the workflow task never computed. The PHP SDK never
rebuilds the workflow body for queries or updates.

Offline replay (`replay()`, `Replayer.replay()`, `replay_history()`) takes the task's object as `replay_clock_entry`. The in-memory `WorkflowEnvironment` supplies no carrier, so entry reads there are unavailable.

**Release status.** The entry value (all three SDKs) and the query and validation rule (Python and Rust) ship in Python SDK 2.24.0, Rust SDK 4.25.0 and PHP SDK 3.32.0 and need Server 3.6.0 or later. The
carrier on query and validation tasks ships in Server 3.30.0. The embedded
package's worker-protocol runner (`WorkflowFiberRunner`) accepts the carrier
from Workflow 2.42.0: once the code that builds the runner passes it,
`Workflow::now()` at entry returns the run's canonical start.
Earlier SDK releases report entry as unavailable.

**Upgrading.** A running workflow whose code branches on the entry read being
unavailable, for example by catching `ReplayClockUnavailable`, takes the other branch on replay after the upgrade, during a rolling deploy that mixes old and new workers, or after a Server upgrade to 3.6.0. Put such code behind `ctx.get_version(...)`
or drain those runs first. `ctx.now()` keeps its fixed start time, so runs that
read it replay unchanged.

#### Clock differences across SDKs

These APIs are deterministic where provided, but they do not share one clock:

| Authoring surface | Repeated calls and durable steps | Continue-as-new successor |
| --- | --- | --- |
| Python `ctx.now()` | Fixed to this run's persisted start time, including after a timer or activity. | Uses the successor run's start anchor. |
| Python `ctx.replay_now()` | Starts at the run's start and advances to each supported consumed step's recorded time. See [Advancing replay clock](#advancing-replay-clock). | Starts at the successor run's own start. |
| Embedded PHP `Workflow::now()` | Starts at the run's start time and advances to the recorded event time consumed by replay. See [workflow time](../features/timers.md#reading-deterministic-time). | Starts with the new run, then advances through that run's consumed events. |
| PHP service-mode SDK | No general public workflow `now()` helper. Use durable operations or recorded activity/side-effect values. | Pass application timing state explicitly when it must survive the handoff. |
| Rust service-mode SDK | No general public `WorkflowContext::now()` helper. A `side_effect` can record a small wall-clock snapshot; it is not an advancing clock. | A side effect in the new run is a new operation; pass earlier timing state explicitly if needed. |
| PHP service-mode `WorkflowContext::replayNow()` | Same semantics as Python `ctx.replay_now()`. | Starts at the successor run's own start. |
| Rust service-mode `WorkflowContext::replay_now()` | Same semantics as Python `ctx.replay_now()`. | Starts at the successor run's own start. |

The embedded PHP behavior is present in
[published Core](https://github.com/durable-workflow/workflow/blob/64efa176e4c37e5d6ae80e767ba3b41464024e53/src/V2/Support/WorkflowFiberContext.php);
the separate [PHP SDK context](https://github.com/durable-workflow/sdk-php/blob/2.5.2/src/Worker/WorkflowContext.php)
and [Rust SDK context](https://github.com/durable-workflow/sdk-rust/blob/3.5.5/src/lib.rs)
have their own APIs. Port the durable operation and deadline policy rather than
assuming that a clock helper has identical semantics in every SDK.
The service-mode clocks share one contract. Embedded `Workflow::now()` also moves to the recorded time of an inline step such as a
side effect, where the service-mode clocks report the time as unavailable, so
such a read is not portable (see
[Clock reads after inline steps are not portable](#inline-step-clock-reads)). Port
the durable operation and deadline policy rather than assuming that every clock
helper behaves identically.

#### Order emitted events with sequence values

Expand All @@ -949,6 +1045,8 @@ workflow-local counter. Pair a run-local counter with `run_id`; carry it through
continue-as-new explicitly if the application needs one logical sequence.
Independent streams or runs do not gain a global order from their timestamps.

Repeated `ctx.replay_now()` reads between durable steps also return one value, so do not use it to order events either.

### Activity Retries and Timeouts

Use `ActivityRetryPolicy` and timeout keyword arguments on `ctx.schedule_activity(...)`
Expand Down
21 changes: 20 additions & 1 deletion docs/polyglot/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -893,14 +893,33 @@ Keep durable command order independent of this observation state and log deliver

See the [published logging guide](https://github.com/durable-workflow/sdk-rust/blob/4.17.0/README.md#workflow-logging), [WorkflowLogger API](https://rust.durable-workflow.com/durable_workflow/struct.WorkflowLogger.html) and [WorkflowReplayState API](https://rust.durable-workflow.com/durable_workflow/enum.WorkflowReplayState.html). [Registry lifecycle/deadline controls](https://github.com/durable-workflow/sdk-rust/pull/269#issuecomment-6868388853) and [four-process logging acceptance](https://github.com/durable-workflow/sdk-rust/pull/269#issuecomment-6868494262) were recorded on the named native Server 3.10.0 linux/amd64 tuple. Other bindings and broader replay/producer qualification retain their own scope.

## Replay-safe workflow time {#replay-safe-workflow-time}

`WorkflowContext::replay_now()` returns replay-safe UTC business time as
`Result<DateTime<Utc>>`. At ordinary entry it is the run's start (for a redrive successor, the original run's start) from the task's `replay_clock` (Server 3.6.0 and later). After each supported consumed
durable step (activities, timers, child workflows, signal and condition waits,
validated groups) it is that step's recorded time. Repeated reads between
durable steps return the same value, and every replay returns the same values.

Where the SDK cannot prove the time, it returns `Error::ReplayClockUnavailable`.
That includes inline and local operations (side effects, version markers, local
activities, memos), which stay unavailable until Core defines a persisted time
for them. A clock read right after such a step is not portable across runners or
mixed fleets; see
[Clock reads after inline steps are not portable](./python.md#inline-step-clock-reads).
Offline replay supplies a carrier with
`WorkflowHistory::replay_clock(carrier)`. See the
[cross-SDK clock semantics](./python.md#advancing-replay-clock) for the full
list, the query and validation rule, release status and the upgrade note.

## Rust determinism rules {#rust-determinism-rules}

A replay must produce the same durable commands in the same order for the recorded input and history. Rust's ordinary collections, clocks and concurrency primitives do not automatically preserve that contract:

| Pattern in workflow code | Durable replacement |
| --- | --- |
| Scheduling while iterating a `HashMap` | Sort keys first or use a `BTreeMap`. |
| System-clock reads, `thread_rng` or a new UUID | Record a snapshot with `ctx.side_effect(...)`, or use an activity. |
| System-clock reads, `thread_rng` or a new UUID | `ctx.replay_now()` for business time; record other values with `ctx.side_effect(...)`, or use an activity. |
| `tokio::time::sleep` or `std::thread::sleep` | `ctx.sleep(...)` or `ctx.start_timer(...)`. |
| `tokio::select!` or racing ordinary futures | `ctx.select(...)` or `ctx.select_keyed(...)`. |
| Untracked concurrent durable calls | `ctx.parallel(...)` with stable input ordering. |
Expand Down
22 changes: 22 additions & 0 deletions i18n/de/docusaurus-plugin-content-docs/current/polyglot/php.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,28 @@ im eingebetteten Paket umgerechnet werden. Die
[Dauerreferenz des PHP SDK](https://php.durable-workflow.com/build/workflows-activities/#durations)
listet alle Einheiten auf.

## Replay-sichere Workflow-Zeit {#replay-safe-workflow-time}

`WorkflowContext::replayNow()` liefert replay-sichere UTC-Geschäftszeit als
`DateTimeImmutable`. Beim normalen Einstieg ist es der Start des Runs (bei einem Redrive-Nachfolger der Start des ursprünglichen Runs) aus dem
`replay_clock` der Aufgabe (Server 3.6.0 und neuer). Nach jedem unterstützten
verarbeiteten dauerhaften Schritt (Aktivitäten, Timer, Child-Workflows,
Bedingungswartevorgänge, validierte Gruppen) ist es dessen aufgezeichnete Zeit.
Wiederholte Lesevorgänge zwischen dauerhaften Schritten liefern denselben Wert,
und jedes Replay liefert dieselben Werte.

Wo das SDK die Zeit nicht nachweisen kann, wirft es
`DurableWorkflow\Exception\ReplayClockUnavailable`. Das umfasst Seiteneffekte,
Versionsmarker und lokale Aktivitäten, die nicht verfügbar bleiben, bis Core
für sie eine gespeicherte Zeit festlegt. Eine Uhrlesung direkt nach einem
solchen Schritt ist weder zwischen Runnern noch in gemischten Flotten portabel;
siehe
[Uhrlesungen nach Inline-Schritten sind nicht portabel](./python.md#inline-step-clock-reads).
Query- und Update-Handler lesen
Historien-Snapshots und bauen den Workflow-Körper nie neu auf. Die vollständige
Liste, den Release-Status und den Upgrade-Hinweis finden Sie in der
[SDK-übergreifenden Uhrsemantik](./python.md#advancing-replay-clock).

## Kompatibilität am Einstieg und Wiederherstellung {#entry-compatibility-and-recovery}

**Veröffentlichte Unterstützung.** PHP SDK 2.5.4 hat den nachfolgenden Einstiegsschutz eingeführt, ergänzt durch Routing und Wiederherstellung in Server 2.9.9. Dies sind die Mindestversionen für diese Funktionen. Installieren Sie aktuelle stabile Versionen, um Sicherheitskorrekturen zu erhalten.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ Registrieren Sie `PollDemo` und `check_status` im selben [Python-Worker](./pytho

Beide Beispiele wurden mit den veröffentlichten Versionen Server **2.9.7 / Core 2.7.2**, regulär installiertem Python **2.6.1** und der Testeingabe `[2, 1]` ausgeführt. Beide führten zwei echte Prüfungen in zwei Läufen aus. Continue-as-new beginnt eine neue Laufhistorie, erzeugt zusätzlichen Lauf- und Verknüpfungsaufwand und behält die ursprüngliche Ausführungsfrist bei. Es ermöglicht keine unbegrenzte Lebensdauer.

Verwenden Sie hier relative dauerhafte Wartezeiten. Eine fortschreitende Python-Uhr und bei der Wiedergabe stabile Abfragen des Historienbudgets bleiben getrennte Arbeiten an [Uhr](https://github.com/durable-workflow/.github/issues/215) und [Budget](https://github.com/durable-workflow/workflow/issues/859). Dieses Rezept verzweigt nicht anhand von `ctx.now()` oder einer neu berechneten Historienlänge. Betrachten Sie `DW_MAX_HISTORY_EVENTS` nicht als erzwungenen automatischen Laufwechsel: [Server #504](https://github.com/durable-workflow/server/issues/504) verfolgt diese Lücke.
Verwenden Sie hier relative dauerhafte Wartezeiten. `ctx.replay_now()` (Python-SDK 2.15.0+) schreitet mit verarbeiteten dauerhaften Schritten fort und hat ab Python-SDK 2.24.0 auch beim Einstieg einen Wert (siehe [Fortschreitende Replay-Uhr](./python.md#advancing-replay-clock)); bei der Wiedergabe stabile Abfragen des Historienbudgets bleiben getrennte Arbeit am [Budget](https://github.com/durable-workflow/workflow/issues/859). Dieses Rezept verzweigt nicht anhand von `ctx.now()` oder einer neu berechneten Historienlänge. Betrachten Sie `DW_MAX_HISTORY_EVENTS` nicht als erzwungenen automatischen Laufwechsel: [Server #504](https://github.com/durable-workflow/server/issues/504) verfolgt diese Lücke.

## Unterbrechen und Auswirkungen abgleichen {#interrupt-and-reconcile}

Expand Down
Loading