Skip to content

Commit 1570a89

Browse files
committed
Add deterministic selection and durable structured concurrency
1 parent 0feba8f commit 1570a89

20 files changed

Lines changed: 3643 additions & 57 deletions

‎CHANGELOG.md‎

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

99
The Python SDK advances to prerelease `2.0.0-rc.37`. PyPI displays the normalized
1010
PEP 440 identity `2.0.0rc37`. This Avro-only SDK release is qualified with Server
11-
`2.0.0-rc.51`; JSON remains HTTP transport and is no longer a workflow payload
11+
`2.0.0-rc.53`; 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.
@@ -17,6 +17,9 @@ Earlier SDK versions remain historical releases and are not alternate supported
1717
- Worker registration now explicitly refuses local activities, worker
1818
sessions, and sticky execution at the portable worker-affinity protocol
1919
floor instead of advertising an unimplemented routing contract.
20+
- `WorkflowContext.select()` starts independent durable operations and returns
21+
the first persisted winner with stable member identity. Non-winning handles
22+
remain available to await or cancel explicitly across replay and restart.
2023
- `WorkflowContext.message_stream()` now consumes named repeated input in
2124
ordered bounded batches. Runtime-owned cursor and wait metadata survives
2225
replay, worker replacement, server restart, duplicates, and continue-as-new
@@ -94,7 +97,7 @@ Earlier SDK versions remain historical releases and are not alternate supported
9497
metadata updates remain consumed exactly once.
9598
- High-level workers now explicitly advertise memo-upsert and typed-search-
9699
attribute command support when registering with Server. Worker requests use
97-
protocol 1.16, while direct `Client.register_worker()` callers retain full
100+
protocol 1.19, while direct `Client.register_worker()` callers retain full
98101
control of their explicit capability list.
99102
- Completed parallel activity, child-workflow, timer, and mixed groups now
100103
replay results and select failures by their durable yielded positions rather

‎pyproject.toml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,11 @@ durable-workflow-workflow-updates-conformance = "durable_workflow.workflow_updat
7070
[tool.durable-workflow]
7171
product-train = "2.0.0-rc.37"
7272
registry-version = "2.0.0rc37"
73-
supported-server-versions = "2.0.0-rc.51"
74-
worker-protocol-version = "1.16"
73+
supported-server-versions = "2.0.0-rc.53"
74+
worker-protocol-version = "1.19"
7575
control-plane-version = "2"
76+
durable-selection = true
77+
durable-selection-minimum-worker-protocol-version = "1.19"
7678
message-streams = true
7779
message-streams-minimum-worker-protocol-version = "1.15"
7880
workflow-streams-contract = "durable-workflow.v2.workflow-streams.contract@1"

‎src/durable_workflow/__init__.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
ChildWorkflowCancelled,
6363
ChildWorkflowFailed,
6464
ChildWorkflowTerminated,
65+
DurableOperationCancelled,
6566
DurableWorkflowError,
6667
ExternalPayloadError,
6768
ExternalPayloadExpired,
@@ -212,12 +213,14 @@
212213
ActivityRetryPolicy,
213214
ChildWorkflowRetryPolicy,
214215
ContinueAsNew,
216+
DurableOperationHandle,
215217
MessageStream,
216218
MessageStreamMessage,
217219
NexusServiceCall,
218220
Replayer,
219221
ReplayOutcome,
220222
Saga,
223+
SelectionResult,
221224
StartChildWorkflow,
222225
replay,
223226
)
@@ -238,6 +241,8 @@
238241
"ChildWorkflowTerminated",
239242
"Client",
240243
"ContinueAsNew",
244+
"DurableOperationCancelled",
245+
"DurableOperationHandle",
241246
"MessageStream",
242247
"MessageStreamMessage",
243248
"NamespaceDescription",
@@ -255,6 +260,7 @@
255260
"Replayer",
256261
"Saga",
257262
"SagaCompensationFailed",
263+
"SelectionResult",
258264
"ScheduleAction",
259265
"ScheduleAlreadyExists",
260266
"ScheduleBackfillResult",

‎src/durable_workflow/client.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
from .nexus import NexusOperationResult, nexus_request_payload
6060
from .retry_policy import TransportRetryPolicy
6161

62-
PROTOCOL_VERSION = "1.16"
62+
PROTOCOL_VERSION = "1.19"
6363
CONTROL_PLANE_VERSION = "2"
6464
PORTABLE_WORKER_AFFINITY_CAPABILITY_MANIFEST: dict[str, dict[str, str | bool]] = {
6565
"local_activities": {
@@ -4585,7 +4585,7 @@ async def register_worker(
45854585
sdk_version: str | None = None,
45864586
build_id: str | None = None,
45874587
capabilities: list[str] | None = None,
4588-
capability_manifest: dict[str, dict[str, Any]] | None = None,
4588+
capability_manifest: dict[str, dict[str, Any]],
45894589
task_slots: dict[str, int] | None = None,
45904590
process_metrics: dict[str, Any] | None = None,
45914591
heartbeat_interval_seconds: int | None = None,
@@ -4596,6 +4596,8 @@ async def register_worker(
45964596
applications should not call this directly — create a
45974597
:class:`~durable_workflow.Worker` instead.
45984598
"""
4599+
if capability_manifest is None:
4600+
raise ValueError("capability_manifest is required for worker registration")
45994601
if sdk_version is None:
46004602
sdk_version = DEFAULT_SDK_VERSION
46014603
if max_concurrent_workflow_tasks is not None and max_concurrent_workflow_tasks < 1:
@@ -4616,15 +4618,14 @@ async def register_worker(
46164618
"sdk_version": sdk_version,
46174619
"supported_workflow_types": supported_workflow_types or [],
46184620
"supported_activity_types": supported_activity_types or [],
4621+
"capability_manifest": capability_manifest,
46194622
}
46204623
if workflow_definition_fingerprints is not None:
46214624
body["workflow_definition_fingerprints"] = workflow_definition_fingerprints
46224625
if workflow_command_contracts is not None:
46234626
body["workflow_command_contracts"] = workflow_command_contracts
46244627
if capabilities is not None:
46254628
body["capabilities"] = [capability for capability in capabilities if capability]
4626-
if capability_manifest is not None:
4627-
body["capability_manifest"] = capability_manifest
46284629
if build_id is not None:
46294630
body["build_id"] = build_id
46304631
if max_concurrent_workflow_tasks is not None:

‎src/durable_workflow/errors.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,25 @@ class DurableWorkflowError(Exception):
2525
"""Base class for every exception raised by the SDK."""
2626

2727

28+
class DurableOperationCancelled(DurableWorkflowError):
29+
"""A durable selection member was explicitly cancelled."""
30+
31+
def __init__(
32+
self,
33+
selection_group_id: str,
34+
member_key: int | str,
35+
member_index: int,
36+
operation_kind: str,
37+
operation_identity: str,
38+
) -> None:
39+
super().__init__(f"Selected {operation_kind} operation {operation_identity} was explicitly cancelled.")
40+
self.selection_group_id = selection_group_id
41+
self.member_key = member_key
42+
self.member_index = member_index
43+
self.operation_kind = operation_kind
44+
self.operation_identity = operation_identity
45+
46+
2847
class RuntimeDiscoveryUnavailable(DurableWorkflowError):
2948
"""Runtime discovery could not prove that an operation is available.
3049

‎src/durable_workflow/worker.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,15 @@
9595
MESSAGE_STREAMS_CAPABILITY = "message_streams"
9696
MEMO_UPSERTS_CAPABILITY = "memo_upserts"
9797
TYPED_SEARCH_ATTRIBUTES_CAPABILITY = "typed_search_attributes"
98+
DURABLE_SELECTION_CAPABILITY = "durable_selection"
9899

99100
# Command capabilities implemented by every high-level Python worker. Keep this
100101
# advertisement explicit: worker capabilities are not inferred from runtime,
101102
# SDK, or protocol-version metadata.
102103
_WORKFLOW_COMMAND_CAPABILITIES = (
103104
MEMO_UPSERTS_CAPABILITY,
104105
TYPED_SEARCH_ATTRIBUTES_CAPABILITY,
106+
DURABLE_SELECTION_CAPABILITY,
105107
)
106108

107109
_WORKFLOW_WORK_TASK_KINDS = ("workflow", "update_validation")

0 commit comments

Comments
 (0)