Skip to content

Commit 8f7fb5d

Browse files
committed
Add deterministic workflow concurrency to PHP service mode
1 parent 8765783 commit 8f7fb5d

10 files changed

Lines changed: 266 additions & 27 deletions

‎CHANGELOG.md‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ 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.32`. PyPI displays the normalized
10-
PEP 440 identity `2.0.0rc32`. This Avro-only SDK release is qualified with Server
11-
`2.0.0-rc.32`; JSON remains HTTP transport and is no longer a workflow payload
9+
The Python SDK advances to prerelease `2.0.0-rc.33`. PyPI displays the normalized
10+
PEP 440 identity `2.0.0rc33`. This Avro-only SDK release is qualified with Server
11+
`2.0.0-rc.39`; JSON remains HTTP transport and is no longer a workflow payload
1212
codec.
1313
Earlier SDK versions remain historical releases and are not alternate supported
1414
2.0 baselines; no prerelease compatibility shim is provided.
1515

1616
### Added
17+
- List-based activity, child-workflow, and timer fan-out now emits the stable
18+
language-neutral parallel-group identity and path metadata consumed by
19+
service-mode and embedded replay implementations.
1720
- Declared update validators now run through durable, synchronous pre-accept
1821
worker tasks. Capability discovery fails closed, validation replay does not
1922
invoke the handler or commit workflow state, and typed failures preserve the

‎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.32"
7+
version = "2.0.0-rc.33"
88
description = "Release candidate Python SDK for the Durable Workflow 2.0 train"
99
readme = "README.md"
1010
requires-python = ">=3.10"
@@ -68,9 +68,9 @@ durable-workflow-replay-conformance = "durable_workflow.replay_conformance:main"
6868
durable-workflow-workflow-updates-conformance = "durable_workflow.workflow_updates_conformance:main"
6969

7070
[tool.durable-workflow]
71-
product-train = "2.0.0-rc.32"
72-
registry-version = "2.0.0rc32"
73-
supported-server-versions = "2.0.0-rc.32"
71+
product-train = "2.0.0-rc.33"
72+
registry-version = "2.0.0rc33"
73+
supported-server-versions = "2.0.0-rc.39"
7474
worker-protocol-version = "1.1"
7575
control-plane-version = "2"
7676

‎src/durable_workflow/workflow.py‎

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import random
2626
import uuid
2727
from collections.abc import Callable, Iterable, Mapping, Sequence
28+
from copy import copy
2829
from dataclasses import dataclass, field
2930
from datetime import datetime, timezone
3031
from typing import Any, TypeVar, cast
@@ -450,6 +451,12 @@ class ScheduleActivity:
450451
schedule_to_start_timeout: int | None = None
451452
schedule_to_close_timeout: int | None = None
452453
heartbeat_timeout: int | None = None
454+
_parallel_group_path: list[dict[str, Any]] | None = field(
455+
default=None,
456+
init=False,
457+
repr=False,
458+
compare=False,
459+
)
453460

454461
def to_server_command(
455462
self,
@@ -535,6 +542,12 @@ class StartTimer:
535542
"""Command requesting a durable timer."""
536543

537544
delay_seconds: int
545+
_parallel_group_path: list[dict[str, Any]] | None = field(
546+
default=None,
547+
init=False,
548+
repr=False,
549+
compare=False,
550+
)
538551

539552
def to_server_command(
540553
self,
@@ -771,6 +784,12 @@ class StartChildWorkflow:
771784
retry_policy: ChildWorkflowRetryPolicyInput | None = None
772785
execution_timeout_seconds: int | None = None
773786
run_timeout_seconds: int | None = None
787+
_parallel_group_path: list[dict[str, Any]] | None = field(
788+
default=None,
789+
init=False,
790+
repr=False,
791+
compare=False,
792+
)
774793

775794
def to_server_command(
776795
self,
@@ -1004,6 +1023,18 @@ def _condition_predicate_fingerprint(predicate: Callable[[], bool]) -> str:
10041023
)
10051024

10061025

1026+
def _apply_parallel_group_metadata(
1027+
command: Command,
1028+
server_command: dict[str, Any],
1029+
) -> None:
1030+
path = getattr(command, "_parallel_group_path", None)
1031+
if not path:
1032+
return
1033+
1034+
server_command.update(path[-1])
1035+
server_command["parallel_group_path"] = [dict(entry) for entry in path]
1036+
1037+
10071038
def commands_to_server_commands(
10081039
commands: Sequence[Command],
10091040
task_queue: str,
@@ -1178,6 +1209,9 @@ def commands_to_server_commands(
11781209
for (index, key, _, _), blob in zip(encode_jobs, blobs, strict=True):
11791210
server_commands[index][key] = blob
11801211

1212+
for command, server_command in zip(commands, server_commands, strict=True):
1213+
_apply_parallel_group_metadata(command, server_command)
1214+
11811215
return server_commands
11821216

11831217

@@ -3143,6 +3177,54 @@ def _same_logical_condition_wait(opened: Mapping[str, Any], cmd: WaitCondition)
31433177
advanced_cmd: Any = None
31443178
terminal_condition_reopen_cmd: WaitCondition | None = None
31453179

3180+
def _annotate_parallel_commands(commands: list[Any]) -> list[Any]:
3181+
if not commands:
3182+
return commands
3183+
if len(commands) > 1000:
3184+
raise ValueError("parallel workflow group exceeds the deterministic limit of 1000 operations")
3185+
if not all(isinstance(command, ScheduleActivity | StartTimer | StartChildWorkflow) for command in commands):
3186+
return commands
3187+
3188+
kinds = {
3189+
"activity"
3190+
if isinstance(command, ScheduleActivity)
3191+
else "timer"
3192+
if isinstance(command, StartTimer)
3193+
else "child"
3194+
for command in commands
3195+
}
3196+
kind = next(iter(kinds)) if len(kinds) == 1 else "mixed"
3197+
prefix = {
3198+
"activity": "parallel-activities",
3199+
"child": "parallel-children",
3200+
"timer": "parallel-timers",
3201+
"mixed": "parallel-calls",
3202+
}[kind]
3203+
candidates = _unconsumed_recorded_steps()
3204+
if candidates:
3205+
base_sequence = candidates[0].workflow_sequence
3206+
else:
3207+
recorded_sequences = [
3208+
step.workflow_sequence for step in recorded_steps + recorded_wait_steps + recorded_pending_steps
3209+
]
3210+
base_sequence = max(recorded_sequences, default=0) + len(pending) + 1
3211+
3212+
group_id = f"{prefix}:{base_sequence}:{len(commands)}"
3213+
annotated_commands: list[Any] = []
3214+
for index, command in enumerate(commands):
3215+
occurrence = copy(command)
3216+
occurrence._parallel_group_path = [
3217+
{
3218+
"parallel_group_id": group_id,
3219+
"parallel_group_kind": kind,
3220+
"parallel_group_base_sequence": base_sequence,
3221+
"parallel_group_size": len(commands),
3222+
"parallel_group_index": index,
3223+
}
3224+
]
3225+
annotated_commands.append(occurrence)
3226+
return annotated_commands
3227+
31463228
def _condition_wait_has_pending_receivers(condition_wait_id: str | None) -> bool:
31473229
if condition_wait_id is None:
31483230
return False
@@ -3194,6 +3276,7 @@ def _terminal_state(value: Any, *, include_pending: bool) -> _ReplayState:
31943276
if isinstance(cmd, list):
31953277
if any(isinstance(child_command, NexusServiceCall) for child_command in cmd):
31963278
raise TypeError("Nexus service calls must be yielded one at a time")
3279+
cmd = _annotate_parallel_commands(cmd)
31973280
needed = len(cmd)
31983281
if result_cursor + needed <= len(resolved_results):
31993282
for offset, child_command in enumerate(cmd):
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/durable-workflow/.github/main/regression-corpus/evidence-schema.json",
3+
"fixture_schema": "durable-workflow.replay-regression/v1",
4+
"id": "parallel-group-metadata-emission",
5+
"protocol_version": "1.1",
6+
"bindings": [
7+
"python"
8+
],
9+
"workflow": {
10+
"type": "tests.replay.parallel-metadata-producer",
11+
"input": [],
12+
"payload_codec": "avro"
13+
},
14+
"history": [
15+
{
16+
"event_type": "WorkflowStarted",
17+
"payload": {
18+
"workflow_type": "tests.replay.parallel-metadata-producer"
19+
}
20+
}
21+
],
22+
"expected": {
23+
"command_sequence": [
24+
{
25+
"type": "schedule_activity",
26+
"parallel_group_id": "parallel-calls:1:3",
27+
"parallel_group_kind": "mixed",
28+
"parallel_group_base_sequence": 1,
29+
"parallel_group_size": 3,
30+
"parallel_group_index": 0,
31+
"parallel_group_path": [
32+
{
33+
"parallel_group_id": "parallel-calls:1:3",
34+
"parallel_group_kind": "mixed",
35+
"parallel_group_base_sequence": 1,
36+
"parallel_group_size": 3,
37+
"parallel_group_index": 0
38+
}
39+
]
40+
},
41+
{
42+
"type": "start_child_workflow",
43+
"parallel_group_id": "parallel-calls:1:3",
44+
"parallel_group_kind": "mixed",
45+
"parallel_group_base_sequence": 1,
46+
"parallel_group_size": 3,
47+
"parallel_group_index": 1,
48+
"parallel_group_path": [
49+
{
50+
"parallel_group_id": "parallel-calls:1:3",
51+
"parallel_group_kind": "mixed",
52+
"parallel_group_base_sequence": 1,
53+
"parallel_group_size": 3,
54+
"parallel_group_index": 1
55+
}
56+
]
57+
},
58+
{
59+
"type": "start_timer",
60+
"parallel_group_id": "parallel-calls:1:3",
61+
"parallel_group_kind": "mixed",
62+
"parallel_group_base_sequence": 1,
63+
"parallel_group_size": 3,
64+
"parallel_group_index": 2,
65+
"parallel_group_path": [
66+
{
67+
"parallel_group_id": "parallel-calls:1:3",
68+
"parallel_group_kind": "mixed",
69+
"parallel_group_base_sequence": 1,
70+
"parallel_group_size": 3,
71+
"parallel_group_index": 2
72+
}
73+
]
74+
}
75+
]
76+
}
77+
}

‎tests/test_api_reference_install.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,15 @@ def run_requirement(
214214
raise PublicRequirementUnavailable(1, ["pip", "install", requirement])
215215
raise subprocess.CalledProcessError(
216216
1,
217-
["python", "-c", "installed durable-workflow 2.0.0rc24, expected 2.0.0rc32"],
217+
["python", "-c", "installed durable-workflow 2.0.0rc24, expected 2.0.0rc33"],
218218
)
219219

220220
monkeypatch.setattr("scripts.check_api_reference_install._run_clean_requirement", run_requirement)
221221

222222
with pytest.raises(PublicRequirementUnavailable):
223223
run_clean_install(identity.requirement, identity, install_attempts=1, install_retry_sleep=0)
224224

225-
assert identity.registry_version == "2.0.0rc32"
225+
assert identity.registry_version == "2.0.0rc33"
226226
assert calls == [identity.exact_requirement]
227227

228228

@@ -233,7 +233,7 @@ def test_stale_documented_range_is_a_hard_failure_after_exact_rc32_exists(
233233
calls: list[str] = []
234234
stale_range = subprocess.CalledProcessError(
235235
1,
236-
["python", "-c", "installed durable-workflow 2.0.0rc24, expected 2.0.0rc32"],
236+
["python", "-c", "installed durable-workflow 2.0.0rc24, expected 2.0.0rc33"],
237237
)
238238

239239
def run_requirement(

‎tests/test_pypi_project_surface.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323

2424
def source_metadata(*, stable: bool = False) -> SourceMetadata:
25-
version = "2.0.0" if stable else "2.0.0-rc.32"
26-
registry_version = "2.0.0" if stable else "2.0.0rc32"
25+
version = "2.0.0" if stable else "2.0.0-rc.33"
26+
registry_version = "2.0.0" if stable else "2.0.0rc33"
2727
return SourceMetadata(
2828
commit="a" * 40,
2929
name="durable-workflow",
@@ -163,7 +163,7 @@ def resolve(requirement: str, *, prerelease: bool) -> object:
163163
monkeypatch.setattr("scripts.check_pypi_project_surface._pip_report", resolve)
164164
monkeypatch.setattr("scripts.check_pypi_project_surface.time.sleep", sleeps.append)
165165

166-
with pytest.raises(ProjectSurfaceError, match="pip selected 2.0.0rc23; expected 2.0.0rc32"):
166+
with pytest.raises(ProjectSurfaceError, match="pip selected 2.0.0rc23; expected 2.0.0rc33"):
167167
main(["--source-ref", "release-source", "--attempts", "30", "--interval-seconds", "10"])
168168

169169
assert requirements == [
@@ -191,14 +191,14 @@ def run_pip(command: list[str], **_: object) -> subprocess.CompletedProcess[str]
191191
if "==" in requirement and pip_attempts[requirement] == 1:
192192
detail = (
193193
f"ERROR: Could not find a version that satisfies the requirement {requirement} "
194-
"(from versions: 0.4.106, 2.0.0rc31)\n"
194+
"(from versions: 0.4.106, 2.0.0rc32)\n"
195195
f"ERROR: No matching distribution found for {requirement}\n"
196196
)
197197
return subprocess.CompletedProcess(command, 1, stdout="", stderr=detail)
198198

199199
version = source.registry_version
200200
if "~=" in requirement and pip_attempts[requirement] == 1:
201-
version = "2.0.0rc31"
201+
version = "2.0.0rc32"
202202
report_path = Path(command[command.index("--report") + 1])
203203
report_path.write_text(json.dumps(pip_report(version)), encoding="utf-8")
204204
return subprocess.CompletedProcess(command, 0, stdout="", stderr="")
@@ -262,7 +262,7 @@ def test_exact_pip_semantic_mismatch_fails_without_retrying(monkeypatch: pytest.
262262
)
263263
monkeypatch.setattr("scripts.check_pypi_project_surface.time.sleep", sleeps.append)
264264

265-
with pytest.raises(ProjectSurfaceError, match="pip selected 2.0.0rc24; expected 2.0.0rc32"):
265+
with pytest.raises(ProjectSurfaceError, match="pip selected 2.0.0rc24; expected 2.0.0rc33"):
266266
main(["--source-ref", "release-source", "--attempts", "30", "--interval-seconds", "10"])
267267

268268
assert requirements == [f"{source.name}=={source.registry_version}"]

‎tests/test_release_docs_source.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
REPO_ROOT = Path(__file__).resolve().parents[1]
77
VALIDATOR = REPO_ROOT / "scripts" / "ci" / "validate-release-docs-source.py"
8-
VERSION = "2.0.0-rc.32"
8+
VERSION = "2.0.0-rc.33"
99

1010

1111
def git(repo: Path, *arguments: str) -> str:

‎tests/test_release_metadata.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ def source_metadata() -> SourceMetadata:
1313
return SourceMetadata(
1414
commit="a" * 40,
1515
name="durable-workflow",
16-
version="2.0.0-rc.32",
17-
registry_version="2.0.0rc32",
16+
version="2.0.0-rc.33",
17+
registry_version="2.0.0rc33",
1818
summary="Release candidate Python SDK for the Durable Workflow 2.0 train",
1919
classifiers=("Programming Language :: Python :: 3",),
2020
readme=(

0 commit comments

Comments
 (0)