dex-python-sdk 1.45.1__tar.gz → 1.45.3__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 (82) hide show
  1. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/PKG-INFO +1 -1
  2. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/__init__.py +26 -0
  3. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/_grpc_errors.py +10 -0
  4. dex_python_sdk-1.45.3/dex/_history_point_mapping.py +156 -0
  5. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/_server_protocol.py +13 -1
  6. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/async_client.py +218 -36
  7. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/client.py +229 -36
  8. dex_python_sdk-1.45.3/dex/dexpb/dex_pb2.py +467 -0
  9. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/dexpb/dex_pb2.pyi +112 -4
  10. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/dexpb/dex_pb2_grpc.py +43 -0
  11. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/flow_options.py +338 -0
  12. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/flow_result.py +8 -2
  13. dex_python_sdk-1.45.3/dex/flow_state.py +322 -0
  14. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/runtime_errors.py +65 -0
  15. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/pyproject.toml +1 -1
  16. dex_python_sdk-1.45.1/dex/dexpb/dex_pb2.py +0 -457
  17. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/LEGACY_NOTICES.md +0 -0
  18. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/LICENSE +0 -0
  19. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/README.md +0 -0
  20. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/_async_value_hydrator.py +0 -0
  21. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/_async_worker_dispatcher.py +0 -0
  22. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/_attribute_reads.py +0 -0
  23. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/_credential_transport.py +0 -0
  24. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/_flow_definition_upload.py +0 -0
  25. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/_flow_service_tls.py +0 -0
  26. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/_invocation_context.py +0 -0
  27. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/_message_size.py +0 -0
  28. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/_native.pyi +0 -0
  29. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/_pull_worker.py +0 -0
  30. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/_task_queue_names.py +0 -0
  31. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/_utils.py +0 -0
  32. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/_value_hydrator.py +0 -0
  33. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/_value_mapper.py +0 -0
  34. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/_worker_dispatcher.py +0 -0
  35. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/action.py +0 -0
  36. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/async_worker.py +0 -0
  37. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/attribute.py +0 -0
  38. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/attribute_match.py +0 -0
  39. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/attribute_values.py +0 -0
  40. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/blob_cache.py +0 -0
  41. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/channel.py +0 -0
  42. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/client_options.py +0 -0
  43. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/codec.py +0 -0
  44. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/condition.py +0 -0
  45. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/context.py +0 -0
  46. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/credential.py +0 -0
  47. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/dexpb/__init__.py +0 -0
  48. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/flow.py +0 -0
  49. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/flow_config.py +0 -0
  50. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/flow_definition.py +0 -0
  51. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/flow_info.py +0 -0
  52. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/flow_service_tls_options.py +0 -0
  53. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/join.py +0 -0
  54. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/pull_registration.py +0 -0
  55. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/py.typed +0 -0
  56. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/rpc_invoke_options.py +0 -0
  57. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/step.py +0 -0
  58. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/step_execution.py +0 -0
  59. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/stream.py +0 -0
  60. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/subflow.py +0 -0
  61. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/timer.py +0 -0
  62. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/wait.py +0 -0
  63. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/wait_options.py +0 -0
  64. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/worker.py +0 -0
  65. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/dex/worker_options.py +0 -0
  66. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/sdk-rust/Cargo.lock +0 -0
  67. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/sdk-rust/Cargo.toml +0 -0
  68. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/sdk-rust/crates/dex-blob-cache/Cargo.toml +0 -0
  69. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/sdk-rust/crates/dex-blob-cache/LICENSE +0 -0
  70. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/sdk-rust/crates/dex-blob-cache/README.md +0 -0
  71. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/sdk-rust/crates/dex-blob-cache/src/config.rs +0 -0
  72. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/sdk-rust/crates/dex-blob-cache/src/entry.rs +0 -0
  73. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/sdk-rust/crates/dex-blob-cache/src/error.rs +0 -0
  74. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/sdk-rust/crates/dex-blob-cache/src/format.rs +0 -0
  75. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/sdk-rust/crates/dex-blob-cache/src/lib.rs +0 -0
  76. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/sdk-rust/crates/dex-blob-cache/src/policy.rs +0 -0
  77. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/sdk-rust/crates/dex-blob-cache/src/store.rs +0 -0
  78. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/sdk-rust/crates/dex-blob-cache/tests/blob_cache_integration.rs +0 -0
  79. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/sdk-rust/crates/dex-blob-cache-python/Cargo.toml +0 -0
  80. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/sdk-rust/crates/dex-blob-cache-python/LICENSE +0 -0
  81. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/sdk-rust/crates/dex-blob-cache-python/README.md +0 -0
  82. {dex_python_sdk-1.45.1 → dex_python_sdk-1.45.3}/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.1
3
+ Version: 1.45.3
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
@@ -67,7 +67,19 @@ from dex.flow_info import (
67
67
  SearchFlowEntry,
68
68
  SearchFlowsPage,
69
69
  )
70
+ from dex.flow_state import (
71
+ ActiveStepExecution,
72
+ ActiveStepExecutionPhase,
73
+ FlowState,
74
+ StepMethodFailureInfo,
75
+ StepMethodInvocation,
76
+ StepMethodInvocationPhase,
77
+ StepMethodName,
78
+ StepMethodPendingReason,
79
+ )
70
80
  from dex.flow_options import (
81
+ CloneForkFlowOptions,
82
+ CloneForkFlowResult,
71
83
  FlowTimeoutHandlerOptions,
72
84
  FlowTimeoutPolicy,
73
85
  IdReusePolicy,
@@ -75,6 +87,7 @@ from dex.flow_options import (
75
87
  StopFlowOptions,
76
88
  StopType,
77
89
  SubFlowOptions,
90
+ SubFlowResetPolicy,
78
91
  SubFlowReusePolicy,
79
92
  TimeTravelOptions,
80
93
  TimeTravelStepMethod,
@@ -94,6 +107,7 @@ from dex.runtime_errors import (
94
107
  ChannelMessageNotFoundError,
95
108
  ChannelMessagesNotLoadedError,
96
109
  BlobMessageTooLargeError,
110
+ CloneForkFlowUnsupportedError,
97
111
  DexServiceError,
98
112
  ErrorSubStatus,
99
113
  FlowAlreadyStartedError,
@@ -207,6 +221,14 @@ __all__ = [
207
221
  "FlowNotActiveOrNotFoundError",
208
222
  "FlowNotFoundError",
209
223
  "FlowStatus",
224
+ "ActiveStepExecution",
225
+ "ActiveStepExecutionPhase",
226
+ "FlowState",
227
+ "StepMethodFailureInfo",
228
+ "StepMethodInvocation",
229
+ "StepMethodInvocationPhase",
230
+ "StepMethodName",
231
+ "StepMethodPendingReason",
210
232
  "FlowTimeoutHandlerOptions",
211
233
  "FlowTimeoutPolicy",
212
234
  "HealthInfo",
@@ -229,6 +251,10 @@ __all__ = [
229
251
  "TimeTravelOptions",
230
252
  "TimeTravelStepMethod",
231
253
  "TimeTravelType",
254
+ "CloneForkFlowOptions",
255
+ "CloneForkFlowResult",
256
+ "CloneForkFlowUnsupportedError",
257
+ "SubFlowResetPolicy",
232
258
  "RetryPolicy",
233
259
  "SearchFlowEntry",
234
260
  "SearchFlowsPage",
@@ -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()
@@ -15,11 +15,14 @@ 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
19
 
19
20
  MINIMUM_SUPPORTED_SERVER_PROTOCOL_VERSION = 4
20
- MAXIMUM_SUPPORTED_SERVER_PROTOCOL_VERSION = 5
21
+ MAXIMUM_SUPPORTED_SERVER_PROTOCOL_VERSION = 6
21
22
  HARD_DELETE_ATTRIBUTE_PROTOCOL_VERSION = 3
22
23
  NAMED_TASK_QUEUE_PROTOCOL_VERSION = 5
24
+ CLONE_FORK_FLOW_PROTOCOL_VERSION = 6
25
+ CLONE_FORK_FLOW_SERVER_ZD_RELEASE = "server-zd 0.1.33"
23
26
  LAST_SERVER_ZD_RELEASE_BEFORE_MINIMUM_PROTOCOL = "v0.1.16"
24
27
 
25
28
 
@@ -108,6 +111,15 @@ class NegotiatedServerProtocol:
108
111
  "the default task queue"
109
112
  )
110
113
 
114
+ def require_clone_fork_flow_support(self) -> None:
115
+ if self._version >= CLONE_FORK_FLOW_PROTOCOL_VERSION:
116
+ return
117
+ raise CloneForkFlowUnsupportedError(
118
+ self._version,
119
+ CLONE_FORK_FLOW_PROTOCOL_VERSION,
120
+ CLONE_FORK_FLOW_SERVER_ZD_RELEASE,
121
+ )
122
+
111
123
 
112
124
  def server_info_request_error(
113
125
  artifact_version: str, failure: grpc.RpcError
@@ -30,7 +30,16 @@ from dex._flow_definition_upload import (
30
30
  upload_requests,
31
31
  upload_results_from_response,
32
32
  )
33
- from dex._grpc_errors import FlowTargetRequirement, translate_rpc_error
33
+ from dex._grpc_errors import (
34
+ FlowTargetRequirement,
35
+ translate_clone_fork_flow_error,
36
+ translate_rpc_error,
37
+ )
38
+ from dex._history_point_mapping import (
39
+ clone_fork_flow_result_from_proto,
40
+ map_clone_fork_flow_request,
41
+ map_time_travel_request,
42
+ )
34
43
  from dex._server_protocol import (
35
44
  NegotiatedServerProtocol,
36
45
  ServerProtocolNegotiationTimeoutError,
@@ -65,15 +74,17 @@ from dex.flow_definition import (
65
74
  )
66
75
  from dex.flow_config import ActiveStepSearchMode, FlowConfig
67
76
  from dex.flow_info import FlowInfo, FlowStatus, SearchFlowEntry, SearchFlowsPage
77
+ from dex.flow_state import FlowState, flow_state_from_proto
68
78
  from dex.flow_options import (
79
+ CloneForkFlowOptions,
80
+ CloneForkFlowResult,
69
81
  FlowTimeoutPolicy,
70
82
  IdReusePolicy,
71
83
  StartFlowOptions,
72
84
  StopFlowOptions,
73
85
  StopType,
74
86
  TimeTravelOptions,
75
- TimeTravelStepMethod,
76
- TimeTravelType,
87
+ _AttributeInitialization,
77
88
  _resolve_flow_timeout_policy,
78
89
  )
79
90
  from dex.flow_result import FlowResult, flow_result_from_proto
@@ -734,6 +745,73 @@ class AsyncClient:
734
745
  response.start_time.ToDatetime(tzinfo=timezone.utc),
735
746
  )
736
747
 
748
+ async def get_flow_state(self, flow_id: str) -> FlowState:
749
+ """Read the open Step executions, their latest failures, and the task queue.
750
+
751
+ .. versionadded:: 1.45.2
752
+
753
+ Use ``get_flow_state`` when a Flow is still running and you need to know
754
+ why. It tells a healthy Flow apart from a Flow whose active Step keeps
755
+ failing and retrying. Each ``ActiveStepExecution`` reports its Step type,
756
+ execution number, and phase. While a WaitFor or Execute call is open,
757
+ ``invocation`` reports its attempt and whether it is pending, running, or
758
+ in retry backoff. ``last_failure`` reports the latest failed attempt of
759
+ that call: its attempt number, error type, message, and stack trace. A
760
+ Step that has not failed has no ``last_failure``.
761
+
762
+ The result also reports the Flow's task queue in ``task_queue``. ``""``
763
+ means the default task queue.
764
+
765
+ The call reads committed server state once and does not wait. No Worker
766
+ runs. Poll it, for example in a test harness, to wait for a Step to start
767
+ failing. Use ``wait_for_flow`` or ``wait_for_step_completion`` to wait for
768
+ completion instead. A closed run stays readable until Dex purges it and
769
+ reports no open Step executions.
770
+
771
+ Example:
772
+ .. code-block:: python
773
+
774
+ state = await client.get_flow_state("order-42")
775
+ print(f"task queue: {state.task_queue or 'default'}")
776
+ for step in state.active_step_executions:
777
+ failure = step.last_failure
778
+ if failure is None:
779
+ phase = step.invocation.phase if step.invocation else step.phase
780
+ print(f"{step.step_execution_id} is {phase.value}")
781
+ continue
782
+ next_attempt = step.invocation.attempt if step.invocation else None
783
+ print(
784
+ f"{step.step_execution_id} attempt {failure.attempt} failed "
785
+ f"with {failure.error_type}: {failure.detail}; "
786
+ f"next attempt {next_attempt}"
787
+ )
788
+
789
+ Args:
790
+ flow_id: The non-empty ID of an existing Flow.
791
+
792
+ Returns:
793
+ The open Step executions and the task queue of the current run, or of
794
+ the latest run when no run is open.
795
+
796
+ Raises:
797
+ ValueError: If ``flow_id`` is empty.
798
+ FlowNotFoundError: If ``flow_id`` does not exist.
799
+ DexServiceError: For other service or transport failures.
800
+ RuntimeError: If the Server reports a protocol range without protocol
801
+ 4, or returns a malformed Step execution ID.
802
+ """
803
+ response = cast(
804
+ pb.GetFlowStateResponse,
805
+ await self._call(
806
+ self._service.GetFlowState,
807
+ pb.GetFlowStateRequest(flow_id=require_name(flow_id)),
808
+ "get_flow_state",
809
+ flow_id,
810
+ "existing",
811
+ ),
812
+ )
813
+ return flow_state_from_proto(flow_id, response)
814
+
737
815
  async def get_attributes(
738
816
  self,
739
817
  flow_id: str,
@@ -917,29 +995,12 @@ class AsyncClient:
917
995
  ValueError: If time travel selector fields are invalid.
918
996
  DexServiceError: If FlowService cannot perform the time travel.
919
997
  RuntimeError: If the Server reports a protocol range without protocol 4.
998
+
999
+ .. versionchanged:: 1.45.3
1000
+ Accepts ``TimeTravelType.EVENT_ID`` with ``options.event_id`` and
1001
+ sends ``options.sub_flow_reset_policy``.
920
1002
  """
921
- request = pb.ResetFlowRequest(
922
- flow_id=require_name(flow_id),
923
- reset_type={
924
- TimeTravelType.BEGINNING: pb.FLOW_RESET_TYPE_BEGINNING,
925
- TimeTravelType.HISTORY_EVENT_TIME: pb.FLOW_RESET_TYPE_HISTORY_EVENT_TIME,
926
- TimeTravelType.STEP_TYPE: pb.FLOW_RESET_TYPE_STEP_TYPE,
927
- TimeTravelType.STEP_EXECUTION_ID: pb.FLOW_RESET_TYPE_STEP_EXECUTION_ID,
928
- }[options.type],
929
- reason=options.reason or "",
930
- skip_writes_reapply=options.skip_writes_reapply,
931
- )
932
- if options.history_event_time is not None:
933
- request.history_event_time = options.history_event_time.isoformat()
934
- if options.step_type is not None:
935
- request.step_type = options.step_type
936
- if options.step_execution_id is not None:
937
- request.step_execution_id = options.step_execution_id
938
- if options.step_method is not None:
939
- request.step_method = {
940
- TimeTravelStepMethod.WAIT_FOR: pb.FLOW_RESET_STEP_METHOD_WAIT_FOR,
941
- TimeTravelStepMethod.EXECUTE: pb.FLOW_RESET_STEP_METHOD_EXECUTE,
942
- }[options.step_method]
1003
+ request = map_time_travel_request(require_name(flow_id), options)
943
1004
  response = cast(
944
1005
  pb.ResetFlowResponse,
945
1006
  await self._call(
@@ -952,6 +1013,98 @@ class AsyncClient:
952
1013
  )
953
1014
  return response.run_id
954
1015
 
1016
+ async def clone_fork_flow(
1017
+ self,
1018
+ flow: Flow[Any],
1019
+ source_flow_id: str,
1020
+ flow_id: str,
1021
+ options: CloneForkFlowOptions = CloneForkFlowOptions(),
1022
+ ) -> CloneForkFlowResult:
1023
+ """Create a new Flow whose first run starts from a copy of another run.
1024
+
1025
+ This is the asynchronous form of :meth:`dex.Client.clone_fork_flow`; it
1026
+ takes the same arguments, returns the same result, and raises the same
1027
+ errors.
1028
+
1029
+ The source run is the run of ``source_flow_id`` that
1030
+ ``options.source_run_id`` selects; the empty default selects the latest
1031
+ run. ``options`` selects the copied point, as for ``time_travel``; the
1032
+ default copies the latest committed state. The new Flow gets the Flow
1033
+ ID ``flow_id``, a new run ID, and run attempt 1, and continues on its
1034
+ own from the copied state. The source run keeps running and never
1035
+ changes.
1036
+
1037
+ Args:
1038
+ flow: The registered Flow instance of the source run's Flow type.
1039
+ The new Flow keeps that type. The Client uses it to encode the
1040
+ Attribute writes of ``options``.
1041
+ source_flow_id: The non-empty Flow ID of the source run.
1042
+ flow_id: The non-empty Flow ID of the new Flow. It must differ from
1043
+ ``source_flow_id``.
1044
+ options: The copied point and the new Flow's start settings.
1045
+
1046
+ Returns:
1047
+ The new run ID and the source run, run attempt, and last history
1048
+ event ID that the copied point includes.
1049
+
1050
+ Raises:
1051
+ CloneForkFlowUnsupportedError: If the Server negotiated a protocol
1052
+ older than version 6; server-zd 0.1.33 and later support it.
1053
+ The request is not sent.
1054
+ FlowAlreadyStartedError: If the ID reuse policy rejects a run of
1055
+ ``flow_id``.
1056
+ FlowNotFoundError: If the source run does not exist. Its
1057
+ ``flow_id`` is ``source_flow_id``.
1058
+ FlowDefinitionError: If ``flow`` is not registered.
1059
+ ValueError: If a Flow ID is empty or both Flow IDs are equal.
1060
+ ValueMappingError: If an Attribute write cannot be encoded.
1061
+ DexServiceError: If FlowService rejects the call, for example with
1062
+ ``FAILED_PRECONDITION`` when the point is outside the source
1063
+ run's history window or its state is not running.
1064
+
1065
+ Examples:
1066
+ >>> result = await client.clone_fork_flow(
1067
+ ... session_flow,
1068
+ ... "session-1",
1069
+ ... "session-1-branch",
1070
+ ... CloneForkFlowOptions(type=TimeTravelType.EVENT_ID, event_id=42),
1071
+ ... )
1072
+ >>> print(result.run_id, result.source_event_id)
1073
+
1074
+ .. versionadded:: 1.45.3
1075
+ """
1076
+ registered = self.registry._flow_for_instance(flow)
1077
+ require_name(source_flow_id)
1078
+ require_name(flow_id)
1079
+ if source_flow_id == flow_id:
1080
+ raise ValueError(
1081
+ "clone_fork_flow flow_id must differ from source_flow_id; "
1082
+ "use time_travel to return a Flow to an earlier point"
1083
+ )
1084
+ request = map_clone_fork_flow_request(
1085
+ source_flow_id,
1086
+ flow_id,
1087
+ options,
1088
+ self._map_clone_fork_flow_config_override(options),
1089
+ self._map_attribute_initializations(
1090
+ registered, options._attribute_initializations
1091
+ ),
1092
+ 0 if options.timeout is None else self._seconds32(options.timeout),
1093
+ )
1094
+ await self._negotiate_server_protocol_for_operation(
1095
+ "clone_fork_flow", flow_id, "none"
1096
+ )
1097
+ self._server_protocol.require_clone_fork_flow_support()
1098
+ try:
1099
+ response = cast(
1100
+ pb.CloneForkFlowResponse, await self._service.CloneForkFlow(request)
1101
+ )
1102
+ except grpc.RpcError as error:
1103
+ raise translate_clone_fork_flow_error(
1104
+ error, source_flow_id, flow_id
1105
+ ) from error
1106
+ return clone_fork_flow_result_from_proto(response)
1107
+
955
1108
  async def skip_timer(
956
1109
  self,
957
1110
  flow_id: str,
@@ -1488,7 +1641,29 @@ class AsyncClient:
1488
1641
  mapped.flow_start_delay_seconds = self._seconds32(options.start_delay)
1489
1642
  if options.retry_policy is not None:
1490
1643
  mapped.retry_policy.CopyFrom(self._map_flow_retry(options.retry_policy))
1491
- for initialization in options._attribute_initializations:
1644
+ mapped.attributes.extend(
1645
+ self._map_attribute_initializations(
1646
+ registered, options._attribute_initializations
1647
+ )
1648
+ )
1649
+ mapped.attributes.extend(
1650
+ registered.initial_work_queue_permissions_writes(mapped.attributes)
1651
+ )
1652
+ mapped.flow_config_override.CopyFrom(
1653
+ self._map_flow_config(options.config_override)
1654
+ )
1655
+ mapped.flow_config_override.worker_target.CopyFrom(
1656
+ pb.WorkerTarget(is_pull_mode=True, task_queue=options.task_queue)
1657
+ )
1658
+ return mapped
1659
+
1660
+ def _map_attribute_initializations(
1661
+ self,
1662
+ registered: _RegisteredFlow,
1663
+ initializations: tuple[_AttributeInitialization, ...],
1664
+ ) -> list[pb.AttributeWrite]:
1665
+ writes: list[pb.AttributeWrite] = []
1666
+ for initialization in initializations:
1492
1667
  definition = initialization.definition
1493
1668
  _require_matching_hard_delete_on_null(
1494
1669
  registered.name, registered.persistence.get(definition.name), definition
@@ -1503,16 +1678,20 @@ class AsyncClient:
1503
1678
  )
1504
1679
  _apply_attribute_store_sync(write, definition)
1505
1680
  _apply_hard_delete_on_null(write, definition)
1506
- mapped.attributes.append(write)
1507
- mapped.attributes.extend(
1508
- registered.initial_work_queue_permissions_writes(mapped.attributes)
1509
- )
1510
- mapped.flow_config_override.CopyFrom(
1511
- self._map_flow_config(options.config_override)
1512
- )
1513
- mapped.flow_config_override.worker_target.CopyFrom(
1514
- pb.WorkerTarget(is_pull_mode=True, task_queue=options.task_queue)
1515
- )
1681
+ writes.append(write)
1682
+ return writes
1683
+
1684
+ def _map_clone_fork_flow_config_override(
1685
+ self, options: CloneForkFlowOptions
1686
+ ) -> pb.FlowConfig | None:
1687
+ # No override keeps every FlowConfig value of the source run.
1688
+ if options.config_override is None and not options.task_queue:
1689
+ return None
1690
+ mapped = self._map_flow_config(options.config_override)
1691
+ if options.task_queue:
1692
+ mapped.worker_target.CopyFrom(
1693
+ pb.WorkerTarget(is_pull_mode=True, task_queue=options.task_queue)
1694
+ )
1516
1695
  return mapped
1517
1696
 
1518
1697
  def _map_flow_config(self, config: FlowConfig | None) -> pb.FlowConfig:
@@ -1675,6 +1854,9 @@ class AsyncClient:
1675
1854
  ),
1676
1855
  int(pb.FLOW_ERROR_TYPE_INTERNAL): FlowErrorType.INTERNAL,
1677
1856
  int(pb.FLOW_ERROR_TYPE_FLOW_TIMEOUT): FlowErrorType.FLOW_TIMEOUT,
1857
+ int(pb.FLOW_ERROR_TYPE_SUB_FLOW_ABANDONED): (
1858
+ FlowErrorType.SUB_FLOW_ABANDONED
1859
+ ),
1678
1860
  }
1679
1861
  return error_types.get(error_type)
1680
1862