@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
@@ -11,15 +11,12 @@ mod wft_extraction;
11
11
  pub(crate) mod wft_poller;
12
12
  mod workflow_stream;
13
13
 
14
- #[cfg(feature = "save_wf_inputs")]
15
- pub use workflow_stream::replay_wf_state_inputs;
16
-
17
14
  pub(crate) use driven_workflow::DrivenWorkflow;
18
15
  pub(crate) use history_update::HistoryUpdate;
19
16
 
20
17
  use crate::{
21
18
  abstractions::{
22
- dbg_panic, take_cell::TakeCell, MeteredSemaphore, TrackedOwnedMeteredSemPermit,
19
+ dbg_panic, take_cell::TakeCell, MeteredPermitDealer, TrackedOwnedMeteredSemPermit,
23
20
  UsedMeteredSemPermit,
24
21
  },
25
22
  internal_flags::InternalFlags,
@@ -61,7 +58,7 @@ use std::{
61
58
  };
62
59
  use temporal_sdk_core_api::{
63
60
  errors::{CompleteWfError, PollWfError},
64
- worker::WorkerConfig,
61
+ worker::{ActivitySlotKind, WorkerConfig, WorkflowSlotKind},
65
62
  };
66
63
  use temporal_sdk_core_protos::{
67
64
  coresdk::{
@@ -125,26 +122,26 @@ pub(crate) struct Workflows {
125
122
  /// If set, can be used to reserve activity task slots for eager-return of new activity tasks.
126
123
  activity_tasks_handle: Option<ActivitiesFromWFTsHandle>,
127
124
  /// Ensures we stay at or below this worker's maximum concurrent workflow task limit
128
- wft_semaphore: Arc<MeteredSemaphore>,
125
+ wft_semaphore: Arc<MeteredPermitDealer<WorkflowSlotKind>>,
129
126
  local_act_mgr: Arc<LocalActivityManager>,
130
127
  ever_polled: AtomicBool,
131
128
  }
132
129
 
133
130
  pub(crate) struct WorkflowBasics {
134
- pub worker_config: Arc<WorkerConfig>,
135
- pub shutdown_token: CancellationToken,
136
- pub metrics: MetricsContext,
137
- pub server_capabilities: get_system_info_response::Capabilities,
131
+ pub(crate) worker_config: Arc<WorkerConfig>,
132
+ pub(crate) shutdown_token: CancellationToken,
133
+ pub(crate) metrics: MetricsContext,
134
+ pub(crate) server_capabilities: get_system_info_response::Capabilities,
138
135
  }
139
136
 
140
137
  pub(crate) struct RunBasics<'a> {
141
- pub worker_config: Arc<WorkerConfig>,
142
- pub workflow_id: String,
143
- pub workflow_type: String,
144
- pub run_id: String,
145
- pub history: HistoryUpdate,
146
- pub metrics: MetricsContext,
147
- pub capabilities: &'a get_system_info_response::Capabilities,
138
+ pub(crate) worker_config: Arc<WorkerConfig>,
139
+ pub(crate) workflow_id: String,
140
+ pub(crate) workflow_type: String,
141
+ pub(crate) run_id: String,
142
+ pub(crate) history: HistoryUpdate,
143
+ pub(crate) metrics: MetricsContext,
144
+ pub(crate) capabilities: &'a get_system_info_response::Capabilities,
148
145
  }
149
146
 
150
147
  impl Workflows {
@@ -153,7 +150,7 @@ impl Workflows {
153
150
  basics: WorkflowBasics,
154
151
  sticky_attrs: Option<StickyExecutionAttributes>,
155
152
  client: Arc<dyn WorkerClient>,
156
- wft_semaphore: Arc<MeteredSemaphore>,
153
+ wft_semaphore: Arc<MeteredPermitDealer<WorkflowSlotKind>>,
157
154
  wft_stream: impl Stream<Item = WFTStreamIn> + Send + 'static,
158
155
  local_activity_request_sink: impl LocalActivityRequestSink,
159
156
  local_act_mgr: Arc<LocalActivityManager>,
@@ -291,7 +288,7 @@ impl Workflows {
291
288
  self.activation_completed(
292
289
  WorkflowActivationCompletion {
293
290
  run_id,
294
- status: Some(auto_fail_to_complete_status(machines_err)),
291
+ status: Some(machines_err.as_failure().into()),
295
292
  },
296
293
  true,
297
294
  Option::<Box<dyn Fn(PostActivateHookData) + Send>>::None,
@@ -458,7 +455,6 @@ impl Workflows {
458
455
  if let Some(h) = post_activate_hook {
459
456
  h(PostActivateHookData {
460
457
  run_id: &run_id,
461
- most_recent_event: completion_outcome.most_recently_processed_event,
462
458
  replaying: completion_outcome.replaying,
463
459
  });
464
460
  }
@@ -514,11 +510,11 @@ impl Workflows {
514
510
  async move { rx.await.ok() }
515
511
  }
516
512
 
517
- pub(super) fn available_wft_permits(&self) -> usize {
513
+ pub(super) fn available_wft_permits(&self) -> Option<usize> {
518
514
  self.wft_semaphore.available_permits()
519
515
  }
520
516
  #[cfg(test)]
521
- pub(super) fn unused_wft_permits(&self) -> usize {
517
+ pub(super) fn unused_wft_permits(&self) -> Option<usize> {
522
518
  self.wft_semaphore.unused_permits()
523
519
  }
524
520
 
@@ -617,7 +613,7 @@ impl Workflows {
617
613
  /// Process eagerly returned activities from WFT completion
618
614
  fn handle_eager_activities(
619
615
  &self,
620
- reserved_act_permits: Vec<TrackedOwnedMeteredSemPermit>,
616
+ reserved_act_permits: Vec<TrackedOwnedMeteredSemPermit<ActivitySlotKind>>,
621
617
  eager_acts: Vec<PollActivityTaskQueueResponse>,
622
618
  ) {
623
619
  if let Some(at_handle) = self.activity_tasks_handle.as_ref() {
@@ -661,7 +657,7 @@ impl Workflows {
661
657
  fn reserve_activity_slots_for_outgoing_commands(
662
658
  &self,
663
659
  commands: &mut [Command],
664
- ) -> Vec<TrackedOwnedMeteredSemPermit> {
660
+ ) -> Vec<TrackedOwnedMeteredSemPermit<ActivitySlotKind>> {
665
661
  let mut reserved = vec![];
666
662
  for cmd in commands {
667
663
  if let Some(Attributes::ScheduleActivityTaskCommandAttributes(attrs)) =
@@ -758,30 +754,14 @@ enum ActivationOrAuto {
758
754
  /// A WFT which is considered to be using a slot for metrics purposes and being or about to be
759
755
  /// applied to workflow state.
760
756
  #[derive(derive_more::DebugCustom)]
761
- #[cfg_attr(
762
- feature = "save_wf_inputs",
763
- derive(serde::Serialize, serde::Deserialize)
764
- )]
765
757
  #[debug(fmt = "PermittedWft({work:?})")]
766
758
  pub(crate) struct PermittedWFT {
767
759
  work: PreparedWFT,
768
- #[cfg_attr(
769
- feature = "save_wf_inputs",
770
- serde(skip, default = "UsedMeteredSemPermit::fake_deserialized")
771
- )]
772
- permit: UsedMeteredSemPermit,
773
- #[cfg_attr(
774
- feature = "save_wf_inputs",
775
- serde(skip, default = "HistoryPaginator::fake_deserialized")
776
- )]
760
+ permit: UsedMeteredSemPermit<WorkflowSlotKind>,
777
761
  paginator: HistoryPaginator,
778
762
  }
779
763
  /// A WFT without a permit
780
764
  #[derive(Debug)]
781
- #[cfg_attr(
782
- feature = "save_wf_inputs",
783
- derive(serde::Serialize, serde::Deserialize)
784
- )]
785
765
  struct WFTWithPaginator {
786
766
  wft: PreparedWFT,
787
767
  paginator: HistoryPaginator,
@@ -789,10 +769,6 @@ struct WFTWithPaginator {
789
769
 
790
770
  /// A WFT which has been validated and had a history update extracted from it.
791
771
  #[derive(Debug)]
792
- #[cfg_attr(
793
- feature = "save_wf_inputs",
794
- derive(serde::Serialize, serde::Deserialize)
795
- )]
796
772
  struct PreparedWFT {
797
773
  task_token: TaskToken,
798
774
  attempt: u32,
@@ -803,10 +779,11 @@ struct PreparedWFT {
803
779
  update: HistoryUpdate,
804
780
  messages: Vec<IncomingProtocolMessage>,
805
781
  }
782
+
806
783
  impl PreparedWFT {
807
784
  /// Returns true if the contained history update is incremental (IE: expects to hit a cached
808
785
  /// workflow)
809
- pub fn is_incremental(&self) -> bool {
786
+ fn is_incremental(&self) -> bool {
810
787
  let start_event_id = self.update.first_event_id();
811
788
  let poll_resp_is_incremental = start_event_id.map(|eid| eid > 1).unwrap_or_default();
812
789
  poll_resp_is_incremental || start_event_id.is_none()
@@ -819,18 +796,18 @@ impl PreparedWFT {
819
796
  }
820
797
 
821
798
  #[derive(Debug)]
822
- pub(crate) struct OutstandingTask {
823
- pub info: WorkflowTaskInfo,
799
+ struct OutstandingTask {
800
+ info: WorkflowTaskInfo,
824
801
  /// Set if the outstanding task has quer(ies) which must be fulfilled upon finishing replay
825
- pub pending_queries: Vec<QueryWorkflow>,
826
- pub start_time: Instant,
802
+ pending_queries: Vec<QueryWorkflow>,
803
+ start_time: Instant,
827
804
  /// The WFT permit owned by this task, ensures we don't exceed max concurrent WFT, and makes
828
805
  /// sure the permit is automatically freed when we delete the task.
829
- pub permit: UsedMeteredSemPermit,
806
+ permit: UsedMeteredSemPermit<WorkflowSlotKind>,
830
807
  }
831
808
 
832
809
  impl OutstandingTask {
833
- pub fn has_pending_legacy_query(&self) -> bool {
810
+ fn has_pending_legacy_query(&self) -> bool {
834
811
  self.pending_queries
835
812
  .iter()
836
813
  .any(|q| q.query_id == LEGACY_QUERY_ID)
@@ -840,62 +817,38 @@ impl OutstandingTask {
840
817
  #[derive(Copy, Clone, Debug)]
841
818
  pub(crate) enum OutstandingActivation {
842
819
  /// A normal activation with a joblist
843
- Normal {
844
- /// True if there is an eviction in the joblist
845
- contains_eviction: bool,
846
- /// Number of jobs in the activation
847
- num_jobs: usize,
848
- },
820
+ Normal,
821
+ /// An eviction job
822
+ Eviction,
849
823
  /// An activation for a legacy query
850
824
  LegacyQuery,
851
825
  /// A fake activation which is never sent to lang, but used internally
852
826
  Autocomplete,
853
827
  }
854
828
 
855
- impl OutstandingActivation {
856
- pub(crate) const fn has_only_eviction(self) -> bool {
857
- matches!(
858
- self,
859
- OutstandingActivation::Normal {
860
- contains_eviction: true,
861
- num_jobs: nj
862
- }
863
- if nj == 1)
864
- }
865
- pub(crate) const fn has_eviction(self) -> bool {
866
- matches!(
867
- self,
868
- OutstandingActivation::Normal {
869
- contains_eviction: true,
870
- ..
871
- }
872
- )
873
- }
874
- }
875
-
876
829
  /// Contains important information about a given workflow task that we need to memorize while
877
830
  /// lang handles it.
878
831
  #[derive(Clone, Debug)]
879
- pub struct WorkflowTaskInfo {
880
- pub task_token: TaskToken,
881
- pub attempt: u32,
832
+ struct WorkflowTaskInfo {
833
+ task_token: TaskToken,
834
+ attempt: u32,
882
835
  /// Exists to allow easy tagging of spans with workflow ids. Is duplicative of info inside the
883
836
  /// run machines themselves, but that can't be accessed easily. Would be nice to somehow have a
884
837
  /// shared repository, or refcounts, or whatever, for strings like these that get duped all
885
838
  /// sorts of places.
886
- pub wf_id: String,
839
+ wf_id: String,
887
840
  }
888
841
 
889
842
  #[derive(Debug)]
890
- pub enum FailedActivationWFTReport {
843
+ enum FailedActivationWFTReport {
891
844
  Report(TaskToken, WorkflowTaskFailedCause, Failure),
892
845
  ReportLegacyQueryFailure(TaskToken, Failure),
893
846
  }
894
847
 
895
848
  #[derive(Debug)]
896
- pub(crate) struct ServerCommandsWithWorkflowInfo {
897
- pub task_token: TaskToken,
898
- pub action: ActivationAction,
849
+ struct ServerCommandsWithWorkflowInfo {
850
+ task_token: TaskToken,
851
+ action: ActivationAction,
899
852
  }
900
853
 
901
854
  #[derive(Debug)]
@@ -931,34 +884,21 @@ impl EvictionRequestResult {
931
884
  #[derive(Debug)]
932
885
  #[allow(dead_code)] // Not always used in non-test
933
886
  pub(crate) struct WorkflowStateInfo {
934
- pub cached_workflows: usize,
935
- pub outstanding_wft: usize,
887
+ pub(crate) cached_workflows: usize,
888
+ pub(crate) outstanding_wft: usize,
936
889
  }
937
890
 
938
891
  #[derive(Debug)]
939
- #[cfg_attr(
940
- feature = "save_wf_inputs",
941
- derive(serde::Serialize, serde::Deserialize)
942
- )]
943
892
  struct WFActCompleteMsg {
944
893
  completion: ValidatedCompletion,
945
- #[cfg_attr(feature = "save_wf_inputs", serde(skip))]
946
894
  response_tx: Option<oneshot::Sender<ActivationCompleteResult>>,
947
895
  }
948
896
  #[derive(Debug)]
949
- #[cfg_attr(
950
- feature = "save_wf_inputs",
951
- derive(serde::Serialize, serde::Deserialize)
952
- )]
953
897
  struct LocalResolutionMsg {
954
898
  run_id: String,
955
899
  res: LocalResolution,
956
900
  }
957
901
  #[derive(Debug)]
958
- #[cfg_attr(
959
- feature = "save_wf_inputs",
960
- derive(serde::Serialize, serde::Deserialize)
961
- )]
962
902
  struct PostActivationMsg {
963
903
  run_id: String,
964
904
  wft_report_status: WFTReportStatus,
@@ -966,10 +906,6 @@ struct PostActivationMsg {
966
906
  is_autocomplete: bool,
967
907
  }
968
908
  #[derive(Debug, Clone)]
969
- #[cfg_attr(
970
- feature = "save_wf_inputs",
971
- derive(serde::Serialize, serde::Deserialize)
972
- )]
973
909
  struct RequestEvictMsg {
974
910
  run_id: String,
975
911
  message: String,
@@ -992,10 +928,10 @@ struct GetStateInfoMsg {
992
928
  /// Each activation completion produces one of these
993
929
  #[derive(Debug)]
994
930
  struct ActivationCompleteResult {
995
- most_recently_processed_event: usize,
996
931
  replaying: bool,
997
932
  outcome: ActivationCompleteOutcome,
998
933
  }
934
+
999
935
  /// What needs to be done after calling [Workflows::activation_completed]
1000
936
  #[derive(Debug)]
1001
937
  #[allow(clippy::large_enum_variant)]
@@ -1012,10 +948,6 @@ enum ActivationCompleteOutcome {
1012
948
  }
1013
949
  /// Did we report, or not, completion of a WFT to server?
1014
950
  #[derive(Debug, Copy, Clone)]
1015
- #[cfg_attr(
1016
- feature = "save_wf_inputs",
1017
- derive(serde::Serialize, serde::Deserialize)
1018
- )]
1019
951
  enum WFTReportStatus {
1020
952
  Reported {
1021
953
  reset_last_started_to: Option<i64>,
@@ -1146,10 +1078,6 @@ fn validate_completion(
1146
1078
  }
1147
1079
 
1148
1080
  #[derive(Debug)]
1149
- #[cfg_attr(
1150
- feature = "save_wf_inputs",
1151
- derive(serde::Serialize, serde::Deserialize)
1152
- )]
1153
1081
  #[allow(clippy::large_enum_variant)]
1154
1082
  enum ValidatedCompletion {
1155
1083
  Success {
@@ -1165,7 +1093,7 @@ enum ValidatedCompletion {
1165
1093
  }
1166
1094
 
1167
1095
  impl ValidatedCompletion {
1168
- pub fn run_id(&self) -> &str {
1096
+ fn run_id(&self) -> &str {
1169
1097
  match self {
1170
1098
  ValidatedCompletion::Success { run_id, .. } => run_id,
1171
1099
  ValidatedCompletion::Fail { run_id, .. } => run_id,
@@ -1174,15 +1102,11 @@ impl ValidatedCompletion {
1174
1102
  }
1175
1103
 
1176
1104
  #[derive(Debug)]
1177
- #[cfg_attr(
1178
- feature = "save_wf_inputs",
1179
- derive(serde::Serialize, serde::Deserialize)
1180
- )]
1181
1105
  pub(crate) enum LocalResolution {
1182
1106
  LocalActivity(LocalActivityResolution),
1183
1107
  }
1184
1108
  impl LocalResolution {
1185
- pub fn is_la_cancel_confirmation(&self) -> bool {
1109
+ fn is_la_cancel_confirmation(&self) -> bool {
1186
1110
  match self {
1187
1111
  LocalResolution::LocalActivity(lar) => {
1188
1112
  matches!(lar.result, LocalActivityExecutionResult::Cancelled(_))
@@ -1193,17 +1117,13 @@ impl LocalResolution {
1193
1117
 
1194
1118
  #[derive(thiserror::Error, Debug, derive_more::From)]
1195
1119
  #[error("Lang provided workflow command with empty variant")]
1196
- pub struct EmptyWorkflowCommandErr;
1120
+ struct EmptyWorkflowCommandErr;
1197
1121
 
1198
1122
  /// [DrivenWorkflow]s respond with these when called, to indicate what they want to do next.
1199
1123
  /// EX: Create a new timer, complete the workflow, etc.
1200
1124
  #[derive(Debug, derive_more::From, derive_more::Display)]
1201
- #[cfg_attr(
1202
- feature = "save_wf_inputs",
1203
- derive(serde::Serialize, serde::Deserialize)
1204
- )]
1205
1125
  #[allow(clippy::large_enum_variant)]
1206
- pub enum WFCommand {
1126
+ enum WFCommand {
1207
1127
  /// Returned when we need to wait for the lang sdk to send us something
1208
1128
  NoCommandsFromLang,
1209
1129
  AddActivity(ScheduleActivity),
@@ -1281,7 +1201,7 @@ impl WFCommand {
1281
1201
  /// * Failed
1282
1202
  /// * Cancelled
1283
1203
  /// * Continue-as-new
1284
- pub fn is_terminal(&self) -> bool {
1204
+ fn is_terminal(&self) -> bool {
1285
1205
  matches!(
1286
1206
  self,
1287
1207
  WFCommand::CompleteWorkflow(_)
@@ -1305,7 +1225,7 @@ enum CommandID {
1305
1225
  /// Details remembered from the workflow execution started event that we may need to recall later.
1306
1226
  /// Is a subset of `WorkflowExecutionStartedEventAttributes`, but avoids holding on to huge fields.
1307
1227
  #[derive(Debug, Clone)]
1308
- pub struct WorkflowStartedInfo {
1228
+ struct WorkflowStartedInfo {
1309
1229
  workflow_task_timeout: Option<Duration>,
1310
1230
  memo: Option<Memo>,
1311
1231
  search_attrs: Option<SearchAttributes>,
@@ -1347,12 +1267,24 @@ pub(crate) enum WFMachinesError {
1347
1267
  }
1348
1268
 
1349
1269
  impl WFMachinesError {
1350
- pub fn evict_reason(&self) -> EvictionReason {
1270
+ fn evict_reason(&self) -> EvictionReason {
1351
1271
  match self {
1352
1272
  WFMachinesError::Nondeterminism(_) => EvictionReason::Nondeterminism,
1353
1273
  WFMachinesError::Fatal(_) => EvictionReason::Fatal,
1354
1274
  }
1355
1275
  }
1276
+
1277
+ fn as_failure(&self) -> Failure {
1278
+ Failure {
1279
+ failure: Some(
1280
+ temporal_sdk_core_protos::temporal::api::failure::v1::Failure::application_failure(
1281
+ self.to_string(),
1282
+ false,
1283
+ ),
1284
+ ),
1285
+ force_cause: WorkflowTaskFailedCause::from(self.evict_reason()) as i32,
1286
+ }
1287
+ }
1356
1288
  }
1357
1289
 
1358
1290
  impl From<TimestampError> for WFMachinesError {
@@ -1367,22 +1299,6 @@ impl From<anyhow::Error> for WFMachinesError {
1367
1299
  }
1368
1300
  }
1369
1301
 
1370
- fn auto_fail_to_complete_status(err: WFMachinesError) -> workflow_activation_completion::Status {
1371
- workflow_activation_completion::Status::Failed(Failure {
1372
- failure: Some(
1373
- temporal_sdk_core_protos::temporal::api::failure::v1::Failure {
1374
- message: "Error while processing workflow task".to_string(),
1375
- source: err.to_string(),
1376
- stack_trace: "".to_string(),
1377
- encoded_attributes: None,
1378
- cause: None,
1379
- failure_info: None,
1380
- },
1381
- ),
1382
- force_cause: WorkflowTaskFailedCause::from(err.evict_reason()) as i32,
1383
- })
1384
- }
1385
-
1386
1302
  pub(crate) trait LocalActivityRequestSink: Send + Sync + 'static {
1387
1303
  fn sink_reqs(&self, reqs: Vec<LocalActRequest>) -> Vec<LocalActivityResolution>;
1388
1304
  }
@@ -1390,10 +1306,6 @@ pub(crate) trait LocalActivityRequestSink: Send + Sync + 'static {
1390
1306
  #[derive(derive_more::Constructor)]
1391
1307
  pub(super) struct LAReqSink {
1392
1308
  lam: Arc<LocalActivityManager>,
1393
- /// If we're recording WF inputs, we also need to store immediate resolutions so they're
1394
- /// available on replay.
1395
- #[allow(dead_code)] // sometimes appears unused due to feature flagging
1396
- recorder: Option<UnboundedSender<Vec<u8>>>,
1397
1309
  }
1398
1310
 
1399
1311
  impl LocalActivityRequestSink for LAReqSink {
@@ -1401,16 +1313,7 @@ impl LocalActivityRequestSink for LAReqSink {
1401
1313
  if reqs.is_empty() {
1402
1314
  return vec![];
1403
1315
  }
1404
-
1405
- #[allow(clippy::let_and_return)] // When feature is off clippy doesn't like this
1406
- let res = self.lam.enqueue(reqs);
1407
-
1408
- // We always save when there are any reqs, even if the response might be empty, so that
1409
- // calls/responses are 1:1
1410
- #[cfg(feature = "save_wf_inputs")]
1411
- self.write_req(&res);
1412
-
1413
- res
1316
+ self.lam.enqueue(reqs)
1414
1317
  }
1415
1318
  }
1416
1319
 
@@ -22,7 +22,7 @@ pub(super) struct RunCache {
22
22
  }
23
23
 
24
24
  impl RunCache {
25
- pub fn new(
25
+ pub(super) fn new(
26
26
  worker_config: Arc<WorkerConfig>,
27
27
  server_capabilities: get_system_info_response::Capabilities,
28
28
  local_activity_request_sink: impl LocalActivityRequestSink,
@@ -46,7 +46,7 @@ impl RunCache {
46
46
  }
47
47
  }
48
48
 
49
- pub fn instantiate_or_update(&mut self, pwft: PermittedWFT) -> RunUpdateAct {
49
+ pub(super) fn instantiate_or_update(&mut self, pwft: PermittedWFT) -> RunUpdateAct {
50
50
  let cur_num_cached_runs = self.runs.len();
51
51
  let run_id = pwft.work.execution.run_id.clone();
52
52
 
@@ -80,44 +80,53 @@ impl RunCache {
80
80
  self.metrics.cache_size(cur_num_cached_runs as u64 + 1);
81
81
  rur
82
82
  }
83
- pub fn remove(&mut self, k: &str) -> Option<ManagedRun> {
83
+
84
+ pub(super) fn remove(&mut self, k: &str) -> Option<ManagedRun> {
84
85
  let r = self.runs.pop(k);
85
86
  self.metrics.cache_size(self.len() as u64);
86
87
  self.metrics.cache_eviction();
87
88
  r
88
89
  }
89
90
 
90
- pub fn get_mut(&mut self, k: &str) -> Option<&mut ManagedRun> {
91
+ pub(super) fn get_mut(&mut self, k: &str) -> Option<&mut ManagedRun> {
91
92
  self.runs.get_mut(k)
92
93
  }
93
- pub fn get(&mut self, k: &str) -> Option<&ManagedRun> {
94
+
95
+ pub(super) fn get(&mut self, k: &str) -> Option<&ManagedRun> {
94
96
  self.runs.get(k)
95
97
  }
96
98
 
97
99
  /// Returns the current least-recently-used run. Returns `None` when cache empty.
98
- pub fn current_lru_run(&self) -> Option<&str> {
100
+ pub(super) fn current_lru_run(&self) -> Option<&str> {
99
101
  self.runs.peek_lru().map(|(run_id, _)| run_id.as_str())
100
102
  }
103
+
101
104
  /// Returns an iterator yielding cached runs in LRU order
102
- pub fn runs_lru_order(&self) -> impl Iterator<Item = (&str, &ManagedRun)> {
105
+ pub(super) fn runs_lru_order(&self) -> impl Iterator<Item = (&str, &ManagedRun)> {
103
106
  self.runs.iter().rev().map(|(k, v)| (k.as_str(), v))
104
107
  }
105
- pub fn peek(&self, k: &str) -> Option<&ManagedRun> {
108
+
109
+ pub(super) fn peek(&self, k: &str) -> Option<&ManagedRun> {
106
110
  self.runs.peek(k)
107
111
  }
108
- pub fn has_run(&self, k: &str) -> bool {
112
+
113
+ pub(super) fn has_run(&self, k: &str) -> bool {
109
114
  self.runs.contains(k)
110
115
  }
111
- pub fn handles(&self) -> impl Iterator<Item = &ManagedRun> {
116
+
117
+ pub(super) fn handles(&self) -> impl Iterator<Item = &ManagedRun> {
112
118
  self.runs.iter().map(|(_, v)| v)
113
119
  }
114
- pub fn is_full(&self) -> bool {
120
+
121
+ pub(super) fn is_full(&self) -> bool {
115
122
  self.runs.cap().get() == self.runs.len()
116
123
  }
117
- pub fn len(&self) -> usize {
124
+
125
+ pub(super) fn len(&self) -> usize {
118
126
  self.runs.len()
119
127
  }
120
- pub fn cache_capacity(&self) -> usize {
128
+
129
+ pub(super) fn cache_capacity(&self) -> usize {
121
130
  self.worker_config.max_cached_workflows
122
131
  }
123
132
  }
@@ -12,6 +12,7 @@ use crate::{
12
12
  use futures::Stream;
13
13
  use futures_util::{stream, stream::PollNext, FutureExt, StreamExt};
14
14
  use std::{future, sync::Arc};
15
+ use temporal_sdk_core_api::worker::{WorkflowSlotInfo, WorkflowSlotKind};
15
16
  use temporal_sdk_core_protos::TaskToken;
16
17
  use tracing::Span;
17
18
 
@@ -21,7 +22,11 @@ pub(super) struct WFTExtractor {}
21
22
 
22
23
  pub(super) enum WFTExtractorOutput {
23
24
  NewWFT(PermittedWFT),
24
- FetchResult(PermittedWFT, Arc<HistfetchRC>),
25
+ FetchResult(
26
+ PermittedWFT,
27
+ // Field isn't read, but we need to hold on to it.
28
+ #[allow(dead_code)] Arc<HistfetchRC>,
29
+ ),
25
30
  NextPage {
26
31
  paginator: HistoryPaginator,
27
32
  update: HistoryUpdate,
@@ -36,7 +41,13 @@ pub(super) enum WFTExtractorOutput {
36
41
  PollerDead,
37
42
  }
38
43
 
39
- pub(crate) type WFTStreamIn = Result<(ValidPollWFTQResponse, OwnedMeteredSemPermit), tonic::Status>;
44
+ pub(crate) type WFTStreamIn = Result<
45
+ (
46
+ ValidPollWFTQResponse,
47
+ OwnedMeteredSemPermit<WorkflowSlotKind>,
48
+ ),
49
+ tonic::Status,
50
+ >;
40
51
  #[derive(derive_more::From, Debug)]
41
52
  pub(super) enum HistoryFetchReq {
42
53
  Full(CacheMissFetchReq, Arc<HistfetchRC>),
@@ -64,8 +75,10 @@ impl WFTExtractor {
64
75
  let tt = wft.task_token.clone();
65
76
  Ok(match HistoryPaginator::from_poll(wft, client).await {
66
77
  Ok((pag, prep)) => WFTExtractorOutput::NewWFT(PermittedWFT {
78
+ permit: permit.into_used(WorkflowSlotInfo {
79
+ workflow_type: prep.workflow_type.as_str(),
80
+ }),
67
81
  work: prep,
68
- permit: permit.into_used(),
69
82
  paginator: pag,
70
83
  }),
71
84
  Err(err) => WFTExtractorOutput::FailedFetch {
@@ -5,12 +5,21 @@ use crate::{
5
5
  MetricsContext,
6
6
  };
7
7
  use futures::{stream, Stream};
8
+ use temporal_sdk_core_api::worker::WorkflowSlotKind;
8
9
  use temporal_sdk_core_protos::temporal::api::workflowservice::v1::PollWorkflowTaskQueueResponse;
9
10
 
10
11
  pub(crate) fn new_wft_poller(
11
12
  poller: BoxedWFPoller,
12
13
  metrics: MetricsContext,
13
- ) -> impl Stream<Item = Result<(ValidPollWFTQResponse, OwnedMeteredSemPermit), tonic::Status>> {
14
+ ) -> impl Stream<
15
+ Item = Result<
16
+ (
17
+ ValidPollWFTQResponse,
18
+ OwnedMeteredSemPermit<WorkflowSlotKind>,
19
+ ),
20
+ tonic::Status,
21
+ >,
22
+ > {
14
23
  stream::unfold((poller, metrics), |(poller, metrics)| async move {
15
24
  loop {
16
25
  return match poller.poll().await {
@@ -66,10 +75,12 @@ pub(crate) fn validate_wft(
66
75
  mod tests {
67
76
  use super::*;
68
77
  use crate::{
69
- abstractions::MeteredSemaphore, pollers::MockPermittedPollBuffer, test_help::mock_poller,
78
+ abstractions::tests::fixed_size_permit_dealer, pollers::MockPermittedPollBuffer,
79
+ test_help::mock_poller,
70
80
  };
71
81
  use futures::{pin_mut, StreamExt};
72
82
  use std::sync::Arc;
83
+ use temporal_sdk_core_api::worker::WorkflowSlotKind;
73
84
 
74
85
  #[tokio::test]
75
86
  async fn poll_timeouts_do_not_produce_responses() {
@@ -80,11 +91,7 @@ mod tests {
80
91
  .returning(|| Some(Ok(PollWorkflowTaskQueueResponse::default())));
81
92
  mock_poller.expect_poll().times(1).returning(|| None);
82
93
  mock_poller.expect_shutdown().times(1).returning(|| ());
83
- let sem = Arc::new(MeteredSemaphore::new(
84
- 10,
85
- MetricsContext::no_op(),
86
- MetricsContext::available_task_slots,
87
- ));
94
+ let sem = Arc::new(fixed_size_permit_dealer::<WorkflowSlotKind>(10));
88
95
  let stream = new_wft_poller(
89
96
  Box::new(MockPermittedPollBuffer::new(sem, mock_poller)),
90
97
  MetricsContext::no_op(),
@@ -100,11 +107,7 @@ mod tests {
100
107
  .expect_poll()
101
108
  .times(1)
102
109
  .returning(|| Some(Err(tonic::Status::internal("ahhh"))));
103
- let sem = Arc::new(MeteredSemaphore::new(
104
- 10,
105
- MetricsContext::no_op(),
106
- MetricsContext::available_task_slots,
107
- ));
110
+ let sem = Arc::new(fixed_size_permit_dealer::<WorkflowSlotKind>(10));
108
111
  let stream = new_wft_poller(
109
112
  Box::new(MockPermittedPollBuffer::new(sem, mock_poller)),
110
113
  MetricsContext::no_op(),