dex-python-sdk 1.45.3__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.3 → dex_python_sdk-1.45.4}/PKG-INFO +1 -1
  2. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/__init__.py +10 -1
  3. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/_async_worker_dispatcher.py +4 -0
  4. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/_invocation_context.py +22 -0
  5. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/_server_protocol.py +26 -2
  6. dex_python_sdk-1.45.4/dex/_stop_flow_mapping.py +43 -0
  7. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/_worker_dispatcher.py +22 -1
  8. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/async_client.py +14 -12
  9. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/client.py +14 -12
  10. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/condition.py +79 -0
  11. dex_python_sdk-1.45.4/dex/dexpb/dex_pb2.py +471 -0
  12. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/dexpb/dex_pb2.pyi +34 -8
  13. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/flow_options.py +56 -1
  14. dex_python_sdk-1.45.4/dex/graceful_completion_context.py +108 -0
  15. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/runtime_errors.py +50 -0
  16. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/wait.py +7 -3
  17. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/pyproject.toml +1 -1
  18. dex_python_sdk-1.45.3/dex/dexpb/dex_pb2.py +0 -467
  19. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/LEGACY_NOTICES.md +0 -0
  20. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/LICENSE +0 -0
  21. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/README.md +0 -0
  22. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/_async_value_hydrator.py +0 -0
  23. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/_attribute_reads.py +0 -0
  24. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/_credential_transport.py +0 -0
  25. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/_flow_definition_upload.py +0 -0
  26. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/_flow_service_tls.py +0 -0
  27. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/_grpc_errors.py +0 -0
  28. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/_history_point_mapping.py +0 -0
  29. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/_message_size.py +0 -0
  30. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/_native.pyi +0 -0
  31. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/_pull_worker.py +0 -0
  32. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/_task_queue_names.py +0 -0
  33. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/_utils.py +0 -0
  34. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/_value_hydrator.py +0 -0
  35. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/_value_mapper.py +0 -0
  36. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/action.py +0 -0
  37. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/async_worker.py +0 -0
  38. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/attribute.py +0 -0
  39. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/attribute_match.py +0 -0
  40. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/attribute_values.py +0 -0
  41. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/blob_cache.py +0 -0
  42. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/channel.py +0 -0
  43. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/client_options.py +0 -0
  44. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/codec.py +0 -0
  45. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/context.py +0 -0
  46. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/credential.py +0 -0
  47. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/dexpb/__init__.py +0 -0
  48. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/dexpb/dex_pb2_grpc.py +0 -0
  49. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/flow.py +0 -0
  50. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/flow_config.py +0 -0
  51. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/flow_definition.py +0 -0
  52. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/flow_info.py +0 -0
  53. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/flow_result.py +0 -0
  54. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/flow_service_tls_options.py +0 -0
  55. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/flow_state.py +0 -0
  56. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/join.py +0 -0
  57. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/pull_registration.py +0 -0
  58. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/py.typed +0 -0
  59. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/rpc_invoke_options.py +0 -0
  60. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/step.py +0 -0
  61. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/step_execution.py +0 -0
  62. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/stream.py +0 -0
  63. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/subflow.py +0 -0
  64. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/timer.py +0 -0
  65. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/wait_options.py +0 -0
  66. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/worker.py +0 -0
  67. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/dex/worker_options.py +0 -0
  68. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/sdk-rust/Cargo.lock +0 -0
  69. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/sdk-rust/Cargo.toml +0 -0
  70. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/sdk-rust/crates/dex-blob-cache/Cargo.toml +0 -0
  71. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/sdk-rust/crates/dex-blob-cache/LICENSE +0 -0
  72. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/sdk-rust/crates/dex-blob-cache/README.md +0 -0
  73. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/sdk-rust/crates/dex-blob-cache/src/config.rs +0 -0
  74. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/sdk-rust/crates/dex-blob-cache/src/entry.rs +0 -0
  75. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/sdk-rust/crates/dex-blob-cache/src/error.rs +0 -0
  76. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/sdk-rust/crates/dex-blob-cache/src/format.rs +0 -0
  77. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/sdk-rust/crates/dex-blob-cache/src/lib.rs +0 -0
  78. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/sdk-rust/crates/dex-blob-cache/src/policy.rs +0 -0
  79. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/sdk-rust/crates/dex-blob-cache/src/store.rs +0 -0
  80. {dex_python_sdk-1.45.3 → 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.3 → dex_python_sdk-1.45.4}/sdk-rust/crates/dex-blob-cache-python/Cargo.toml +0 -0
  82. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/sdk-rust/crates/dex-blob-cache-python/LICENSE +0 -0
  83. {dex_python_sdk-1.45.3 → dex_python_sdk-1.45.4}/sdk-rust/crates/dex-blob-cache-python/README.md +0 -0
  84. {dex_python_sdk-1.45.3 → 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.3
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,
@@ -116,6 +120,7 @@ from dex.runtime_errors import (
116
120
  FlowErrorType,
117
121
  FlowNotActiveOrNotFoundError,
118
122
  FlowNotFoundError,
123
+ GracefulCompletionConditionUnsupportedError,
119
124
  InvalidStepResultError,
120
125
  LongPollTimeoutError,
121
126
  RequestTimeoutError,
@@ -254,6 +259,7 @@ __all__ = [
254
259
  "CloneForkFlowOptions",
255
260
  "CloneForkFlowResult",
256
261
  "CloneForkFlowUnsupportedError",
262
+ "GracefulCompletionConditionUnsupportedError",
257
263
  "SubFlowResetPolicy",
258
264
  "RetryPolicy",
259
265
  "SearchFlowEntry",
@@ -299,7 +305,10 @@ __all__ = [
299
305
  "force_complete_if_channels_empty",
300
306
  "force_fail",
301
307
  "graceful_complete",
308
+ "graceful_completion_requested",
302
309
  "heartbeat",
310
+ "is_graceful_completion_condition_completed",
311
+ "supports_graceful_completion_condition",
303
312
  "go_to",
304
313
  "go_to_many",
305
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:
@@ -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,14 +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 CloneForkFlowUnsupportedError
18
+ from dex.runtime_errors import (
19
+ CloneForkFlowUnsupportedError,
20
+ GracefulCompletionConditionUnsupportedError,
21
+ )
19
22
 
20
23
  MINIMUM_SUPPORTED_SERVER_PROTOCOL_VERSION = 4
21
- MAXIMUM_SUPPORTED_SERVER_PROTOCOL_VERSION = 6
24
+ MAXIMUM_SUPPORTED_SERVER_PROTOCOL_VERSION = 7
22
25
  HARD_DELETE_ATTRIBUTE_PROTOCOL_VERSION = 3
23
26
  NAMED_TASK_QUEUE_PROTOCOL_VERSION = 5
24
27
  CLONE_FORK_FLOW_PROTOCOL_VERSION = 6
25
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"
26
31
  LAST_SERVER_ZD_RELEASE_BEFORE_MINIMUM_PROTOCOL = "v0.1.16"
27
32
 
28
33
 
@@ -120,6 +125,25 @@ class NegotiatedServerProtocol:
120
125
  CLONE_FORK_FLOW_SERVER_ZD_RELEASE,
121
126
  )
122
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
+
123
147
 
124
148
  def server_info_request_error(
125
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
@@ -47,6 +47,7 @@ from dex._server_protocol import (
47
47
  remaining_negotiation_seconds,
48
48
  sdk_version,
49
49
  )
50
+ from dex._stop_flow_mapping import map_stop_flow_request
50
51
  from dex._utils import require_name
51
52
  from dex._value_mapper import ValueMapper
52
53
  from dex._worker_dispatcher import WorkerDispatcher
@@ -82,7 +83,6 @@ from dex.flow_options import (
82
83
  IdReusePolicy,
83
84
  StartFlowOptions,
84
85
  StopFlowOptions,
85
- StopType,
86
86
  TimeTravelOptions,
87
87
  _AttributeInitialization,
88
88
  _resolve_flow_timeout_policy,
@@ -681,33 +681,35 @@ class AsyncClient:
681
681
  flow_id: str,
682
682
  options: StopFlowOptions = StopFlowOptions(),
683
683
  ) -> None:
684
- """Request cancellation, termination, or failure of an active Flow.
684
+ """Request cancellation, termination, failure, or completion of an active Flow.
685
685
 
686
686
  The await completes after Dex accepts the request, not after terminal status.
687
687
  Await wait_for_flow afterward to observe closure. Cancellation is cooperative;
688
688
  a handler may still be unwinding, and external effects are not undone.
689
+ ``StopType.GRACEFUL_COMPLETE`` and ``StopType.FORCE_COMPLETE`` complete the
690
+ Flow with ``StopFlowOptions.output`` as a result, like the graceful and force
691
+ complete Step decisions; see :class:`StopType`.
689
692
  The synchronous Client examples also apply here with awaited calls.
690
693
 
691
694
  Args:
692
695
  flow_id: The non-empty target Flow ID.
693
- options: Stop mode and optional recorded reason.
696
+ options: Stop mode, optional recorded reason, and optional output.
694
697
 
695
698
  Raises:
699
+ ValueError: If ``options.output`` is set for a stop type that does not
700
+ complete the Flow.
701
+ ValueMappingError: If ``options.output`` cannot be encoded.
696
702
  FlowNotActiveOrNotFoundError: If no active run exists.
697
703
  DexServiceError: If FlowService rejects or cannot perform the request.
698
704
  RuntimeError: If the Server reports a protocol range without protocol 4.
705
+
706
+ .. versionchanged:: 1.45.4
707
+ Accepts ``StopType.GRACEFUL_COMPLETE``, ``StopType.FORCE_COMPLETE``, and
708
+ ``StopFlowOptions.output``.
699
709
  """
700
710
  await self._call(
701
711
  self._service.StopFlow,
702
- pb.StopFlowRequest(
703
- flow_id=require_name(flow_id),
704
- reason=options.reason or "",
705
- stop_type={
706
- StopType.CANCEL: pb.STOP_TYPE_CANCEL,
707
- StopType.TERMINATE: pb.STOP_TYPE_TERMINATE,
708
- StopType.FAIL: pb.STOP_TYPE_FAIL,
709
- }[options.type],
710
- ),
712
+ map_stop_flow_request(flow_id, options, self._values),
711
713
  "stop_flow",
712
714
  flow_id,
713
715
  "active",
@@ -46,6 +46,7 @@ from dex._server_protocol import (
46
46
  remaining_negotiation_seconds,
47
47
  sdk_version,
48
48
  )
49
+ from dex._stop_flow_mapping import map_stop_flow_request
49
50
  from dex._utils import require_name
50
51
  from dex._value_hydrator import ValueHydrator
51
52
  from dex._value_mapper import ValueMapper
@@ -82,7 +83,6 @@ from dex.flow_options import (
82
83
  IdReusePolicy,
83
84
  StartFlowOptions,
84
85
  StopFlowOptions,
85
- StopType,
86
86
  TimeTravelOptions,
87
87
  _AttributeInitialization,
88
88
  _resolve_flow_timeout_policy,
@@ -690,13 +690,16 @@ class Client:
690
690
  flow_id: str,
691
691
  options: StopFlowOptions = StopFlowOptions(),
692
692
  ) -> None:
693
- """Request cancellation, termination, or failure of an active Flow.
693
+ """Request cancellation, termination, failure, or completion of an active Flow.
694
694
 
695
695
  The call returns after Dex accepts the request and does not wait for terminal
696
696
  status.
697
697
  Use wait_for_flow afterward to observe closure. Cancellation is cooperative;
698
698
  Python handlers can still be unwinding after the request returns. External
699
699
  side effects are not undone by any stop mode.
700
+ ``StopType.GRACEFUL_COMPLETE`` and ``StopType.FORCE_COMPLETE`` complete the
701
+ Flow with ``StopFlowOptions.output`` as a result, like the graceful and force
702
+ complete Step decisions; see :class:`StopType`.
700
703
 
701
704
  Examples:
702
705
  >>> from dex import StopFlowOptions, StopType
@@ -705,24 +708,23 @@ class Client:
705
708
 
706
709
  Args:
707
710
  flow_id: The non-empty target Flow ID.
708
- options: Stop mode and optional recorded reason.
711
+ options: Stop mode, optional recorded reason, and optional output.
709
712
 
710
713
  Raises:
714
+ ValueError: If ``options.output`` is set for a stop type that does not
715
+ complete the Flow.
716
+ ValueMappingError: If ``options.output`` cannot be encoded.
711
717
  FlowNotActiveOrNotFoundError: If no active run exists.
712
718
  DexServiceError: If FlowService rejects or cannot perform the request.
713
719
  RuntimeError: If the Server reports a protocol range without protocol 4.
720
+
721
+ .. versionchanged:: 1.45.4
722
+ Accepts ``StopType.GRACEFUL_COMPLETE``, ``StopType.FORCE_COMPLETE``, and
723
+ ``StopFlowOptions.output``.
714
724
  """
715
725
  self._call(
716
726
  self._service.StopFlow,
717
- pb.StopFlowRequest(
718
- flow_id=require_name(flow_id),
719
- reason=options.reason or "",
720
- stop_type={
721
- StopType.CANCEL: pb.STOP_TYPE_CANCEL,
722
- StopType.TERMINATE: pb.STOP_TYPE_TERMINATE,
723
- StopType.FAIL: pb.STOP_TYPE_FAIL,
724
- }[options.type],
725
- ),
727
+ map_stop_flow_request(flow_id, options, self._values),
726
728
  "stop_flow",
727
729
  flow_id,
728
730
  "active",
@@ -87,6 +87,85 @@ class SubFlowCondition(Condition):
87
87
  raise ValueError("SubFlow condition requires a Flow")
88
88
 
89
89
 
90
+ @dataclass(frozen=True)
91
+ class GracefulCompletionCondition(Condition):
92
+ """Describe a wait for a graceful completion request of the Flow.
93
+
94
+ Applications create this value through
95
+ :func:`graceful_completion_requested`.
96
+
97
+ .. versionadded:: 1.45.4
98
+ """
99
+
100
+
101
+ def graceful_completion_requested(*, condition_id: str | None = None) -> Condition:
102
+ """Create a Condition satisfied once the Flow has a graceful completion request.
103
+
104
+ A graceful completion request comes from ``Client.stop_flow`` with
105
+ ``StopType.GRACEFUL_COMPLETE``, or from a Step that returns
106
+ ``graceful_complete``. The request stays in force, so a Wait registered
107
+ after it is satisfied at once. When the request arrives, Dex re-checks only
108
+ the Waits that include this Condition. Other waiting Steps keep waiting and
109
+ keep the Flow running.
110
+
111
+ Use it to let a long-waiting Step end when someone asks the Flow to
112
+ complete. A typical Step waits for the next message or this Condition with
113
+ :meth:`Wait.any_of`. Its ``execute`` first handles a message that the Wait
114
+ consumed. When there is none and
115
+ :func:`dex.is_graceful_completion_condition_completed` returns ``True``,
116
+ it returns ``dead_end``. The Flow then completes once no other Step is active.
117
+
118
+ In :meth:`Wait.any_of`, this Condition comes after Timers, Channels, and
119
+ SubFlows, so a ready message still wins over the request. This Condition
120
+ still reports completed when a message won and a request exists. Check the
121
+ message first, or it is lost. It also works in :meth:`Wait.all_of` and in
122
+ :meth:`Wait.any_combination_of`, where it needs ``condition_id``.
123
+
124
+ A Wait may hold at most one graceful completion condition. A second one
125
+ fails the Step's ``wait_for`` with ``InvalidStepResultError``.
126
+
127
+ It requires Dex Server protocol version 7 or later, which server-zd 0.1.34
128
+ and later releases provide. With an older Server, the Step's ``wait_for``
129
+ fails with ``GracefulCompletionConditionUnsupportedError`` and the Step
130
+ retries according to its retry policy.
131
+
132
+ Args:
133
+ condition_id: Optional stable identifier unique within the Wait tree.
134
+ Required inside :meth:`Wait.any_combination_of`.
135
+
136
+ Returns:
137
+ A durable graceful completion Condition accepted by :class:`Wait`.
138
+
139
+ Raises:
140
+ ValueError: If ``condition_id`` is invalid.
141
+
142
+ Examples:
143
+ >>> from dex import (
144
+ ... Channel, Context, Step, StepDecision, Wait, dead_end,
145
+ ... go_to, graceful_completion_requested,
146
+ ... is_graceful_completion_condition_completed,
147
+ ... )
148
+ >>> USER_MESSAGES = Channel("user-messages", str)
149
+ >>> class WaitForMessage(Step[None]):
150
+ ... def wait_for(self, context: Context, input: None) -> Wait:
151
+ ... return Wait.any_of(
152
+ ... USER_MESSAGES.for_one(),
153
+ ... graceful_completion_requested(),
154
+ ... )
155
+ ...
156
+ ... def execute(self, context: Context, input: None) -> StepDecision:
157
+ ... messages = USER_MESSAGES.results(context)
158
+ ... if messages:
159
+ ... return go_to(HandleMessage, messages[0])
160
+ ... if is_graceful_completion_condition_completed(context):
161
+ ... return dead_end()
162
+ ... return go_to(WaitForMessage, None)
163
+
164
+ .. versionadded:: 1.45.4
165
+ """
166
+ return GracefulCompletionCondition(condition_id=condition_id)
167
+
168
+
90
169
  @dataclass(frozen=True)
91
170
  class ConditionCombination:
92
171
  """Group Conditions that must become ready together.