@temporalio/core-bridge 1.9.2 → 1.10.0

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 (177) hide show
  1. package/Cargo.lock +754 -473
  2. package/Cargo.toml +3 -3
  3. package/lib/index.d.ts +33 -2
  4. package/lib/index.js.map +1 -1
  5. package/package.json +4 -4
  6. package/releases/aarch64-apple-darwin/index.node +0 -0
  7. package/releases/aarch64-unknown-linux-gnu/index.node +0 -0
  8. package/releases/x86_64-apple-darwin/index.node +0 -0
  9. package/releases/x86_64-pc-windows-msvc/index.node +0 -0
  10. package/releases/x86_64-unknown-linux-gnu/index.node +0 -0
  11. package/scripts/build.js +4 -3
  12. package/sdk-core/.cargo/config.toml +2 -4
  13. package/sdk-core/.github/workflows/heavy.yml +1 -1
  14. package/sdk-core/.github/workflows/per-pr.yml +6 -4
  15. package/sdk-core/Cargo.toml +10 -3
  16. package/sdk-core/README.md +4 -6
  17. package/sdk-core/client/Cargo.toml +13 -5
  18. package/sdk-core/client/src/lib.rs +123 -34
  19. package/sdk-core/client/src/metrics.rs +70 -18
  20. package/sdk-core/client/src/proxy.rs +85 -0
  21. package/sdk-core/client/src/raw.rs +67 -5
  22. package/sdk-core/client/src/worker_registry/mod.rs +5 -3
  23. package/sdk-core/client/src/workflow_handle/mod.rs +3 -1
  24. package/sdk-core/core/Cargo.toml +31 -37
  25. package/sdk-core/core/src/abstractions/take_cell.rs +3 -3
  26. package/sdk-core/core/src/abstractions.rs +176 -108
  27. package/sdk-core/core/src/core_tests/activity_tasks.rs +4 -13
  28. package/sdk-core/core/src/core_tests/determinism.rs +2 -1
  29. package/sdk-core/core/src/core_tests/local_activities.rs +3 -3
  30. package/sdk-core/core/src/core_tests/mod.rs +3 -3
  31. package/sdk-core/core/src/core_tests/queries.rs +42 -5
  32. package/sdk-core/core/src/core_tests/workers.rs +2 -3
  33. package/sdk-core/core/src/core_tests/workflow_tasks.rs +115 -15
  34. package/sdk-core/core/src/ephemeral_server/mod.rs +109 -136
  35. package/sdk-core/core/src/internal_flags.rs +8 -8
  36. package/sdk-core/core/src/lib.rs +16 -11
  37. package/sdk-core/core/src/pollers/mod.rs +11 -5
  38. package/sdk-core/core/src/pollers/poll_buffer.rs +48 -29
  39. package/sdk-core/core/src/protosext/mod.rs +32 -32
  40. package/sdk-core/core/src/protosext/protocol_messages.rs +14 -24
  41. package/sdk-core/core/src/retry_logic.rs +2 -2
  42. package/sdk-core/core/src/telemetry/log_export.rs +10 -9
  43. package/sdk-core/core/src/telemetry/metrics.rs +233 -330
  44. package/sdk-core/core/src/telemetry/mod.rs +11 -38
  45. package/sdk-core/core/src/telemetry/otel.rs +355 -0
  46. package/sdk-core/core/src/telemetry/prometheus_server.rs +36 -23
  47. package/sdk-core/core/src/test_help/mod.rs +80 -59
  48. package/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +6 -6
  49. package/sdk-core/core/src/worker/activities/local_activities.rs +46 -43
  50. package/sdk-core/core/src/worker/activities.rs +45 -46
  51. package/sdk-core/core/src/worker/client/mocks.rs +8 -7
  52. package/sdk-core/core/src/worker/client.rs +40 -39
  53. package/sdk-core/core/src/worker/mod.rs +72 -42
  54. package/sdk-core/core/src/worker/slot_provider.rs +28 -28
  55. package/sdk-core/core/src/worker/slot_supplier.rs +1 -0
  56. package/sdk-core/core/src/worker/tuner/fixed_size.rs +52 -0
  57. package/sdk-core/core/src/worker/tuner/resource_based.rs +561 -0
  58. package/sdk-core/core/src/worker/tuner.rs +122 -0
  59. package/sdk-core/core/src/worker/workflow/driven_workflow.rs +6 -6
  60. package/sdk-core/core/src/worker/workflow/history_update.rs +27 -53
  61. package/sdk-core/core/src/worker/workflow/machines/activity_state_machine.rs +4 -17
  62. package/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +1 -10
  63. package/sdk-core/core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +4 -11
  64. package/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +17 -35
  65. package/sdk-core/core/src/worker/workflow/machines/complete_workflow_state_machine.rs +0 -8
  66. package/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +1 -5
  67. package/sdk-core/core/src/worker/workflow/machines/fail_workflow_state_machine.rs +0 -5
  68. package/sdk-core/core/src/worker/workflow/machines/local_activity_state_machine.rs +0 -5
  69. package/sdk-core/core/src/worker/workflow/machines/mod.rs +0 -14
  70. package/sdk-core/core/src/worker/workflow/machines/modify_workflow_properties_state_machine.rs +0 -5
  71. package/sdk-core/core/src/worker/workflow/machines/patch_state_machine.rs +0 -5
  72. package/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +1 -10
  73. package/sdk-core/core/src/worker/workflow/machines/timer_state_machine.rs +3 -10
  74. package/sdk-core/core/src/worker/workflow/machines/transition_coverage.rs +12 -8
  75. package/sdk-core/core/src/worker/workflow/machines/update_state_machine.rs +0 -10
  76. package/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +6 -13
  77. package/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +27 -37
  78. package/sdk-core/core/src/worker/workflow/machines/workflow_task_state_machine.rs +3 -14
  79. package/sdk-core/core/src/worker/workflow/managed_run.rs +84 -54
  80. package/sdk-core/core/src/worker/workflow/mod.rs +63 -160
  81. package/sdk-core/core/src/worker/workflow/run_cache.rs +22 -13
  82. package/sdk-core/core/src/worker/workflow/wft_extraction.rs +16 -3
  83. package/sdk-core/core/src/worker/workflow/wft_poller.rs +15 -12
  84. package/sdk-core/core/src/worker/workflow/workflow_stream.rs +39 -78
  85. package/sdk-core/core-api/Cargo.toml +6 -5
  86. package/sdk-core/core-api/src/errors.rs +8 -0
  87. package/sdk-core/core-api/src/telemetry/metrics.rs +75 -4
  88. package/sdk-core/core-api/src/telemetry.rs +7 -1
  89. package/sdk-core/core-api/src/worker.rs +212 -56
  90. package/sdk-core/fsm/Cargo.toml +3 -0
  91. package/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/no_handle_conversions_require_into_fail.stderr +1 -1
  92. package/sdk-core/sdk/Cargo.toml +5 -7
  93. package/sdk-core/sdk/src/app_data.rs +3 -3
  94. package/sdk-core/sdk/src/lib.rs +5 -3
  95. package/sdk-core/sdk/src/workflow_context/options.rs +1 -1
  96. package/sdk-core/sdk/src/workflow_context.rs +10 -9
  97. package/sdk-core/sdk/src/workflow_future.rs +1 -1
  98. package/sdk-core/sdk-core-protos/Cargo.toml +8 -6
  99. package/sdk-core/sdk-core-protos/build.rs +1 -10
  100. package/sdk-core/sdk-core-protos/protos/api_upstream/.github/PULL_REQUEST_TEMPLATE.md +3 -0
  101. package/sdk-core/sdk-core-protos/protos/api_upstream/.github/workflows/ci.yml +26 -0
  102. package/sdk-core/sdk-core-protos/protos/api_upstream/Makefile +42 -20
  103. package/sdk-core/sdk-core-protos/protos/api_upstream/README.md +2 -0
  104. package/sdk-core/sdk-core-protos/protos/api_upstream/api-linter.yaml +36 -26
  105. package/sdk-core/sdk-core-protos/protos/api_upstream/buf.lock +2 -0
  106. package/sdk-core/sdk-core-protos/protos/api_upstream/google/protobuf/struct.proto +95 -0
  107. package/sdk-core/sdk-core-protos/protos/api_upstream/openapi/openapiv2.json +9632 -0
  108. package/sdk-core/sdk-core-protos/protos/api_upstream/openapi/openapiv3.yaml +7337 -0
  109. package/sdk-core/sdk-core-protos/protos/api_upstream/openapi/payload_description.txt +2 -0
  110. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/command/v1/message.proto +45 -11
  111. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/common/v1/message.proto +22 -4
  112. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/command_type.proto +2 -0
  113. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/common.proto +44 -0
  114. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/event_type.proto +18 -3
  115. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +20 -0
  116. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/task_queue.proto +30 -0
  117. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/update.proto +7 -8
  118. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/workflow.proto +23 -5
  119. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/errordetails/v1/message.proto +20 -0
  120. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/failure/v1/message.proto +25 -0
  121. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/history/v1/message.proto +141 -15
  122. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/namespace/v1/message.proto +12 -0
  123. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/nexus/v1/message.proto +193 -0
  124. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +73 -6
  125. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/operatorservice/v1/service.proto +46 -4
  126. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/schedule/v1/message.proto +4 -0
  127. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/sdk/v1/workflow_metadata.proto +2 -2
  128. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +116 -0
  129. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflow/v1/message.proto +134 -0
  130. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +274 -29
  131. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +57 -1
  132. package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +10 -12
  133. package/sdk-core/sdk-core-protos/src/history_builder.rs +1 -1
  134. package/sdk-core/sdk-core-protos/src/lib.rs +54 -51
  135. package/sdk-core/sdk-core-protos/src/task_token.rs +11 -2
  136. package/sdk-core/test-utils/Cargo.toml +7 -4
  137. package/sdk-core/test-utils/src/histfetch.rs +1 -1
  138. package/sdk-core/test-utils/src/lib.rs +44 -62
  139. package/sdk-core/tests/fuzzy_workflow.rs +5 -2
  140. package/sdk-core/tests/heavy_tests.rs +114 -17
  141. package/sdk-core/tests/integ_tests/activity_functions.rs +1 -1
  142. package/sdk-core/tests/integ_tests/client_tests.rs +2 -2
  143. package/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +38 -26
  144. package/sdk-core/tests/integ_tests/metrics_tests.rs +126 -17
  145. package/sdk-core/tests/integ_tests/polling_tests.rs +118 -2
  146. package/sdk-core/tests/integ_tests/update_tests.rs +3 -5
  147. package/sdk-core/tests/integ_tests/visibility_tests.rs +3 -3
  148. package/sdk-core/tests/integ_tests/workflow_tests/activities.rs +1 -1
  149. package/sdk-core/tests/integ_tests/workflow_tests/appdata_propagation.rs +1 -1
  150. package/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +1 -1
  151. package/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +1 -1
  152. package/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +3 -3
  153. package/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +5 -4
  154. package/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +3 -2
  155. package/sdk-core/tests/integ_tests/workflow_tests/eager.rs +6 -10
  156. package/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +9 -7
  157. package/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +1 -1
  158. package/sdk-core/tests/integ_tests/workflow_tests/patches.rs +14 -9
  159. package/sdk-core/tests/integ_tests/workflow_tests/resets.rs +1 -1
  160. package/sdk-core/tests/integ_tests/workflow_tests/signals.rs +6 -13
  161. package/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +9 -6
  162. package/sdk-core/tests/integ_tests/workflow_tests/timers.rs +5 -5
  163. package/sdk-core/tests/integ_tests/workflow_tests/upsert_search_attrs.rs +1 -1
  164. package/sdk-core/tests/integ_tests/workflow_tests.rs +115 -11
  165. package/sdk-core/tests/main.rs +2 -2
  166. package/src/conversions.rs +57 -0
  167. package/src/lib.rs +1 -0
  168. package/src/runtime.rs +51 -35
  169. package/ts/index.ts +67 -3
  170. package/sdk-core/core/src/worker/workflow/workflow_stream/saved_wf_inputs.rs +0 -117
  171. package/sdk-core/core/src/worker/workflow/workflow_stream/tonic_status_serde.rs +0 -24
  172. package/sdk-core/sdk/src/payload_converter.rs +0 -11
  173. package/sdk-core/sdk-core-protos/protos/api_upstream/.buildkite/Dockerfile +0 -2
  174. package/sdk-core/sdk-core-protos/protos/api_upstream/.buildkite/docker-compose.yml +0 -15
  175. package/sdk-core/sdk-core-protos/protos/api_upstream/.buildkite/pipeline.yml +0 -10
  176. package/sdk-core/test-utils/src/wf_input_saver.rs +0 -50
  177. package/sdk-core/tests/wf_input_replay.rs +0 -32
@@ -12,7 +12,7 @@ use temporal_sdk_core_protos::{
12
12
 
13
13
  /// Represents a connection to a lang side workflow that can have activations fed into it and
14
14
  /// command responses pulled out.
15
- pub struct DrivenWorkflow {
15
+ pub(crate) struct DrivenWorkflow {
16
16
  started_attrs: Option<WorkflowStartedInfo>,
17
17
  incoming_commands: Receiver<Vec<WFCommand>>,
18
18
  /// Outgoing activation jobs that need to be sent to the lang sdk
@@ -20,7 +20,7 @@ pub struct DrivenWorkflow {
20
20
  }
21
21
 
22
22
  impl DrivenWorkflow {
23
- pub fn new() -> (Self, Sender<Vec<WFCommand>>) {
23
+ pub(super) fn new() -> (Self, Sender<Vec<WFCommand>>) {
24
24
  let (tx, rx) = mpsc::channel();
25
25
  (
26
26
  Self {
@@ -32,7 +32,7 @@ impl DrivenWorkflow {
32
32
  )
33
33
  }
34
34
  /// Start the workflow
35
- pub fn start(
35
+ pub(super) fn start(
36
36
  &mut self,
37
37
  workflow_id: String,
38
38
  randomness_seed: u64,
@@ -53,7 +53,7 @@ impl DrivenWorkflow {
53
53
  }
54
54
 
55
55
  /// Return the attributes from the workflow execution started event if this workflow has started
56
- pub fn get_started_info(&self) -> Option<&WorkflowStartedInfo> {
56
+ pub(super) fn get_started_info(&self) -> Option<&WorkflowStartedInfo> {
57
57
  self.started_attrs.as_ref()
58
58
  }
59
59
 
@@ -68,7 +68,7 @@ impl DrivenWorkflow {
68
68
  }
69
69
 
70
70
  /// Drain all pending jobs, so that they may be sent to the driven workflow
71
- pub fn drain_jobs(&mut self) -> Vec<WorkflowActivationJob> {
71
+ pub(super) fn drain_jobs(&mut self) -> Vec<WorkflowActivationJob> {
72
72
  self.outgoing_wf_activation_jobs
73
73
  .drain(..)
74
74
  .map(Into::into)
@@ -79,7 +79,7 @@ impl DrivenWorkflow {
79
79
  /// responsible for calling workflow code as a result of receiving tasks from
80
80
  /// [crate::Core::poll_task], we cannot directly iterate it here. Commands are simply pulled
81
81
  /// from a buffer that the language side sinks into when it calls [crate::Core::complete_task]
82
- pub fn fetch_workflow_iteration_output(&mut self) -> Vec<WFCommand> {
82
+ pub(super) fn fetch_workflow_iteration_output(&mut self) -> Vec<WFCommand> {
83
83
  let in_cmds = self.incoming_commands.try_recv();
84
84
  let in_cmds = in_cmds.unwrap_or_else(|_| vec![WFCommand::NoCommandsFromLang]);
85
85
  debug!(in_cmds = %in_cmds.display(), "wf bridge iteration fetch");
@@ -7,6 +7,7 @@ use crate::{
7
7
  };
8
8
  use futures::{future::BoxFuture, FutureExt, Stream};
9
9
  use itertools::Itertools;
10
+ use once_cell::sync::Lazy;
10
11
  use std::{
11
12
  collections::VecDeque,
12
13
  fmt::Debug,
@@ -23,33 +24,29 @@ use temporal_sdk_core_protos::temporal::api::{
23
24
  };
24
25
  use tracing::Instrument;
25
26
 
26
- lazy_static::lazy_static! {
27
- static ref EMPTY_FETCH_ERR: tonic::Status
28
- = tonic::Status::unknown("Fetched empty history page");
29
- static ref EMPTY_TASK_ERR: tonic::Status
30
- = tonic::Status::unknown("Received an empty workflow task with no queries or history");
31
- }
27
+ static EMPTY_FETCH_ERR: Lazy<tonic::Status> =
28
+ Lazy::new(|| tonic::Status::unknown("Fetched empty history page"));
29
+ static EMPTY_TASK_ERR: Lazy<tonic::Status> = Lazy::new(|| {
30
+ tonic::Status::unknown("Received an empty workflow task with no queries or history")
31
+ });
32
32
 
33
33
  /// Represents one or more complete WFT sequences. History events are expected to be consumed from
34
34
  /// it and applied to the state machines via [HistoryUpdate::take_next_wft_sequence]
35
- #[cfg_attr(
36
- feature = "save_wf_inputs",
37
- derive(serde::Serialize, serde::Deserialize)
38
- )]
39
- pub struct HistoryUpdate {
35
+ pub(crate) struct HistoryUpdate {
40
36
  events: Vec<HistoryEvent>,
41
37
  /// The event ID of the last started WFT, as according to the WFT which this update was
42
38
  /// extracted from. Hence, while processing multiple logical WFTs during replay which were part
43
39
  /// of one large history fetched from server, multiple updates may have the same value here.
44
- pub previous_wft_started_id: i64,
40
+ pub(crate) previous_wft_started_id: i64,
45
41
  /// The `started_event_id` field from the WFT which this update is tied to. Multiple updates
46
42
  /// may have the same value if they're associated with the same WFT.
47
- pub wft_started_id: i64,
43
+ pub(crate) wft_started_id: i64,
48
44
  /// True if this update contains the final WFT in history, and no more attempts to extract
49
45
  /// additional updates should be made.
50
46
  has_last_wft: bool,
51
47
  wft_count: usize,
52
48
  }
49
+
53
50
  impl Debug for HistoryUpdate {
54
51
  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
55
52
  if self.is_real() {
@@ -69,7 +66,7 @@ impl Debug for HistoryUpdate {
69
66
  }
70
67
 
71
68
  #[derive(Debug)]
72
- pub enum NextWFT {
69
+ pub(crate) enum NextWFT {
73
70
  ReplayOver,
74
71
  WFT(Vec<HistoryEvent>, bool),
75
72
  NeedFetch,
@@ -77,32 +74,23 @@ pub enum NextWFT {
77
74
 
78
75
  #[derive(derive_more::DebugCustom)]
79
76
  #[debug(fmt = "HistoryPaginator(run_id: {run_id})")]
80
- #[cfg_attr(
81
- feature = "save_wf_inputs",
82
- derive(serde::Serialize, serde::Deserialize),
83
- serde(default = "HistoryPaginator::fake_deserialized")
84
- )]
85
- pub struct HistoryPaginator {
77
+ pub(crate) struct HistoryPaginator {
86
78
  pub(crate) wf_id: String,
87
79
  pub(crate) run_id: String,
88
80
  pub(crate) previous_wft_started_id: i64,
89
81
  pub(crate) wft_started_event_id: i64,
90
82
  id_of_last_event_in_last_extracted_update: Option<i64>,
91
83
 
92
- #[cfg_attr(feature = "save_wf_inputs", serde(skip))]
93
84
  client: Arc<dyn WorkerClient>,
94
- #[cfg_attr(feature = "save_wf_inputs", serde(skip))]
95
85
  event_queue: VecDeque<HistoryEvent>,
96
- #[cfg_attr(feature = "save_wf_inputs", serde(skip))]
97
86
  next_page_token: NextPageToken,
98
87
  /// These are events that should be returned once pagination has finished. This only happens
99
88
  /// during cache misses, where we got a partial task but need to fetch history from the start.
100
- #[cfg_attr(feature = "save_wf_inputs", serde(skip))]
101
89
  final_events: Vec<HistoryEvent>,
102
90
  }
103
91
 
104
92
  #[derive(Clone, Debug)]
105
- pub enum NextPageToken {
93
+ pub(crate) enum NextPageToken {
106
94
  /// There is no page token, we need to fetch history from the beginning
107
95
  FetchFromStart,
108
96
  /// There is a page token
@@ -224,22 +212,6 @@ impl HistoryPaginator {
224
212
  }
225
213
  }
226
214
 
227
- #[cfg(feature = "save_wf_inputs")]
228
- pub(super) fn fake_deserialized() -> HistoryPaginator {
229
- use crate::worker::client::mocks::mock_manual_workflow_client;
230
- HistoryPaginator {
231
- client: Arc::new(mock_manual_workflow_client()),
232
- event_queue: Default::default(),
233
- wf_id: "".to_string(),
234
- run_id: "".to_string(),
235
- next_page_token: NextPageToken::FetchFromStart,
236
- final_events: vec![],
237
- previous_wft_started_id: -2,
238
- wft_started_event_id: -2,
239
- id_of_last_event_in_last_extracted_update: None,
240
- }
241
- }
242
-
243
215
  /// Return at least the next two WFT sequences (as determined by the passed-in ID) as a
244
216
  /// [HistoryUpdate]. Two sequences supports the required peek-ahead during replay without
245
217
  /// unnecessary back-and-forth.
@@ -409,7 +381,7 @@ struct StreamingHistoryPaginator {
409
381
  impl StreamingHistoryPaginator {
410
382
  // Kept since can be used for history downloading
411
383
  #[cfg(test)]
412
- pub fn new(inner: HistoryPaginator) -> Self {
384
+ fn new(inner: HistoryPaginator) -> Self {
413
385
  Self {
414
386
  inner,
415
387
  open_history_request: None,
@@ -451,7 +423,7 @@ impl Stream for StreamingHistoryPaginator {
451
423
  impl HistoryUpdate {
452
424
  /// Sometimes it's useful to take an update out of something without needing to use an option
453
425
  /// field. Use this to replace the field with an empty update.
454
- pub fn dummy() -> Self {
426
+ pub(crate) fn dummy() -> Self {
455
427
  Self {
456
428
  events: vec![],
457
429
  previous_wft_started_id: -1,
@@ -460,10 +432,12 @@ impl HistoryUpdate {
460
432
  wft_count: 0,
461
433
  }
462
434
  }
463
- pub fn is_real(&self) -> bool {
435
+
436
+ pub(crate) fn is_real(&self) -> bool {
464
437
  self.previous_wft_started_id >= 0
465
438
  }
466
- pub fn first_event_id(&self) -> Option<i64> {
439
+
440
+ pub(crate) fn first_event_id(&self) -> Option<i64> {
467
441
  self.events.first().map(|e| e.event_id)
468
442
  }
469
443
 
@@ -485,7 +459,7 @@ impl HistoryUpdate {
485
459
  /// partial WFT sequence at the end, all events after the last complete WFT sequence (ending
486
460
  /// with WFT started) are returned back to the caller, since the history update only works in
487
461
  /// terms of complete WFT sequences.
488
- pub fn from_events<I: IntoIterator<Item = HistoryEvent>>(
462
+ pub(crate) fn from_events<I: IntoIterator<Item = HistoryEvent>>(
489
463
  events: I,
490
464
  previous_wft_started_id: i64,
491
465
  wft_started_id: i64,
@@ -566,7 +540,7 @@ impl HistoryUpdate {
566
540
  /// of one or more complete WFT sequences. IE: The event iterator must not end in the middle
567
541
  /// of a WFT sequence.
568
542
  #[cfg(test)]
569
- pub fn new_from_events<I: IntoIterator<Item = HistoryEvent>>(
543
+ fn new_from_events<I: IntoIterator<Item = HistoryEvent>>(
570
544
  events: I,
571
545
  previous_wft_started_id: i64,
572
546
  wft_started_id: i64,
@@ -590,7 +564,7 @@ impl HistoryUpdate {
590
564
  ///
591
565
  /// If we are out of WFT sequences that can be yielded by this update, it will return an empty
592
566
  /// vec, indicating more pages will need to be fetched.
593
- pub fn take_next_wft_sequence(&mut self, from_wft_started_id: i64) -> NextWFT {
567
+ pub(crate) fn take_next_wft_sequence(&mut self, from_wft_started_id: i64) -> NextWFT {
594
568
  // First, drop any events from the queue which are earlier than the passed-in id.
595
569
  if let Some(ix_first_relevant) = self.starting_index_after_skipping(from_wft_started_id) {
596
570
  self.events.drain(0..ix_first_relevant);
@@ -629,7 +603,7 @@ impl HistoryUpdate {
629
603
  /// [take_next_wft_sequence]. Will always return the first available WFT sequence if that has
630
604
  /// not been called first. May also return an empty iterator or incomplete sequence if we are at
631
605
  /// the end of history.
632
- pub fn peek_next_wft_sequence(&self, from_wft_started_id: i64) -> &[HistoryEvent] {
606
+ pub(crate) fn peek_next_wft_sequence(&self, from_wft_started_id: i64) -> &[HistoryEvent] {
633
607
  let ix_first_relevant = self
634
608
  .starting_index_after_skipping(from_wft_started_id)
635
609
  .unwrap_or_default();
@@ -645,7 +619,7 @@ impl HistoryUpdate {
645
619
 
646
620
  /// Returns true if this update has the next needed WFT sequence, false if events will need to
647
621
  /// be fetched in order to create a complete update with the entire next WFT sequence.
648
- pub fn can_take_next_wft_sequence(&self, from_wft_started_id: i64) -> bool {
622
+ pub(crate) fn can_take_next_wft_sequence(&self, from_wft_started_id: i64) -> bool {
649
623
  let next_wft_ix =
650
624
  find_end_index_of_next_wft_seq(&self.events, from_wft_started_id, self.has_last_wft);
651
625
  if let NextWFTSeqEndIndex::Incomplete(_) = next_wft_ix {
@@ -658,7 +632,7 @@ impl HistoryUpdate {
658
632
 
659
633
  /// Returns the next WFT completed event attributes, if any, starting at (inclusive) the
660
634
  /// `from_id`
661
- pub fn peek_next_wft_completed(
635
+ pub(crate) fn peek_next_wft_completed(
662
636
  &self,
663
637
  from_id: i64,
664
638
  ) -> Option<&WorkflowTaskCompletedEventAttributes> {
@@ -776,7 +750,7 @@ fn find_end_index_of_next_wft_seq(
776
750
  }
777
751
 
778
752
  #[cfg(test)]
779
- pub mod tests {
753
+ mod tests {
780
754
  use super::*;
781
755
  use crate::{
782
756
  replay::{HistoryInfo, TestHistoryBuilder},
@@ -806,7 +780,7 @@ pub mod tests {
806
780
  }
807
781
  }
808
782
 
809
- pub trait TestHBExt {
783
+ trait TestHBExt {
810
784
  fn as_history_update(&self) -> HistoryUpdate;
811
785
  }
812
786
 
@@ -28,7 +28,7 @@ use temporal_sdk_core_protos::{
28
28
  history::v1::{
29
29
  history_event, ActivityTaskCanceledEventAttributes,
30
30
  ActivityTaskCompletedEventAttributes, ActivityTaskFailedEventAttributes,
31
- ActivityTaskTimedOutEventAttributes, HistoryEvent,
31
+ ActivityTaskTimedOutEventAttributes,
32
32
  },
33
33
  },
34
34
  };
@@ -117,8 +117,8 @@ impl ActivityMachine {
117
117
  let mut s = Self::from_parts(
118
118
  Created {}.into(),
119
119
  SharedState {
120
- cancellation_type: ActivityCancellationType::from_i32(attrs.cancellation_type)
121
- .unwrap(),
120
+ cancellation_type: ActivityCancellationType::try_from(attrs.cancellation_type)
121
+ .unwrap_or(ActivityCancellationType::TryCancel),
122
122
  attrs,
123
123
  internal_flags,
124
124
  scheduled_event_id: 0,
@@ -286,19 +286,6 @@ impl WFMachinesAdapter for ActivityMachine {
286
286
  }
287
287
  })
288
288
  }
289
-
290
- fn matches_event(&self, event: &HistoryEvent) -> bool {
291
- matches!(
292
- event.event_type(),
293
- EventType::ActivityTaskScheduled
294
- | EventType::ActivityTaskStarted
295
- | EventType::ActivityTaskCompleted
296
- | EventType::ActivityTaskFailed
297
- | EventType::ActivityTaskTimedOut
298
- | EventType::ActivityTaskCancelRequested
299
- | EventType::ActivityTaskCanceled
300
- )
301
- }
302
289
  }
303
290
 
304
291
  impl TryFrom<CommandType> for ActivityMachineEvents {
@@ -781,7 +768,7 @@ fn new_cancel_failure(dat: &SharedState, attrs: ActivityTaskCanceledEventAttribu
781
768
  }
782
769
  }
783
770
 
784
- pub fn activity_fail_info(
771
+ pub(super) fn activity_fail_info(
785
772
  act_type: String,
786
773
  act_id: String,
787
774
  identity: Option<String>,
@@ -14,7 +14,7 @@ use temporal_sdk_core_protos::{
14
14
  command::v1::{command, Command, RequestCancelExternalWorkflowExecutionCommandAttributes},
15
15
  enums::v1::{CancelExternalWorkflowExecutionFailedCause, CommandType, EventType},
16
16
  failure::v1::{failure::FailureInfo, ApplicationFailureInfo, Failure},
17
- history::v1::{history_event, HistoryEvent},
17
+ history::v1::history_event,
18
18
  },
19
19
  };
20
20
 
@@ -210,15 +210,6 @@ impl WFMachinesAdapter for CancelExternalMachine {
210
210
  }
211
211
  })
212
212
  }
213
-
214
- fn matches_event(&self, event: &HistoryEvent) -> bool {
215
- matches!(
216
- event.event_type(),
217
- EventType::ExternalWorkflowExecutionCancelRequested
218
- | EventType::RequestCancelExternalWorkflowExecutionFailed
219
- | EventType::RequestCancelExternalWorkflowExecutionInitiated
220
- )
221
- }
222
213
  }
223
214
 
224
215
  impl Cancellable for CancelExternalMachine {}
@@ -1,6 +1,6 @@
1
1
  use super::{
2
- workflow_machines::MachineResponse, Cancellable, EventInfo, HistoryEvent,
3
- NewMachineWithCommand, OnEventWrapper, WFMachinesAdapter, WFMachinesError,
2
+ workflow_machines::MachineResponse, Cancellable, EventInfo, NewMachineWithCommand,
3
+ OnEventWrapper, WFMachinesAdapter, WFMachinesError,
4
4
  };
5
5
  use crate::worker::workflow::machines::HistEventData;
6
6
  use rustfsm::{fsm, StateMachine, TransitionResult};
@@ -27,9 +27,6 @@ fsm! {
27
27
  --> CancelWorkflowCommandRecorded;
28
28
  }
29
29
 
30
- #[derive(thiserror::Error, Debug)]
31
- pub(super) enum CancelWorkflowMachineError {}
32
-
33
30
  #[derive(Debug, derive_more::Display)]
34
31
  pub(super) enum CancelWorkflowCommand {}
35
32
 
@@ -75,8 +72,8 @@ impl TryFrom<HistEventData> for CancelWorkflowMachineEvents {
75
72
 
76
73
  fn try_from(e: HistEventData) -> Result<Self, Self::Error> {
77
74
  let e = e.event;
78
- Ok(match EventType::from_i32(e.event_type) {
79
- Some(EventType::WorkflowExecutionCanceled) => Self::WorkflowExecutionCanceled,
75
+ Ok(match EventType::try_from(e.event_type) {
76
+ Ok(EventType::WorkflowExecutionCanceled) => Self::WorkflowExecutionCanceled,
80
77
  _ => {
81
78
  return Err(WFMachinesError::Nondeterminism(format!(
82
79
  "Cancel workflow machine does not handle this event: {e}"
@@ -105,10 +102,6 @@ impl WFMachinesAdapter for CancelWorkflowMachine {
105
102
  ) -> Result<Vec<MachineResponse>, WFMachinesError> {
106
103
  Ok(vec![])
107
104
  }
108
-
109
- fn matches_event(&self, event: &HistoryEvent) -> bool {
110
- event.event_type() == EventType::WorkflowExecutionCanceled
111
- }
112
105
  }
113
106
 
114
107
  impl Cancellable for CancelWorkflowMachine {}
@@ -38,7 +38,7 @@ use temporal_sdk_core_protos::{
38
38
  history::v1::{
39
39
  history_event, ChildWorkflowExecutionCompletedEventAttributes,
40
40
  ChildWorkflowExecutionFailedEventAttributes,
41
- ChildWorkflowExecutionStartedEventAttributes, HistoryEvent,
41
+ ChildWorkflowExecutionStartedEventAttributes,
42
42
  StartChildWorkflowExecutionFailedEventAttributes,
43
43
  },
44
44
  },
@@ -98,7 +98,7 @@ fsm! {
98
98
  Completed --(Cancel) --> Completed;
99
99
  }
100
100
 
101
- pub struct ChildWorkflowExecutionStartedEvent {
101
+ pub(super) struct ChildWorkflowExecutionStartedEvent {
102
102
  workflow_execution: WorkflowExecution,
103
103
  started_event_id: i64,
104
104
  }
@@ -283,7 +283,7 @@ impl StartEventRecorded {
283
283
  event: ChildWorkflowExecutionStartedEvent,
284
284
  ) -> ChildWorkflowMachineTransition<Started> {
285
285
  state.started_event_id = event.started_event_id;
286
- state.run_id = event.workflow_execution.run_id.clone();
286
+ state.run_id.clone_from(&event.workflow_execution.run_id);
287
287
  ChildWorkflowMachineTransition::commands(vec![ChildWorkflowCommand::Start(
288
288
  event.workflow_execution,
289
289
  )])
@@ -498,8 +498,8 @@ impl TryFrom<HistEventData> for ChildWorkflowMachineEvents {
498
498
  fn try_from(e: HistEventData) -> Result<Self, Self::Error> {
499
499
  let last_task_in_history = e.current_task_is_last_in_history;
500
500
  let e = e.event;
501
- Ok(match EventType::from_i32(e.event_type) {
502
- Some(EventType::StartChildWorkflowExecutionInitiated) => {
501
+ Ok(match EventType::try_from(e.event_type) {
502
+ Ok(EventType::StartChildWorkflowExecutionInitiated) => {
503
503
  if let Some(
504
504
  history_event::Attributes::StartChildWorkflowExecutionInitiatedEventAttributes(
505
505
  attrs,
@@ -518,7 +518,7 @@ impl TryFrom<HistEventData> for ChildWorkflowMachineEvents {
518
518
  ));
519
519
  }
520
520
  }
521
- Some(EventType::StartChildWorkflowExecutionFailed) => {
521
+ Ok(EventType::StartChildWorkflowExecutionFailed) => {
522
522
  if let Some(
523
523
  history_event::Attributes::StartChildWorkflowExecutionFailedEventAttributes(
524
524
  StartChildWorkflowExecutionFailedEventAttributes { cause, .. },
@@ -526,13 +526,11 @@ impl TryFrom<HistEventData> for ChildWorkflowMachineEvents {
526
526
  ) = e.attributes
527
527
  {
528
528
  Self::StartChildWorkflowExecutionFailed(
529
- StartChildWorkflowExecutionFailedCause::from_i32(cause).ok_or_else(
530
- || {
531
- WFMachinesError::Fatal(
532
- "Invalid StartChildWorkflowExecutionFailedCause".to_string(),
533
- )
534
- },
535
- )?,
529
+ StartChildWorkflowExecutionFailedCause::try_from(cause).map_err(|_| {
530
+ WFMachinesError::Fatal(
531
+ "Invalid StartChildWorkflowExecutionFailedCause".to_string(),
532
+ )
533
+ })?,
536
534
  )
537
535
  } else {
538
536
  return Err(WFMachinesError::Fatal(
@@ -540,7 +538,7 @@ impl TryFrom<HistEventData> for ChildWorkflowMachineEvents {
540
538
  ));
541
539
  }
542
540
  }
543
- Some(EventType::ChildWorkflowExecutionStarted) => {
541
+ Ok(EventType::ChildWorkflowExecutionStarted) => {
544
542
  if let Some(
545
543
  history_event::Attributes::ChildWorkflowExecutionStartedEventAttributes(
546
544
  ChildWorkflowExecutionStartedEventAttributes {
@@ -561,7 +559,7 @@ impl TryFrom<HistEventData> for ChildWorkflowMachineEvents {
561
559
  ));
562
560
  }
563
561
  }
564
- Some(EventType::ChildWorkflowExecutionCompleted) => {
562
+ Ok(EventType::ChildWorkflowExecutionCompleted) => {
565
563
  if let Some(
566
564
  history_event::Attributes::ChildWorkflowExecutionCompletedEventAttributes(
567
565
  ChildWorkflowExecutionCompletedEventAttributes { result, .. },
@@ -576,7 +574,7 @@ impl TryFrom<HistEventData> for ChildWorkflowMachineEvents {
576
574
  ));
577
575
  }
578
576
  }
579
- Some(EventType::ChildWorkflowExecutionFailed) => {
577
+ Ok(EventType::ChildWorkflowExecutionFailed) => {
580
578
  if let Some(
581
579
  history_event::Attributes::ChildWorkflowExecutionFailedEventAttributes(attrs),
582
580
  ) = e.attributes
@@ -588,7 +586,7 @@ impl TryFrom<HistEventData> for ChildWorkflowMachineEvents {
588
586
  ));
589
587
  }
590
588
  }
591
- Some(EventType::ChildWorkflowExecutionTimedOut) => {
589
+ Ok(EventType::ChildWorkflowExecutionTimedOut) => {
592
590
  if let Some(
593
591
  history_event::Attributes::ChildWorkflowExecutionTimedOutEventAttributes(atts),
594
592
  ) = e.attributes
@@ -601,12 +599,10 @@ impl TryFrom<HistEventData> for ChildWorkflowMachineEvents {
601
599
  ));
602
600
  }
603
601
  }
604
- Some(EventType::ChildWorkflowExecutionTerminated) => {
602
+ Ok(EventType::ChildWorkflowExecutionTerminated) => {
605
603
  Self::ChildWorkflowExecutionTerminated
606
604
  }
607
- Some(EventType::ChildWorkflowExecutionCanceled) => {
608
- Self::ChildWorkflowExecutionCancelled
609
- }
605
+ Ok(EventType::ChildWorkflowExecutionCanceled) => Self::ChildWorkflowExecutionCancelled,
610
606
  _ => {
611
607
  return Err(WFMachinesError::Nondeterminism(format!(
612
608
  "Child workflow machine does not handle this event: {e:?}"
@@ -708,20 +704,6 @@ impl WFMachinesAdapter for ChildWorkflowMachine {
708
704
  }
709
705
  })
710
706
  }
711
-
712
- fn matches_event(&self, event: &HistoryEvent) -> bool {
713
- matches!(
714
- event.event_type(),
715
- EventType::StartChildWorkflowExecutionInitiated
716
- | EventType::StartChildWorkflowExecutionFailed
717
- | EventType::ChildWorkflowExecutionStarted
718
- | EventType::ChildWorkflowExecutionCompleted
719
- | EventType::ChildWorkflowExecutionFailed
720
- | EventType::ChildWorkflowExecutionTimedOut
721
- | EventType::ChildWorkflowExecutionTerminated
722
- | EventType::ChildWorkflowExecutionCanceled
723
- )
724
- }
725
707
  }
726
708
 
727
709
  impl TryFrom<CommandType> for ChildWorkflowMachineEvents {
@@ -10,7 +10,6 @@ use temporal_sdk_core_protos::{
10
10
  temporal::api::{
11
11
  command::v1::Command,
12
12
  enums::v1::{CommandType, EventType},
13
- history::v1::HistoryEvent,
14
13
  },
15
14
  };
16
15
 
@@ -103,9 +102,6 @@ impl Created {
103
102
  }
104
103
  }
105
104
 
106
- #[derive(thiserror::Error, Debug)]
107
- pub(super) enum CompleteWorkflowMachineError {}
108
-
109
105
  #[derive(Default, Clone)]
110
106
  pub(super) struct CompleteWorkflowCommandCreated {}
111
107
 
@@ -126,10 +122,6 @@ impl WFMachinesAdapter for CompleteWorkflowMachine {
126
122
  ) -> Result<Vec<MachineResponse>, WFMachinesError> {
127
123
  Ok(vec![])
128
124
  }
129
-
130
- fn matches_event(&self, event: &HistoryEvent) -> bool {
131
- event.event_type() == EventType::WorkflowExecutionCompleted
132
- }
133
125
  }
134
126
 
135
127
  impl Cancellable for CompleteWorkflowMachine {}
@@ -1,5 +1,5 @@
1
1
  use super::{
2
- Cancellable, EventInfo, HistoryEvent, MachineResponse, NewMachineWithCommand, OnEventWrapper,
2
+ Cancellable, EventInfo, MachineResponse, NewMachineWithCommand, OnEventWrapper,
3
3
  WFMachinesAdapter, WFMachinesError,
4
4
  };
5
5
  use crate::worker::workflow::machines::HistEventData;
@@ -107,10 +107,6 @@ impl WFMachinesAdapter for ContinueAsNewWorkflowMachine {
107
107
  ) -> Result<Vec<MachineResponse>, WFMachinesError> {
108
108
  Ok(vec![])
109
109
  }
110
-
111
- fn matches_event(&self, event: &HistoryEvent) -> bool {
112
- event.event_type() == EventType::WorkflowExecutionContinuedAsNew
113
- }
114
110
  }
115
111
 
116
112
  impl Cancellable for ContinueAsNewWorkflowMachine {}
@@ -10,7 +10,6 @@ use temporal_sdk_core_protos::{
10
10
  temporal::api::{
11
11
  command::v1::Command as ProtoCommand,
12
12
  enums::v1::{CommandType, EventType},
13
- history::v1::HistoryEvent,
14
13
  },
15
14
  };
16
15
 
@@ -117,10 +116,6 @@ impl WFMachinesAdapter for FailWorkflowMachine {
117
116
  ) -> Result<Vec<MachineResponse>, WFMachinesError> {
118
117
  Ok(vec![])
119
118
  }
120
-
121
- fn matches_event(&self, event: &HistoryEvent) -> bool {
122
- event.event_type() == EventType::WorkflowExecutionFailed
123
- }
124
119
  }
125
120
 
126
121
  impl Cancellable for FailWorkflowMachine {}
@@ -34,7 +34,6 @@ use temporal_sdk_core_protos::{
34
34
  command::v1::{command, RecordMarkerCommandAttributes},
35
35
  enums::v1::{CommandType, EventType, RetryState},
36
36
  failure::v1::{failure::FailureInfo, Failure},
37
- history::v1::HistoryEvent,
38
37
  },
39
38
  utilities::TryIntoOrNone,
40
39
  };
@@ -799,10 +798,6 @@ impl WFMachinesAdapter for LocalActivityMachine {
799
798
  }
800
799
  }
801
800
  }
802
-
803
- fn matches_event(&self, event: &HistoryEvent) -> bool {
804
- event.is_local_activity_marker()
805
- }
806
801
  }
807
802
 
808
803
  impl TryFrom<CommandType> for LocalActivityMachineEvents {
@@ -84,11 +84,6 @@ trait TemporalStateMachine {
84
84
  command_type: CommandType,
85
85
  ) -> Result<Vec<MachineResponse>, WFMachinesError>;
86
86
 
87
- /// Returns true if this machine is compatible with the provided event. Provides a way to know
88
- /// ahead of time if it's worth trying to call [TemporalStateMachine::handle_event] without
89
- /// requiring mutable access.
90
- fn matches_event(&self, event: &HistoryEvent) -> bool;
91
-
92
87
  /// Tell the state machine to handle some event. Returns a list of responses that can be used
93
88
  /// to update the overall state of the workflow. EX: To issue outgoing WF activations.
94
89
  fn handle_event(
@@ -150,10 +145,6 @@ where
150
145
  }
151
146
  }
152
147
 
153
- fn matches_event(&self, event: &HistoryEvent) -> bool {
154
- self.matches_event(event)
155
- }
156
-
157
148
  fn handle_event(
158
149
  &mut self,
159
150
  event_dat: HistEventData,
@@ -240,11 +231,6 @@ trait WFMachinesAdapter: StateMachine {
240
231
  my_command: Self::Command,
241
232
  event_info: Option<EventInfo>,
242
233
  ) -> Result<Vec<MachineResponse>, WFMachinesError>;
243
-
244
- /// Returns true if this machine is compatible with the provided event. Provides a way to know
245
- /// ahead of time if it's worth trying to call [TemporalStateMachine::handle_event] without
246
- /// requiring mutable access.
247
- fn matches_event(&self, event: &HistoryEvent) -> bool;
248
234
  }
249
235
 
250
236
  /// Wraps a history event with extra relevant data that a machine might care about while the event
@@ -9,7 +9,6 @@ use temporal_sdk_core_protos::{
9
9
  temporal::api::{
10
10
  command::v1::Command,
11
11
  enums::v1::{CommandType, EventType},
12
- history::v1::HistoryEvent,
13
12
  },
14
13
  };
15
14
 
@@ -63,10 +62,6 @@ impl WFMachinesAdapter for ModifyWorkflowPropertiesMachine {
63
62
  "ModifyWorkflowProperties does not use state machine commands".to_string(),
64
63
  ))
65
64
  }
66
-
67
- fn matches_event(&self, event: &HistoryEvent) -> bool {
68
- matches!(event.event_type(), EventType::WorkflowPropertiesModified)
69
- }
70
65
  }
71
66
 
72
67
  impl Cancellable for ModifyWorkflowPropertiesMachine {}