dex-python-sdk 1.45.2__tar.gz → 1.45.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/PKG-INFO +1 -1
  2. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/__init__.py +18 -1
  3. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/_async_worker_dispatcher.py +4 -0
  4. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/_grpc_errors.py +10 -0
  5. dex_python_sdk-1.45.4/dex/_history_point_mapping.py +156 -0
  6. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/_invocation_context.py +22 -0
  7. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/_server_protocol.py +37 -1
  8. dex_python_sdk-1.45.4/dex/_stop_flow_mapping.py +43 -0
  9. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/_worker_dispatcher.py +22 -1
  10. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/async_client.py +164 -48
  11. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/client.py +175 -48
  12. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/condition.py +79 -0
  13. dex_python_sdk-1.45.4/dex/dexpb/dex_pb2.py +471 -0
  14. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/dexpb/dex_pb2.pyi +146 -12
  15. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/dexpb/dex_pb2_grpc.py +43 -0
  16. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/flow_options.py +394 -1
  17. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/flow_result.py +8 -2
  18. dex_python_sdk-1.45.4/dex/graceful_completion_context.py +108 -0
  19. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/runtime_errors.py +115 -0
  20. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/wait.py +7 -3
  21. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/pyproject.toml +1 -1
  22. dex_python_sdk-1.45.2/dex/dexpb/dex_pb2.py +0 -457
  23. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/LEGACY_NOTICES.md +0 -0
  24. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/LICENSE +0 -0
  25. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/README.md +0 -0
  26. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/_async_value_hydrator.py +0 -0
  27. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/_attribute_reads.py +0 -0
  28. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/_credential_transport.py +0 -0
  29. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/_flow_definition_upload.py +0 -0
  30. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/_flow_service_tls.py +0 -0
  31. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/_message_size.py +0 -0
  32. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/_native.pyi +0 -0
  33. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/_pull_worker.py +0 -0
  34. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/_task_queue_names.py +0 -0
  35. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/_utils.py +0 -0
  36. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/_value_hydrator.py +0 -0
  37. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/_value_mapper.py +0 -0
  38. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/action.py +0 -0
  39. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/async_worker.py +0 -0
  40. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/attribute.py +0 -0
  41. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/attribute_match.py +0 -0
  42. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/attribute_values.py +0 -0
  43. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/blob_cache.py +0 -0
  44. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/channel.py +0 -0
  45. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/client_options.py +0 -0
  46. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/codec.py +0 -0
  47. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/context.py +0 -0
  48. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/credential.py +0 -0
  49. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/dexpb/__init__.py +0 -0
  50. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/flow.py +0 -0
  51. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/flow_config.py +0 -0
  52. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/flow_definition.py +0 -0
  53. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/flow_info.py +0 -0
  54. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/flow_service_tls_options.py +0 -0
  55. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/flow_state.py +0 -0
  56. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/join.py +0 -0
  57. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/pull_registration.py +0 -0
  58. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/py.typed +0 -0
  59. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/rpc_invoke_options.py +0 -0
  60. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/step.py +0 -0
  61. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/step_execution.py +0 -0
  62. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/stream.py +0 -0
  63. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/subflow.py +0 -0
  64. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/timer.py +0 -0
  65. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/wait_options.py +0 -0
  66. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/worker.py +0 -0
  67. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/dex/worker_options.py +0 -0
  68. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/sdk-rust/Cargo.lock +0 -0
  69. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/sdk-rust/Cargo.toml +0 -0
  70. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/sdk-rust/crates/dex-blob-cache/Cargo.toml +0 -0
  71. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/sdk-rust/crates/dex-blob-cache/LICENSE +0 -0
  72. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/sdk-rust/crates/dex-blob-cache/README.md +0 -0
  73. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/sdk-rust/crates/dex-blob-cache/src/config.rs +0 -0
  74. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/sdk-rust/crates/dex-blob-cache/src/entry.rs +0 -0
  75. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/sdk-rust/crates/dex-blob-cache/src/error.rs +0 -0
  76. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/sdk-rust/crates/dex-blob-cache/src/format.rs +0 -0
  77. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/sdk-rust/crates/dex-blob-cache/src/lib.rs +0 -0
  78. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/sdk-rust/crates/dex-blob-cache/src/policy.rs +0 -0
  79. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/sdk-rust/crates/dex-blob-cache/src/store.rs +0 -0
  80. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/sdk-rust/crates/dex-blob-cache/tests/blob_cache_integration.rs +0 -0
  81. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/sdk-rust/crates/dex-blob-cache-python/Cargo.toml +0 -0
  82. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/sdk-rust/crates/dex-blob-cache-python/LICENSE +0 -0
  83. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/sdk-rust/crates/dex-blob-cache-python/README.md +0 -0
  84. {dex_python_sdk-1.45.2 → dex_python_sdk-1.45.4}/sdk-rust/crates/dex-blob-cache-python/src/lib.rs +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dex-python-sdk
3
- Version: 1.45.2
3
+ Version: 1.45.4
4
4
  Requires-Dist: grpcio>=1.83.0
5
5
  Requires-Dist: grpcio-status>=1.83.0
6
6
  Requires-Dist: protobuf>=7.35.1
@@ -45,8 +45,12 @@ from dex.codec import (
45
45
  Value,
46
46
  WireKind,
47
47
  )
48
- from dex.condition import ConditionCombination
48
+ from dex.condition import ConditionCombination, graceful_completion_requested
49
49
  from dex.context import AsyncContext, Context, RecoveryErrorInfo, StepAttemptProgress
50
+ from dex.graceful_completion_context import (
51
+ is_graceful_completion_condition_completed,
52
+ supports_graceful_completion_condition,
53
+ )
50
54
  from dex.credential import (
51
55
  ApiKeyCredential,
52
56
  ApiKeyExchangeError,
@@ -78,6 +82,8 @@ from dex.flow_state import (
78
82
  StepMethodPendingReason,
79
83
  )
80
84
  from dex.flow_options import (
85
+ CloneForkFlowOptions,
86
+ CloneForkFlowResult,
81
87
  FlowTimeoutHandlerOptions,
82
88
  FlowTimeoutPolicy,
83
89
  IdReusePolicy,
@@ -85,6 +91,7 @@ from dex.flow_options import (
85
91
  StopFlowOptions,
86
92
  StopType,
87
93
  SubFlowOptions,
94
+ SubFlowResetPolicy,
88
95
  SubFlowReusePolicy,
89
96
  TimeTravelOptions,
90
97
  TimeTravelStepMethod,
@@ -104,6 +111,7 @@ from dex.runtime_errors import (
104
111
  ChannelMessageNotFoundError,
105
112
  ChannelMessagesNotLoadedError,
106
113
  BlobMessageTooLargeError,
114
+ CloneForkFlowUnsupportedError,
107
115
  DexServiceError,
108
116
  ErrorSubStatus,
109
117
  FlowAlreadyStartedError,
@@ -112,6 +120,7 @@ from dex.runtime_errors import (
112
120
  FlowErrorType,
113
121
  FlowNotActiveOrNotFoundError,
114
122
  FlowNotFoundError,
123
+ GracefulCompletionConditionUnsupportedError,
115
124
  InvalidStepResultError,
116
125
  LongPollTimeoutError,
117
126
  RequestTimeoutError,
@@ -247,6 +256,11 @@ __all__ = [
247
256
  "TimeTravelOptions",
248
257
  "TimeTravelStepMethod",
249
258
  "TimeTravelType",
259
+ "CloneForkFlowOptions",
260
+ "CloneForkFlowResult",
261
+ "CloneForkFlowUnsupportedError",
262
+ "GracefulCompletionConditionUnsupportedError",
263
+ "SubFlowResetPolicy",
250
264
  "RetryPolicy",
251
265
  "SearchFlowEntry",
252
266
  "SearchFlowsPage",
@@ -291,7 +305,10 @@ __all__ = [
291
305
  "force_complete_if_channels_empty",
292
306
  "force_fail",
293
307
  "graceful_complete",
308
+ "graceful_completion_requested",
294
309
  "heartbeat",
310
+ "is_graceful_completion_condition_completed",
311
+ "supports_graceful_completion_condition",
295
312
  "go_to",
296
313
  "go_to_many",
297
314
  "open_blob_cache",
@@ -118,6 +118,7 @@ class AsyncWorkerDispatcher(WorkerDispatcher):
118
118
  is_active=is_active,
119
119
  deadline=deadline,
120
120
  output_emitter=emitter,
121
+ server_protocol=self._server_protocol,
121
122
  )
122
123
  input = self._values.decode(request.step_input, step.input_codec)
123
124
  response: pb.InvokeWaitForMethodResponse | None = None
@@ -227,6 +228,7 @@ class AsyncWorkerDispatcher(WorkerDispatcher):
227
228
  is_active=is_active,
228
229
  deadline=deadline,
229
230
  output_emitter=emitter,
231
+ server_protocol=self._server_protocol,
230
232
  )
231
233
  input = self._values.decode(request.step_input, step.input_codec)
232
234
  response: pb.InvokeExecuteMethodResponse | None = None
@@ -313,6 +315,7 @@ class AsyncWorkerDispatcher(WorkerDispatcher):
313
315
  is_active=is_active,
314
316
  deadline=deadline,
315
317
  output_emitter=emitter,
318
+ server_protocol=self._server_protocol,
316
319
  )
317
320
  response: pb.InvokeExecuteMethodResponse | None = None
318
321
  failure: BaseException | None = None
@@ -379,6 +382,7 @@ class AsyncWorkerDispatcher(WorkerDispatcher):
379
382
  loaded_channel_names=request.loaded_channel_names,
380
383
  loaded_channel_map_instances=request.loaded_channel_map_instances,
381
384
  is_active=is_active,
385
+ server_protocol=self._server_protocol,
382
386
  )
383
387
  arguments: list[object] = [context]
384
388
  if rpc.input_codec is not None:
@@ -152,6 +152,16 @@ def translate_rpc_error(
152
152
  return DexServiceError(*parameters)
153
153
 
154
154
 
155
+ def translate_clone_fork_flow_error(
156
+ error: grpc.RpcError, source_flow_id: str, flow_id: str
157
+ ) -> DexServiceError:
158
+ """Attribute not-found to the source Flow and every other error to the new Flow."""
159
+ translated = translate_rpc_error(error, "clone_fork_flow", flow_id, "none")
160
+ if translated.sub_status is ErrorSubStatus.FLOW_NOT_EXISTS:
161
+ return translate_rpc_error(error, "clone_fork_flow", source_flow_id, "existing")
162
+ return translated
163
+
164
+
155
165
  def _worker_code(details: pb.ServiceErrorResponse | None) -> grpc.StatusCode | None:
156
166
  if details is None or details.original_worker_error_status == 0:
157
167
  return None
@@ -0,0 +1,156 @@
1
+ # Copyright (c) 2026 Super Durable, Inc.
2
+ #
3
+ # Licensed under the Sustainable Use License 1.0.
4
+ # You may not use this file except in compliance with the License.
5
+ # See the LICENSE file in the repository root.
6
+ #
7
+ # SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
8
+
9
+ from __future__ import annotations
10
+
11
+ from collections.abc import Iterable
12
+ from datetime import datetime
13
+ from uuid import uuid4
14
+
15
+ from dex.dexpb import dex_pb2 as pb
16
+ from dex.flow_options import (
17
+ CloneForkFlowOptions,
18
+ CloneForkFlowResult,
19
+ IdReusePolicy,
20
+ SubFlowResetPolicy,
21
+ TimeTravelOptions,
22
+ TimeTravelStepMethod,
23
+ TimeTravelType,
24
+ _validate_history_point,
25
+ )
26
+
27
+ _RESET_TYPES = {
28
+ TimeTravelType.BEGINNING: pb.FLOW_RESET_TYPE_BEGINNING,
29
+ TimeTravelType.HISTORY_EVENT_TIME: pb.FLOW_RESET_TYPE_HISTORY_EVENT_TIME,
30
+ TimeTravelType.STEP_TYPE: pb.FLOW_RESET_TYPE_STEP_TYPE,
31
+ TimeTravelType.STEP_EXECUTION_ID: pb.FLOW_RESET_TYPE_STEP_EXECUTION_ID,
32
+ TimeTravelType.EVENT_ID: pb.FLOW_RESET_TYPE_EVENT_ID,
33
+ }
34
+
35
+ _CLONE_FORK_POINT_TYPES = {
36
+ TimeTravelType.CURRENT: pb.FLOW_CLONE_FORK_POINT_TYPE_CURRENT,
37
+ TimeTravelType.BEGINNING: pb.FLOW_CLONE_FORK_POINT_TYPE_BEGINNING,
38
+ TimeTravelType.HISTORY_EVENT_TIME: pb.FLOW_CLONE_FORK_POINT_TYPE_HISTORY_EVENT_TIME,
39
+ TimeTravelType.STEP_TYPE: pb.FLOW_CLONE_FORK_POINT_TYPE_STEP_TYPE,
40
+ TimeTravelType.STEP_EXECUTION_ID: pb.FLOW_CLONE_FORK_POINT_TYPE_STEP_EXECUTION_ID,
41
+ TimeTravelType.EVENT_ID: pb.FLOW_CLONE_FORK_POINT_TYPE_EVENT_ID,
42
+ }
43
+
44
+ _STEP_METHODS = {
45
+ TimeTravelStepMethod.WAIT_FOR: pb.FLOW_RESET_STEP_METHOD_WAIT_FOR,
46
+ TimeTravelStepMethod.EXECUTE: pb.FLOW_RESET_STEP_METHOD_EXECUTE,
47
+ }
48
+
49
+ _SUB_FLOW_RESET_POLICIES = {
50
+ SubFlowResetPolicy.DEFAULT: pb.SUB_FLOW_RESET_POLICY_UNSPECIFIED,
51
+ SubFlowResetPolicy.ALWAYS_RESTART: pb.SUB_FLOW_RESET_POLICY_ALWAYS_RESTART,
52
+ SubFlowResetPolicy.ALWAYS_FAIL: pb.SUB_FLOW_RESET_POLICY_ALWAYS_FAIL,
53
+ SubFlowResetPolicy.ALWAYS_REJECT: pb.SUB_FLOW_RESET_POLICY_ALWAYS_REJECT,
54
+ SubFlowResetPolicy.ATTACH_ELSE_RESTART: pb.SUB_FLOW_RESET_POLICY_ATTACH_ELSE_RESTART,
55
+ SubFlowResetPolicy.ATTACH_ELSE_FAIL: pb.SUB_FLOW_RESET_POLICY_ATTACH_ELSE_FAIL,
56
+ SubFlowResetPolicy.ATTACH_ELSE_REJECT: pb.SUB_FLOW_RESET_POLICY_ATTACH_ELSE_REJECT,
57
+ }
58
+
59
+ _ID_REUSE_POLICIES = {
60
+ IdReusePolicy.DEFAULT: pb.ID_REUSE_POLICY_UNSPECIFIED,
61
+ IdReusePolicy.ALLOW_IF_PREVIOUS_FAILED: (
62
+ pb.ID_REUSE_POLICY_ALLOW_IF_PREVIOUS_EXISTS_ABNORMALLY
63
+ ),
64
+ IdReusePolicy.ALLOW_IF_NOT_RUNNING: pb.ID_REUSE_POLICY_ALLOW_IF_NO_RUNNING,
65
+ IdReusePolicy.ALLOW_TERMINATE_IF_RUNNING: (
66
+ pb.ID_REUSE_POLICY_ALLOW_TERMINATE_IF_RUNNING
67
+ ),
68
+ IdReusePolicy.DISALLOW: pb.ID_REUSE_POLICY_DISALLOW_REUSE,
69
+ }
70
+
71
+
72
+ def map_time_travel_request(
73
+ flow_id: str, options: TimeTravelOptions
74
+ ) -> pb.ResetFlowRequest:
75
+ """Map time travel options; only the event ID selector is validated, as before."""
76
+ if options.type is TimeTravelType.CURRENT:
77
+ raise ValueError("time travel type CURRENT is valid only for clone_fork_flow")
78
+ if options.type is TimeTravelType.EVENT_ID or options.event_id is not None:
79
+ _validate_history_point(
80
+ "time travel",
81
+ options.type,
82
+ options.history_event_time,
83
+ options.step_type,
84
+ options.step_execution_id,
85
+ options.step_method,
86
+ options.event_id,
87
+ )
88
+ request = pb.ResetFlowRequest(
89
+ flow_id=flow_id,
90
+ reset_type=_RESET_TYPES[options.type],
91
+ reason=options.reason or "",
92
+ skip_writes_reapply=options.skip_writes_reapply,
93
+ sub_flow_reset_policy=_SUB_FLOW_RESET_POLICIES[options.sub_flow_reset_policy],
94
+ )
95
+ if options.history_event_time is not None:
96
+ request.history_event_time = options.history_event_time.isoformat()
97
+ if options.step_type is not None:
98
+ request.step_type = options.step_type
99
+ if options.step_execution_id is not None:
100
+ request.step_execution_id = options.step_execution_id
101
+ if options.step_method is not None:
102
+ request.step_method = _STEP_METHODS[options.step_method]
103
+ if options.event_id is not None:
104
+ request.event_id = options.event_id
105
+ return request
106
+
107
+
108
+ def map_clone_fork_flow_request(
109
+ source_flow_id: str,
110
+ flow_id: str,
111
+ options: CloneForkFlowOptions,
112
+ flow_config_override: pb.FlowConfig | None,
113
+ attributes: Iterable[pb.AttributeWrite],
114
+ timeout_seconds: int,
115
+ ) -> pb.CloneForkFlowRequest:
116
+ request = pb.CloneForkFlowRequest(
117
+ source_flow_id=source_flow_id,
118
+ source_run_id=options.source_run_id,
119
+ flow_id=flow_id,
120
+ request_id=options.request_id or str(uuid4()),
121
+ id_reuse_policy=_ID_REUSE_POLICIES[options.id_reuse_policy],
122
+ flow_timeout_seconds=timeout_seconds,
123
+ reason=options.reason or "",
124
+ point_type=_CLONE_FORK_POINT_TYPES[options.type],
125
+ history_event_time=_format_history_event_time(options.history_event_time),
126
+ step_type=options.step_type or "",
127
+ step_execution_id=options.step_execution_id or "",
128
+ event_id=options.event_id or 0,
129
+ run_attempt=options.source_run_attempt,
130
+ sub_flow_reset_policy=_SUB_FLOW_RESET_POLICIES[options.sub_flow_reset_policy],
131
+ )
132
+ if options.ignore_already_started:
133
+ request.flow_already_started_options.ignore_already_started_error = True
134
+ if options.step_method is not None:
135
+ request.step_method = _STEP_METHODS[options.step_method]
136
+ if flow_config_override is not None:
137
+ request.flow_config_override.CopyFrom(flow_config_override)
138
+ request.attributes.extend(attributes)
139
+ return request
140
+
141
+
142
+ def clone_fork_flow_result_from_proto(
143
+ response: pb.CloneForkFlowResponse,
144
+ ) -> CloneForkFlowResult:
145
+ if not response.run_id:
146
+ raise RuntimeError("CloneForkFlow response has no run ID")
147
+ return CloneForkFlowResult(
148
+ run_id=response.run_id,
149
+ source_run_id=response.source_run_id,
150
+ source_run_attempt=response.source_run_attempt,
151
+ source_event_id=response.source_event_id,
152
+ )
153
+
154
+
155
+ def _format_history_event_time(history_event_time: datetime | None) -> str:
156
+ return "" if history_event_time is None else history_event_time.isoformat()
@@ -13,6 +13,7 @@ from enum import Enum
13
13
  from typing import Any, Callable, Protocol, Sequence, TypeVar, cast
14
14
  from urllib.parse import unquote
15
15
 
16
+ from dex._server_protocol import NegotiatedServerProtocol
16
17
  from dex._utils import require_map_instance, require_name
17
18
  from dex._value_mapper import ValueMapper
18
19
  from dex.attribute import (
@@ -84,8 +85,15 @@ class InvocationContext:
84
85
  is_active: Callable[[], bool] | None = None,
85
86
  output_emitter: _StepOutputEmitter | None = None,
86
87
  deadline: datetime | None = None,
88
+ server_protocol: NegotiatedServerProtocol | None = None,
87
89
  ) -> None:
88
90
  self._deadline = None if method is InvocationMethod.RPC else deadline
91
+ # None means a test or fake context with no negotiated Server.
92
+ self._server_protocol = (
93
+ server_protocol
94
+ if server_protocol is not None
95
+ else NegotiatedServerProtocol()
96
+ )
89
97
  self._method = method
90
98
  self._flow = flow
91
99
  self._metadata = metadata
@@ -206,6 +214,20 @@ class InvocationContext:
206
214
  and results[index].condition_status == pb.CONDITION_STATUS_COMPLETED
207
215
  )
208
216
 
217
+ def is_graceful_completion_condition_completed(self) -> bool:
218
+ if (
219
+ self._method is not InvocationMethod.EXECUTE
220
+ or self._condition_results is None
221
+ ):
222
+ return False
223
+ return any(
224
+ result.condition_status == pb.CONDITION_STATUS_COMPLETED
225
+ for result in self._condition_results.graceful_completion_results
226
+ )
227
+
228
+ def supports_graceful_completion_condition(self) -> bool:
229
+ return self._server_protocol.supports_graceful_completion_condition()
230
+
209
231
  def wait_for_method_failed(self) -> bool:
210
232
  return bool(
211
233
  self._condition_results is not None
@@ -15,11 +15,19 @@ from typing import Iterable
15
15
  import grpc
16
16
 
17
17
  from dex.dexpb import dex_pb2 as pb
18
+ from dex.runtime_errors import (
19
+ CloneForkFlowUnsupportedError,
20
+ GracefulCompletionConditionUnsupportedError,
21
+ )
18
22
 
19
23
  MINIMUM_SUPPORTED_SERVER_PROTOCOL_VERSION = 4
20
- MAXIMUM_SUPPORTED_SERVER_PROTOCOL_VERSION = 5
24
+ MAXIMUM_SUPPORTED_SERVER_PROTOCOL_VERSION = 7
21
25
  HARD_DELETE_ATTRIBUTE_PROTOCOL_VERSION = 3
22
26
  NAMED_TASK_QUEUE_PROTOCOL_VERSION = 5
27
+ CLONE_FORK_FLOW_PROTOCOL_VERSION = 6
28
+ CLONE_FORK_FLOW_SERVER_ZD_RELEASE = "server-zd 0.1.33"
29
+ GRACEFUL_COMPLETION_CONDITION_PROTOCOL_VERSION = 7
30
+ GRACEFUL_COMPLETION_CONDITION_SERVER_ZD_RELEASE = "server-zd 0.1.34"
23
31
  LAST_SERVER_ZD_RELEASE_BEFORE_MINIMUM_PROTOCOL = "v0.1.16"
24
32
 
25
33
 
@@ -108,6 +116,34 @@ class NegotiatedServerProtocol:
108
116
  "the default task queue"
109
117
  )
110
118
 
119
+ def require_clone_fork_flow_support(self) -> None:
120
+ if self._version >= CLONE_FORK_FLOW_PROTOCOL_VERSION:
121
+ return
122
+ raise CloneForkFlowUnsupportedError(
123
+ self._version,
124
+ CLONE_FORK_FLOW_PROTOCOL_VERSION,
125
+ CLONE_FORK_FLOW_SERVER_ZD_RELEASE,
126
+ )
127
+
128
+ def supports_graceful_completion_condition(self) -> bool:
129
+ return self._version >= GRACEFUL_COMPLETION_CONDITION_PROTOCOL_VERSION
130
+
131
+ def require_graceful_completion_condition_support(
132
+ self,
133
+ waiting: pb.WaitingCondition,
134
+ ) -> None:
135
+ # An older Server drops the condition, so fail closed instead.
136
+ if (
137
+ not waiting.graceful_completion_conditions
138
+ or self.supports_graceful_completion_condition()
139
+ ):
140
+ return
141
+ raise GracefulCompletionConditionUnsupportedError(
142
+ self._version,
143
+ GRACEFUL_COMPLETION_CONDITION_PROTOCOL_VERSION,
144
+ GRACEFUL_COMPLETION_CONDITION_SERVER_ZD_RELEASE,
145
+ )
146
+
111
147
 
112
148
  def server_info_request_error(
113
149
  artifact_version: str, failure: grpc.RpcError
@@ -0,0 +1,43 @@
1
+ # Copyright (c) 2026 Super Durable, Inc.
2
+ #
3
+ # Licensed under the Sustainable Use License 1.0.
4
+ # You may not use this file except in compliance with the License.
5
+ # See the LICENSE file in the repository root.
6
+ #
7
+ # SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
8
+
9
+ from __future__ import annotations
10
+
11
+ from dex._utils import require_name
12
+ from dex._value_mapper import ValueMapper
13
+ from dex.dexpb import dex_pb2 as pb
14
+ from dex.flow_options import StopFlowOptions, StopType
15
+
16
+ _STOP_TYPES = {
17
+ StopType.CANCEL: pb.STOP_TYPE_CANCEL,
18
+ StopType.TERMINATE: pb.STOP_TYPE_TERMINATE,
19
+ StopType.FAIL: pb.STOP_TYPE_FAIL,
20
+ StopType.GRACEFUL_COMPLETE: pb.STOP_TYPE_GRACEFUL_COMPLETE,
21
+ StopType.FORCE_COMPLETE: pb.STOP_TYPE_FORCE_COMPLETE,
22
+ }
23
+
24
+ _COMPLETE_STOP_TYPES = frozenset({StopType.GRACEFUL_COMPLETE, StopType.FORCE_COMPLETE})
25
+
26
+
27
+ def map_stop_flow_request(
28
+ flow_id: str, options: StopFlowOptions, values: ValueMapper
29
+ ) -> pb.StopFlowRequest:
30
+ request = pb.StopFlowRequest(
31
+ flow_id=require_name(flow_id),
32
+ reason=options.reason or "",
33
+ stop_type=_STOP_TYPES[options.type],
34
+ )
35
+ if options.output is None:
36
+ return request
37
+ if options.type not in _COMPLETE_STOP_TYPES:
38
+ raise ValueError(
39
+ "StopFlowOptions.output requires StopType.GRACEFUL_COMPLETE or "
40
+ "StopType.FORCE_COMPLETE"
41
+ )
42
+ request.output.CopyFrom(values.encode_dynamic(options.output))
43
+ return request
@@ -26,7 +26,13 @@ from dex.attribute import (
26
26
  _require_matching_hard_delete_on_null,
27
27
  )
28
28
  from dex.channel import Channel, ChannelMap, ChannelMapLoad
29
- from dex.condition import ChannelCondition, Condition, SubFlowCondition, TimerCondition
29
+ from dex.condition import (
30
+ ChannelCondition,
31
+ Condition,
32
+ GracefulCompletionCondition,
33
+ SubFlowCondition,
34
+ TimerCondition,
35
+ )
30
36
  from dex.dexpb import dex_pb2 as pb
31
37
  from dex.flow import Registry, RPCResult, _RegisteredFlow, _RegisteredStep
32
38
  from dex.flow_config import ActiveStepSearchMode, FlowConfig
@@ -95,6 +101,7 @@ class WorkerDispatcher:
95
101
  loaded_channel_map_instances=request.loaded_channel_map_instances,
96
102
  is_active=is_active,
97
103
  deadline=deadline,
104
+ server_protocol=self._server_protocol,
98
105
  )
99
106
  input = self._values.decode(request.step_input, step.input_codec)
100
107
  wait = step.step.wait_for(context, input)
@@ -160,6 +167,7 @@ class WorkerDispatcher:
160
167
  loaded_channel_map_instances=request.loaded_channel_map_instances,
161
168
  is_active=is_active,
162
169
  deadline=deadline,
170
+ server_protocol=self._server_protocol,
163
171
  )
164
172
  input = self._values.decode(request.step_input, step.input_codec)
165
173
  decision = step.step.execute(context, input)
@@ -227,6 +235,7 @@ class WorkerDispatcher:
227
235
  loaded_channel_names=request.loaded_channel_names,
228
236
  loaded_channel_map_instances=request.loaded_channel_map_instances,
229
237
  deadline=deadline,
238
+ server_protocol=self._server_protocol,
230
239
  )
231
240
  decision = flow.flow.handle_timeout(context)
232
241
  if isgenerator(decision):
@@ -288,6 +297,7 @@ class WorkerDispatcher:
288
297
  loaded_channel_names=request.loaded_channel_names,
289
298
  loaded_channel_map_instances=request.loaded_channel_map_instances,
290
299
  is_active=is_active,
300
+ server_protocol=self._server_protocol,
291
301
  )
292
302
  arguments: list[object] = [context]
293
303
  if rpc.input_codec is not None:
@@ -661,6 +671,8 @@ class WorkerDispatcher:
661
671
  waiting.timer_conditions.extend(mapper.timers)
662
672
  waiting.channel_conditions.extend(mapper.channels)
663
673
  waiting.sub_flow_conditions.extend(mapper.sub_flows)
674
+ waiting.graceful_completion_conditions.extend(mapper.graceful_completions)
675
+ self._server_protocol.require_graceful_completion_condition_support(waiting)
664
676
  return waiting
665
677
 
666
678
  def _map_sub_flow_options(
@@ -997,6 +1009,7 @@ class _ConditionMapper:
997
1009
  self.timers: list[pb.TimerCondition] = []
998
1010
  self.channels: list[pb.ChannelCondition] = []
999
1011
  self.sub_flows: list[pb.SubFlowCondition] = []
1012
+ self.graceful_completions: list[pb.GracefulCompletionCondition] = []
1000
1013
 
1001
1014
  def add_all(self, conditions: tuple[Condition, ...]) -> None:
1002
1015
  if not conditions:
@@ -1083,6 +1096,14 @@ class _ConditionMapper:
1083
1096
  self._dispatcher._map_sub_flow_options(target, options)
1084
1097
  )
1085
1098
  self.sub_flows.append(mapped_sub_flow)
1099
+ elif isinstance(condition, GracefulCompletionCondition):
1100
+ if self.graceful_completions:
1101
+ raise ValueError(
1102
+ "a Wait accepts at most one graceful completion condition"
1103
+ )
1104
+ self.graceful_completions.append(
1105
+ pb.GracefulCompletionCondition(condition_id=condition_id)
1106
+ )
1086
1107
  else:
1087
1108
  raise TypeError("unsupported Condition")
1088
1109
  self._ids[identity] = condition_id