Skip to content

Commit 4fb166c

Browse files
committed
Make condition-timeout worker history self-identifying
1 parent ed3c60e commit 4fb166c

7 files changed

Lines changed: 316 additions & 45 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9-
The Python SDK advances to prerelease `2.0.0-rc.9`. PyPI displays the normalized
10-
PEP 440 identity `2.0.0rc9`. This SDK release is qualified with Server
11-
`2.0.0-rc.14`; SDK and Server prerelease sequence numbers advance independently.
9+
The Python SDK advances to prerelease `2.0.0-rc.16`. PyPI displays the normalized
10+
PEP 440 identity `2.0.0rc16`. This SDK release is qualified with Server
11+
`2.0.0-rc.16`; SDK and Server prerelease sequence numbers advance independently.
1212
Earlier SDK versions remain historical releases and are not alternate supported
1313
2.0 baselines; no prerelease compatibility shim is provided.
1414

@@ -57,9 +57,10 @@ Earlier SDK versions remain historical releases and are not alternate supported
5757
suffix, query, or fragment while preserving self-hosted and managed-runtime
5858
path prefixes. The quickstart also uses unique durable workflow identities
5959
and documents typed duplicate-start handling.
60-
- Condition-timeout history now remains correlated when a worker snapshot gives
61-
the internal timer its own sequence without repeating its wait id or timer
62-
kind, keeping updates and signals from shifting the ordinary activity cursor.
60+
- Current condition-timeout history uses explicit timer and condition identity
61+
without adjacency inference, while the metadata-poor historical shape keeps a
62+
narrowly bounded replay fallback. Interleaved updates and signals no longer
63+
shift the ordinary activity cursor.
6364
- Worker registration now advertises each workflow's declared signal, query,
6465
and update contract with typed parameter metadata, allowing the server to
6566
admit declared Python workflow updates while preserving typed refusals.

‎README.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A Python SDK for the [Durable Workflow server](https://github.com/durable-workflow/server). Speaks the server's language-neutral HTTP/JSON worker protocol — no PHP runtime required.
44

5-
Status: **Beta** — this is Python SDK prerelease `2.0.0-rc.9` in the Durable
5+
Status: **Beta** — this is Python SDK prerelease `2.0.0-rc.16` in the Durable
66
Workflow 2.0 line. Core features include workflows, activities,
77
schedules, signals, timers, child workflows, continue-as-new, side effects,
88
version markers, worker-applied accepted updates, replay verification, the
@@ -11,7 +11,7 @@ in-process `WorkflowEnvironment` test harness, and invocable activity carriers.
1111
## Install
1212

1313
```bash
14-
pip install durable-workflow==2.0.0-rc.9
14+
pip install durable-workflow==2.0.0-rc.16
1515
```
1616

1717
Or for development:
@@ -605,8 +605,8 @@ Full documentation is available at
605605

606606
## Compatibility
607607

608-
SDK version `2.0.0-rc.9` is qualified with
609-
`durableworkflow/server:2.0.0-rc.14`. The SDK package and Server release
608+
SDK version `2.0.0-rc.16` is qualified with
609+
`durableworkflow/server:2.0.0-rc.16`. The SDK package and Server release
610610
identities advance independently; matching RC sequence numbers are not
611611
required. The server must advertise these protocol manifests from
612612
`GET /api/cluster/info`:

‎pyproject.toml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "durable-workflow"
7-
version = "2.0.0-rc.9"
7+
version = "2.0.0-rc.16"
88
description = "Python SDK for the Durable Workflow server (language-neutral HTTP protocol)"
99
readme = "README.md"
1010
requires-python = ">=3.10"
@@ -66,9 +66,9 @@ durable-workflow-replay-conformance = "durable_workflow.replay_conformance:main"
6666
durable-workflow-workflow-updates-conformance = "durable_workflow.workflow_updates_conformance:main"
6767

6868
[tool.durable-workflow]
69-
product-train = "2.0.0-rc.9"
70-
registry-version = "2.0.0rc9"
71-
supported-server-versions = "2.0.0-rc.14"
69+
product-train = "2.0.0-rc.16"
70+
registry-version = "2.0.0rc16"
71+
supported-server-versions = "2.0.0-rc.16"
7272
worker-protocol-version = "1.1"
7373
control-plane-version = "2"
7474

‎src/durable_workflow/workflow.py‎

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,20 +2116,20 @@ def _condition_timeout_wait_id(
21162116
return condition_wait_ids_by_sequence.get(sequence) if sequence is not None else None
21172117

21182118

2119-
def _condition_timeout_timer_sequence_aliases(
2119+
def _legacy_condition_timeout_timer_sequence_aliases(
21202120
events: Iterable[Mapping[str, Any]],
21212121
condition_wait_ids_by_sequence: Mapping[int, str],
21222122
) -> dict[int, str]:
2123-
"""Correlate metadata-poor timeout timers with the open timed condition.
2123+
"""Read the metadata-poor condition-timer shape emitted by older servers.
21242124
2125-
A worker-protocol history can persist the internal timer at a sequence after
2126-
``ConditionWaitOpened`` without repeating the wait id or timer kind. While a
2127-
condition is open, the workflow generator cannot yield an ordinary timer,
2128-
so its first untyped ``TimerScheduled`` row is the condition's timeout.
2125+
The legacy row must have its own sequence, a timer id, and a delay equal to
2126+
the open condition's positive timeout. Current histories identify the timer
2127+
directly and never enter this adjacency-based compatibility path.
21292128
"""
21302129
aliases: dict[int, str] = {}
21312130
active_wait_id: str | None = None
2132-
active_wait_has_timeout = False
2131+
active_wait_sequence: int | None = None
2132+
active_wait_timeout: int | None = None
21332133

21342134
for event in events:
21352135
event_type = _history_event_type(event)
@@ -2139,36 +2139,41 @@ def _condition_timeout_timer_sequence_aliases(
21392139

21402140
if event_type == "ConditionWaitOpened":
21412141
active_wait_id = _optional_str(payload.get("condition_wait_id"))
2142+
active_wait_sequence = _workflow_sequence(payload)
21422143
timeout_seconds = payload.get("timeout_seconds")
2143-
active_wait_has_timeout = (isinstance(timeout_seconds, (int, float)) and timeout_seconds > 0) or (
2144-
isinstance(timeout_seconds, str) and timeout_seconds.isdigit() and int(timeout_seconds) > 0
2145-
)
2144+
if isinstance(timeout_seconds, bool):
2145+
active_wait_timeout = None
2146+
elif isinstance(timeout_seconds, int) and timeout_seconds > 0:
2147+
active_wait_timeout = timeout_seconds
2148+
elif isinstance(timeout_seconds, str) and timeout_seconds.isdigit() and int(timeout_seconds) > 0:
2149+
active_wait_timeout = int(timeout_seconds)
2150+
else:
2151+
active_wait_timeout = None
21462152
continue
21472153

21482154
if event_type == "TimerScheduled":
21492155
sequence = _workflow_sequence(payload)
2150-
explicit_kind = _internal_timeout_timer_kind(
2151-
payload,
2152-
condition_wait_ids_by_sequence,
2153-
)
2156+
explicit_kind = _internal_timeout_timer_kind(payload)
21542157
timer_kind = _optional_str(payload.get("timer_kind"))
21552158
if explicit_kind == "condition_timeout":
2156-
wait_id = _optional_str(payload.get("condition_wait_id")) or active_wait_id
2157-
if sequence is not None and wait_id is not None:
2158-
aliases[sequence] = wait_id
21592159
continue
21602160
if (
21612161
sequence is not None
21622162
and active_wait_id is not None
2163-
and active_wait_has_timeout
2163+
and active_wait_sequence is not None
2164+
and sequence != active_wait_sequence
2165+
and active_wait_timeout is not None
2166+
and payload.get("delay_seconds") == active_wait_timeout
2167+
and _optional_str(payload.get("timer_id")) is not None
21642168
and timer_kind is None
21652169
and _optional_str(payload.get("signal_wait_id")) is None
21662170
):
21672171
aliases[sequence] = active_wait_id
21682172
continue
21692173

21702174
active_wait_id = None
2171-
active_wait_has_timeout = False
2175+
active_wait_sequence = None
2176+
active_wait_timeout = None
21722177
continue
21732178

21742179
if event_type in ("TimerFired", "TimerCancelled"):
@@ -2177,14 +2182,16 @@ def _condition_timeout_timer_sequence_aliases(
21772182
payload, condition_wait_ids_by_sequence
21782183
) == "condition_timeout":
21792184
active_wait_id = None
2180-
active_wait_has_timeout = False
2185+
active_wait_sequence = None
2186+
active_wait_timeout = None
21812187
continue
21822188

21832189
if event_type in ("ConditionWaitSatisfied", "ConditionWaitTimedOut"):
21842190
resolved_wait_id = _optional_str(payload.get("condition_wait_id"))
21852191
if resolved_wait_id is None or resolved_wait_id == active_wait_id:
21862192
active_wait_id = None
2187-
active_wait_has_timeout = False
2193+
active_wait_sequence = None
2194+
active_wait_timeout = None
21882195
continue
21892196

21902197
if event_type in (
@@ -2195,11 +2202,28 @@ def _condition_timeout_timer_sequence_aliases(
21952202
"ChildWorkflowScheduled",
21962203
):
21972204
active_wait_id = None
2198-
active_wait_has_timeout = False
2205+
active_wait_sequence = None
2206+
active_wait_timeout = None
21992207

22002208
return aliases
22012209

22022210

2211+
def _has_metadata_poor_timer_schedule(events: Iterable[Mapping[str, Any]]) -> bool:
2212+
for event in events:
2213+
if _history_event_type(event) != "TimerScheduled":
2214+
continue
2215+
payload = event.get("payload") or {}
2216+
if not isinstance(payload, Mapping):
2217+
continue
2218+
if (
2219+
_internal_timeout_timer_kind(payload) is None
2220+
and _optional_str(payload.get("timer_id")) is not None
2221+
and _optional_str(payload.get("timer_kind")) is None
2222+
):
2223+
return True
2224+
return False
2225+
2226+
22032227
def _activity_type_from_payload(payload: Mapping[str, Any]) -> str | None:
22042228
activity_type = _optional_str(payload.get("activity_type"))
22052229
if activity_type is not None:
@@ -2476,12 +2500,13 @@ def _replay_state(
24762500
if isinstance(wait_id, str) and wait_id:
24772501
condition_wait_ids_by_sequence[sequence] = wait_id
24782502

2479-
condition_wait_ids_by_sequence.update(
2480-
_condition_timeout_timer_sequence_aliases(
2481-
events,
2482-
condition_wait_ids_by_sequence,
2503+
if _has_metadata_poor_timer_schedule(events):
2504+
condition_wait_ids_by_sequence.update(
2505+
_legacy_condition_timeout_timer_sequence_aliases(
2506+
events,
2507+
condition_wait_ids_by_sequence,
2508+
)
24832509
)
2484-
)
24852510

24862511
for event in events:
24872512
event_type = _history_event_type(event)

0 commit comments

Comments
 (0)