@temporalio/core-bridge 1.11.8 → 1.12.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 (205) hide show
  1. package/Cargo.lock +219 -193
  2. package/Cargo.toml +27 -8
  3. package/README.md +5 -0
  4. package/index.js +72 -12
  5. package/lib/errors.d.ts +25 -0
  6. package/lib/errors.js +76 -1
  7. package/lib/errors.js.map +1 -1
  8. package/lib/index.d.ts +11 -478
  9. package/lib/index.js +28 -5
  10. package/lib/index.js.map +1 -1
  11. package/lib/native.d.ts +330 -0
  12. package/lib/{worker-tuner.js → native.js} +1 -1
  13. package/lib/native.js.map +1 -0
  14. package/package.json +7 -3
  15. package/releases/aarch64-apple-darwin/index.node +0 -0
  16. package/releases/aarch64-unknown-linux-gnu/index.node +0 -0
  17. package/releases/x86_64-apple-darwin/index.node +0 -0
  18. package/releases/x86_64-pc-windows-msvc/index.node +0 -0
  19. package/releases/x86_64-unknown-linux-gnu/index.node +0 -0
  20. package/sdk-core/.cargo/config.toml +8 -2
  21. package/sdk-core/.cargo/multi-worker-manual-test +15 -0
  22. package/sdk-core/.github/workflows/per-pr.yml +40 -11
  23. package/sdk-core/AGENTS.md +73 -0
  24. package/sdk-core/ARCHITECTURE.md +71 -23
  25. package/sdk-core/Cargo.toml +1 -1
  26. package/sdk-core/README.md +4 -4
  27. package/sdk-core/arch_docs/workflow_task_chunking.md +51 -0
  28. package/sdk-core/client/Cargo.toml +1 -1
  29. package/sdk-core/client/src/lib.rs +49 -13
  30. package/sdk-core/client/src/metrics.rs +15 -16
  31. package/sdk-core/client/src/proxy.rs +2 -2
  32. package/sdk-core/client/src/raw.rs +54 -8
  33. package/sdk-core/client/src/retry.rs +109 -13
  34. package/sdk-core/client/src/worker_registry/mod.rs +4 -4
  35. package/sdk-core/client/src/workflow_handle/mod.rs +1 -1
  36. package/sdk-core/core/Cargo.toml +28 -8
  37. package/sdk-core/core/src/abstractions.rs +62 -10
  38. package/sdk-core/core/src/core_tests/activity_tasks.rs +180 -8
  39. package/sdk-core/core/src/core_tests/mod.rs +4 -4
  40. package/sdk-core/core/src/core_tests/queries.rs +18 -4
  41. package/sdk-core/core/src/core_tests/workers.rs +3 -3
  42. package/sdk-core/core/src/core_tests/workflow_tasks.rs +191 -25
  43. package/sdk-core/core/src/ephemeral_server/mod.rs +10 -3
  44. package/sdk-core/core/src/internal_flags.rs +14 -14
  45. package/sdk-core/core/src/lib.rs +5 -2
  46. package/sdk-core/core/src/pollers/mod.rs +1 -1
  47. package/sdk-core/core/src/pollers/poll_buffer.rs +495 -164
  48. package/sdk-core/core/src/protosext/mod.rs +3 -3
  49. package/sdk-core/core/src/replay/mod.rs +3 -3
  50. package/sdk-core/core/src/telemetry/metrics.rs +13 -4
  51. package/sdk-core/core/src/telemetry/mod.rs +72 -70
  52. package/sdk-core/core/src/telemetry/otel.rs +51 -54
  53. package/sdk-core/core/src/test_help/mod.rs +9 -3
  54. package/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +31 -11
  55. package/sdk-core/core/src/worker/activities/local_activities.rs +35 -28
  56. package/sdk-core/core/src/worker/activities.rs +58 -30
  57. package/sdk-core/core/src/worker/client/mocks.rs +3 -3
  58. package/sdk-core/core/src/worker/client.rs +155 -53
  59. package/sdk-core/core/src/worker/mod.rs +103 -95
  60. package/sdk-core/core/src/worker/nexus.rs +100 -73
  61. package/sdk-core/core/src/worker/tuner/resource_based.rs +14 -6
  62. package/sdk-core/core/src/worker/tuner.rs +4 -13
  63. package/sdk-core/core/src/worker/workflow/history_update.rs +47 -51
  64. package/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +1 -4
  65. package/sdk-core/core/src/worker/workflow/machines/nexus_operation_state_machine.rs +127 -32
  66. package/sdk-core/core/src/worker/workflow/machines/transition_coverage.rs +1 -2
  67. package/sdk-core/core/src/worker/workflow/machines/update_state_machine.rs +1 -1
  68. package/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +55 -42
  69. package/sdk-core/core/src/worker/workflow/managed_run.rs +45 -35
  70. package/sdk-core/core/src/worker/workflow/mod.rs +200 -97
  71. package/sdk-core/core/src/worker/workflow/wft_poller.rs +175 -4
  72. package/sdk-core/core/src/worker/workflow/workflow_stream.rs +38 -36
  73. package/sdk-core/core-api/Cargo.toml +8 -0
  74. package/sdk-core/core-api/src/envconfig.rs +1544 -0
  75. package/sdk-core/core-api/src/lib.rs +2 -0
  76. package/sdk-core/core-api/src/telemetry/metrics.rs +8 -0
  77. package/sdk-core/core-api/src/telemetry.rs +36 -3
  78. package/sdk-core/core-api/src/worker.rs +301 -75
  79. package/sdk-core/docker/docker-compose-telem.yaml +1 -0
  80. package/sdk-core/etc/prometheus.yaml +6 -2
  81. package/sdk-core/histories/long_local_activity_with_update-0_history.bin +0 -0
  82. package/sdk-core/histories/long_local_activity_with_update-1_history.bin +0 -0
  83. package/sdk-core/histories/long_local_activity_with_update-2_history.bin +0 -0
  84. package/sdk-core/histories/long_local_activity_with_update-3_history.bin +0 -0
  85. package/sdk-core/sdk/src/activity_context.rs +5 -0
  86. package/sdk-core/sdk/src/interceptors.rs +73 -3
  87. package/sdk-core/sdk/src/lib.rs +15 -16
  88. package/sdk-core/sdk/src/workflow_context/options.rs +10 -0
  89. package/sdk-core/sdk/src/workflow_context.rs +48 -29
  90. package/sdk-core/sdk/src/workflow_future.rs +5 -6
  91. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/.github/workflows/push-to-buf.yml +20 -0
  92. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/CODEOWNERS +6 -0
  93. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/README.md +17 -6
  94. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/VERSION +1 -1
  95. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/buf.lock +7 -2
  96. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/buf.yaml +2 -0
  97. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/cloudservice/v1/request_response.proto +78 -0
  98. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/cloudservice/v1/service.proto +29 -0
  99. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/identity/v1/message.proto +74 -32
  100. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/namespace/v1/message.proto +45 -15
  101. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/nexus/v1/message.proto +7 -1
  102. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/operation/v1/message.proto +3 -3
  103. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/region/v1/message.proto +3 -3
  104. package/sdk-core/sdk-core-protos/protos/api_upstream/LICENSE +1 -1
  105. package/sdk-core/sdk-core-protos/protos/api_upstream/buf.yaml +2 -0
  106. package/sdk-core/sdk-core-protos/protos/api_upstream/openapi/openapiv2.json +1103 -88
  107. package/sdk-core/sdk-core-protos/protos/api_upstream/openapi/openapiv3.yaml +1233 -151
  108. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/activity/v1/message.proto +0 -22
  109. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/batch/v1/message.proto +19 -24
  110. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/command/v1/message.proto +0 -22
  111. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/common/v1/message.proto +12 -22
  112. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/deployment/v1/message.proto +45 -45
  113. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/batch_operation.proto +0 -22
  114. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/command_type.proto +0 -22
  115. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/common.proto +15 -22
  116. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/deployment.proto +0 -22
  117. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/event_type.proto +4 -22
  118. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +0 -22
  119. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/namespace.proto +0 -22
  120. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/nexus.proto +0 -20
  121. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/query.proto +0 -22
  122. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/reset.proto +0 -22
  123. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/schedule.proto +0 -22
  124. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/task_queue.proto +0 -22
  125. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/update.proto +0 -22
  126. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/workflow.proto +4 -22
  127. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/errordetails/v1/message.proto +0 -22
  128. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/export/v1/message.proto +0 -22
  129. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/failure/v1/message.proto +2 -22
  130. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/filter/v1/message.proto +0 -22
  131. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/history/v1/message.proto +75 -49
  132. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/namespace/v1/message.proto +0 -22
  133. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/nexus/v1/message.proto +0 -20
  134. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +0 -22
  135. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/operatorservice/v1/service.proto +0 -22
  136. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/protocol/v1/message.proto +0 -22
  137. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/query/v1/message.proto +0 -22
  138. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/replication/v1/message.proto +0 -22
  139. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/rules/v1/message.proto +90 -0
  140. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/schedule/v1/message.proto +0 -22
  141. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/sdk/v1/enhanced_stack_trace.proto +0 -22
  142. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/sdk/v1/task_complete_metadata.proto +0 -22
  143. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/sdk/v1/user_metadata.proto +0 -22
  144. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/sdk/v1/workflow_metadata.proto +0 -22
  145. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +17 -38
  146. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/update/v1/message.proto +0 -22
  147. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/version/v1/message.proto +0 -22
  148. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflow/v1/message.proto +151 -44
  149. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +172 -65
  150. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +69 -28
  151. package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/activity_task/activity_task.proto +18 -0
  152. package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/common/common.proto +5 -0
  153. package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/nexus/nexus.proto +16 -1
  154. package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +21 -15
  155. package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +3 -0
  156. package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/workflow_completion/workflow_completion.proto +3 -0
  157. package/sdk-core/sdk-core-protos/src/lib.rs +60 -16
  158. package/sdk-core/test-utils/src/lib.rs +157 -39
  159. package/sdk-core/tests/cloud_tests.rs +86 -0
  160. package/sdk-core/tests/fuzzy_workflow.rs +23 -26
  161. package/sdk-core/tests/global_metric_tests.rs +116 -0
  162. package/sdk-core/tests/heavy_tests.rs +127 -7
  163. package/sdk-core/tests/integ_tests/client_tests.rs +2 -8
  164. package/sdk-core/tests/integ_tests/metrics_tests.rs +100 -106
  165. package/sdk-core/tests/integ_tests/polling_tests.rs +94 -8
  166. package/sdk-core/tests/integ_tests/update_tests.rs +75 -6
  167. package/sdk-core/tests/integ_tests/worker_tests.rs +54 -5
  168. package/sdk-core/tests/integ_tests/worker_versioning_tests.rs +240 -0
  169. package/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +41 -3
  170. package/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +168 -8
  171. package/sdk-core/tests/integ_tests/workflow_tests/nexus.rs +285 -15
  172. package/sdk-core/tests/integ_tests/workflow_tests/priority.rs +12 -4
  173. package/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +3 -2
  174. package/sdk-core/tests/integ_tests/workflow_tests.rs +124 -74
  175. package/sdk-core/tests/main.rs +3 -51
  176. package/sdk-core/tests/manual_tests.rs +430 -0
  177. package/sdk-core/tests/runner.rs +28 -2
  178. package/src/client.rs +565 -0
  179. package/src/helpers/abort_controller.rs +204 -0
  180. package/src/helpers/callbacks.rs +299 -0
  181. package/src/helpers/errors.rs +302 -0
  182. package/src/helpers/future.rs +44 -0
  183. package/src/helpers/handles.rs +191 -0
  184. package/src/helpers/inspect.rs +18 -0
  185. package/src/helpers/json_string.rs +58 -0
  186. package/src/helpers/mod.rs +20 -0
  187. package/src/helpers/properties.rs +71 -0
  188. package/src/helpers/try_from_js.rs +213 -0
  189. package/src/helpers/try_into_js.rs +129 -0
  190. package/src/lib.rs +28 -40
  191. package/src/logs.rs +111 -0
  192. package/src/metrics.rs +325 -0
  193. package/src/runtime.rs +409 -498
  194. package/src/testing.rs +315 -57
  195. package/src/worker.rs +907 -378
  196. package/ts/errors.ts +57 -0
  197. package/ts/index.ts +10 -596
  198. package/ts/native.ts +496 -0
  199. package/lib/worker-tuner.d.ts +0 -167
  200. package/lib/worker-tuner.js.map +0 -1
  201. package/src/conversions/slot_supplier_bridge.rs +0 -291
  202. package/src/conversions.rs +0 -618
  203. package/src/errors.rs +0 -38
  204. package/src/helpers.rs +0 -297
  205. package/ts/worker-tuner.ts +0 -193
@@ -3,7 +3,7 @@ use crate::{
3
3
  abstractions::{MeteredPermitDealer, OwnedMeteredSemPermit, UsedMeteredSemPermit, dbg_panic},
4
4
  protosext::ValidScheduleLA,
5
5
  retry_logic::RetryPolicyExt,
6
- telemetry::metrics::{activity_type, workflow_type},
6
+ telemetry::metrics::{activity_type, should_record_failure_metric, workflow_type},
7
7
  worker::workflow::HeartbeatTimeoutMsg,
8
8
  };
9
9
  use futures_util::{
@@ -22,7 +22,7 @@ use temporal_sdk_core_protos::{
22
22
  coresdk::{
23
23
  LocalActivitySlotInfo,
24
24
  activity_result::{Cancellation, Failure as ActFail, Success},
25
- activity_task::{ActivityCancelReason, ActivityTask, Cancel, Start, activity_task},
25
+ activity_task::{ActivityCancelReason, ActivityTask, Start, activity_task},
26
26
  },
27
27
  temporal::api::{
28
28
  common::v1::WorkflowExecution,
@@ -255,6 +255,7 @@ impl LocalActivityManager {
255
255
  MetricsContext::no_op(),
256
256
  None,
257
257
  Arc::new(Default::default()),
258
+ None,
258
259
  ),
259
260
  hb_tx,
260
261
  MetricsContext::no_op(),
@@ -348,10 +349,10 @@ impl LocalActivityManager {
348
349
  LocalActRequest::Cancel(id) => {
349
350
  debug!(id=?id, "Cancelling local activity");
350
351
  let mut dlock = self.dat.lock();
351
- if let Some(lai) = dlock.la_info.get_mut(&id) {
352
- if let Some(immediate_res) = self.cancel_one_la(id.seq_num, lai) {
353
- immediate_resolutions.push(immediate_res);
354
- }
352
+ if let Some(lai) = dlock.la_info.get_mut(&id)
353
+ && let Some(immediate_res) = self.cancel_one_la(id.seq_num, lai)
354
+ {
355
+ immediate_resolutions.push(immediate_res);
355
356
  }
356
357
  }
357
358
  LocalActRequest::CancelAllInRun(run_id) => {
@@ -525,6 +526,7 @@ impl LocalActivityManager {
525
526
  .and_then(|t| t.try_into().ok()),
526
527
  heartbeat_timeout: None,
527
528
  retry_policy: Some(sa.retry_policy),
529
+ priority: Some(Default::default()),
528
530
  is_local: true,
529
531
  })),
530
532
  }))
@@ -549,11 +551,11 @@ impl LocalActivityManager {
549
551
  seq_num: info.la_info.schedule_cmd.seq,
550
552
  };
551
553
  let maybe_old_lai = dlock.la_info.remove(&exec_id);
552
- if let Some(ref oldlai) = maybe_old_lai {
553
- if let Some(ref bot) = oldlai.backing_off_task {
554
- dbg_panic!("Just-resolved LA should not have backoff task");
555
- bot.abort();
556
- }
554
+ if let Some(ref oldlai) = maybe_old_lai
555
+ && let Some(ref bot) = oldlai.backing_off_task
556
+ {
557
+ dbg_panic!("Just-resolved LA should not have backoff task");
558
+ bot.abort();
557
559
  }
558
560
 
559
561
  let la_metrics = self.metrics.with_new_attrs([
@@ -582,7 +584,9 @@ impl LocalActivityManager {
582
584
  la_metrics.la_exec_latency(runtime);
583
585
  let outcome = match &status {
584
586
  LocalActivityExecutionResult::Failed(fail) => {
585
- la_metrics.la_execution_failed();
587
+ if should_record_failure_metric(&fail.failure) {
588
+ la_metrics.la_execution_failed()
589
+ }
586
590
  Outcome::FailurePath {
587
591
  backoff: calc_backoff!(fail),
588
592
  }
@@ -626,12 +630,13 @@ impl LocalActivityManager {
626
630
  };
627
631
  // We want to generate a cancel task if the reason for failure was a timeout.
628
632
  let task = if is_timeout {
629
- Some(ActivityTask {
630
- task_token: task_token.clone().0,
631
- variant: Some(activity_task::Variant::Cancel(Cancel {
632
- reason: ActivityCancelReason::TimedOut as i32,
633
- })),
634
- })
633
+ Some(ActivityTask::cancel_from_ids(
634
+ task_token.clone().0,
635
+ ActivityCancelReason::TimedOut,
636
+ ActivityTask::primary_reason_to_cancellation_details(
637
+ ActivityCancelReason::TimedOut,
638
+ ),
639
+ ))
635
640
  } else {
636
641
  None
637
642
  };
@@ -783,12 +788,13 @@ impl LocalActivityManager {
783
788
  }
784
789
 
785
790
  self.cancels_req_tx
786
- .send(CancelOrTimeout::Cancel(ActivityTask {
787
- task_token: lai.task_token.0.clone(),
788
- variant: Some(activity_task::Variant::Cancel(Cancel {
789
- reason: ActivityCancelReason::Cancelled as i32,
790
- })),
791
- }))
791
+ .send(CancelOrTimeout::Cancel(ActivityTask::cancel_from_ids(
792
+ lai.task_token.0.clone(),
793
+ ActivityCancelReason::Cancelled,
794
+ ActivityTask::primary_reason_to_cancellation_details(
795
+ ActivityCancelReason::Cancelled,
796
+ ),
797
+ )))
792
798
  .expect("Receive half of LA cancel channel cannot be dropped");
793
799
  None
794
800
  }
@@ -887,6 +893,7 @@ impl TimeoutBag {
887
893
  /// as request to schedule it arrives.
888
894
  ///
889
895
  /// Returns error in the event the activity is *already* timed out
896
+ #[allow(clippy::result_large_err)]
890
897
  fn new(
891
898
  new_la: &NewLocalAct,
892
899
  cancel_chan: UnboundedSender<CancelOrTimeout>,
@@ -909,10 +916,10 @@ impl TimeoutBag {
909
916
  // Remove any time already elapsed since the scheduling time
910
917
  let schedule_to_close = schedule_to_close
911
918
  .map(|s2c| s2c.saturating_sub(sched_time.elapsed().unwrap_or_default()));
912
- if let Some(ref s2c) = schedule_to_close {
913
- if s2c.is_zero() {
914
- return Err(resolution);
915
- }
919
+ if let Some(ref s2c) = schedule_to_close
920
+ && s2c.is_zero()
921
+ {
922
+ return Err(resolution);
916
923
  }
917
924
  let timeout_dat = CancelOrTimeout::Timeout {
918
925
  run_id: new_la.workflow_exec_info.run_id.clone(),
@@ -13,7 +13,9 @@ use crate::{
13
13
  UsedMeteredSemPermit,
14
14
  },
15
15
  pollers::{BoxedActPoller, PermittedTqResp, TrackedPermittedTqResp, new_activity_task_poller},
16
- telemetry::metrics::{MetricsContext, activity_type, eager, workflow_type},
16
+ telemetry::metrics::{
17
+ MetricsContext, activity_type, eager, should_record_failure_metric, workflow_type,
18
+ },
17
19
  worker::{
18
20
  activities::activity_heartbeat_manager::ActivityHeartbeatError, client::WorkerClient,
19
21
  },
@@ -38,7 +40,7 @@ use temporal_sdk_core_protos::{
38
40
  coresdk::{
39
41
  ActivityHeartbeat, ActivitySlotInfo,
40
42
  activity_result::{self as ar, activity_execution_result as aer},
41
- activity_task::{ActivityCancelReason, ActivityTask},
43
+ activity_task::{ActivityCancelReason, ActivityCancellationDetails, ActivityTask},
42
44
  },
43
45
  temporal::api::{
44
46
  failure::v1::{ApplicationFailureInfo, CanceledFailureInfo, Failure, failure::FailureInfo},
@@ -63,16 +65,19 @@ type OutstandingActMap = Arc<DashMap<TaskToken, RemoteInFlightActInfo>>;
63
65
  struct PendingActivityCancel {
64
66
  task_token: TaskToken,
65
67
  reason: ActivityCancelReason,
66
- /// Set true if we should assume the server has already forgotten about this activity
67
- consider_not_found: bool,
68
+ details: ActivityCancellationDetails,
68
69
  }
69
70
 
70
71
  impl PendingActivityCancel {
71
- fn new(task_token: TaskToken, reason: ActivityCancelReason) -> Self {
72
+ fn new(
73
+ task_token: TaskToken,
74
+ reason: ActivityCancelReason,
75
+ details: ActivityCancellationDetails,
76
+ ) -> Self {
72
77
  Self {
73
78
  task_token,
74
79
  reason,
75
- consider_not_found: false,
80
+ details,
76
81
  }
77
82
  }
78
83
  }
@@ -170,7 +175,7 @@ pub(crate) struct WorkerActivityTasks {
170
175
  #[derive(derive_more::From)]
171
176
  enum ActivityTaskSource {
172
177
  PendingCancel(PendingActivityCancel),
173
- PendingStart(Result<(PermittedTqResp<PollActivityTaskQueueResponse>, bool), PollError>),
178
+ PendingStart(Box<Result<(PermittedTqResp<PollActivityTaskQueueResponse>, bool), PollError>>),
174
179
  }
175
180
 
176
181
  impl WorkerActivityTasks {
@@ -204,7 +209,7 @@ impl WorkerActivityTasks {
204
209
  let complete_notify = Arc::new(Notify::new());
205
210
  let source_stream = stream::select_with_strategy(
206
211
  UnboundedReceiverStream::new(cancels_rx).map(ActivityTaskSource::from),
207
- starts_stream.map(ActivityTaskSource::from),
212
+ starts_stream.map(|a| ActivityTaskSource::from(Box::new(a))),
208
213
  |_: &mut ()| PollNext::Left,
209
214
  );
210
215
 
@@ -349,7 +354,9 @@ impl WorkerActivityTasks {
349
354
  .err()
350
355
  }
351
356
  aer::Status::Failed(ar::Failure { failure }) => {
352
- act_metrics.act_execution_failed();
357
+ if should_record_failure_metric(&failure) {
358
+ act_metrics.act_execution_failed();
359
+ }
353
360
  client
354
361
  .fail_activity_task(task_token.clone(), failure)
355
362
  .await
@@ -455,7 +462,7 @@ impl WorkerActivityTasks {
455
462
  }
456
463
 
457
464
  #[cfg(test)]
458
- pub(crate) fn remaining_activity_capacity(&self) -> Option<usize> {
465
+ pub(crate) fn unused_permits(&self) -> Option<usize> {
459
466
  self.eager_activities_semaphore.unused_permits()
460
467
  }
461
468
  }
@@ -504,13 +511,14 @@ where
504
511
  } else {
505
512
  details.issued_cancel_to_lang = Some(next_pc.reason);
506
513
  if next_pc.reason == ActivityCancelReason::NotFound
507
- || next_pc.consider_not_found
514
+ || next_pc.details.is_not_found
508
515
  {
509
516
  details.known_not_found = true;
510
517
  }
511
518
  Some(Ok(ActivityTask::cancel_from_ids(
512
519
  next_pc.task_token.0,
513
520
  next_pc.reason,
521
+ next_pc.details,
514
522
  )))
515
523
  }
516
524
  } else {
@@ -562,6 +570,9 @@ where
562
570
  let _ = cancels_tx.send(PendingActivityCancel::new(
563
571
  tt,
564
572
  ActivityCancelReason::WorkerShutdown,
573
+ ActivityTask::primary_reason_to_cancellation_details(
574
+ ActivityCancelReason::WorkerShutdown,
575
+ ),
565
576
  ));
566
577
  } else {
567
578
  // Fire off task to keep track of local timeouts. We do this so that
@@ -607,11 +618,15 @@ where
607
618
  "Timing out activity due to elapsed local \
608
619
  {timeout_type} timer"
609
620
  );
610
- let _ = cancel_tx.send(PendingActivityCancel {
611
- task_token: tt,
612
- reason: ActivityCancelReason::TimedOut,
613
- consider_not_found: true,
614
- });
621
+ let _ = cancel_tx.send(PendingActivityCancel::new(
622
+ tt,
623
+ ActivityCancelReason::TimedOut,
624
+ ActivityCancellationDetails {
625
+ is_not_found: true,
626
+ is_timed_out: true,
627
+ ..Default::default()
628
+ },
629
+ ));
615
630
  }));
616
631
  outstanding_info.timeout_resetter = resetter;
617
632
  }
@@ -635,6 +650,9 @@ where
635
650
  let _ = self.cancels_tx.send(PendingActivityCancel::new(
636
651
  mapref.key().clone(),
637
652
  ActivityCancelReason::WorkerShutdown,
653
+ ActivityTask::primary_reason_to_cancellation_details(
654
+ ActivityCancelReason::WorkerShutdown,
655
+ ),
638
656
  ));
639
657
  }
640
658
  }
@@ -705,9 +723,12 @@ fn worker_shutdown_failure() -> Failure {
705
723
  mod tests {
706
724
  use super::*;
707
725
  use crate::{
708
- abstractions::tests::fixed_size_permit_dealer, pollers::new_activity_task_buffer,
709
- prost_dur, worker::client::mocks::mock_workflow_client,
726
+ abstractions::tests::fixed_size_permit_dealer,
727
+ pollers::{ActivityTaskOptions, LongPollBuffer},
728
+ prost_dur,
729
+ worker::client::mocks::mock_workflow_client,
710
730
  };
731
+ use temporal_sdk_core_api::worker::PollerBehavior;
711
732
  use temporal_sdk_core_protos::coresdk::activity_result::ActivityExecutionResult;
712
733
 
713
734
  #[tokio::test]
@@ -740,15 +761,18 @@ mod tests {
740
761
  let mock_client = Arc::new(mock_client);
741
762
  let sem = fixed_size_permit_dealer(10);
742
763
  let shutdown_token = CancellationToken::new();
743
- let ap = new_activity_task_buffer(
764
+ let ap = LongPollBuffer::new_activity_task(
744
765
  mock_client.clone(),
745
766
  "tq".to_string(),
746
- 5, // Lots of concurrent pollers, to ensure we don't poll to much when that's the case
767
+ // Lots of concurrent pollers, to ensure we don't poll to much when that's the case
768
+ PollerBehavior::SimpleMaximum(5),
747
769
  sem.clone(),
748
- None,
749
770
  shutdown_token.clone(),
750
771
  None::<fn(usize)>,
751
- Some(2.0),
772
+ ActivityTaskOptions {
773
+ max_worker_acts_per_second: Some(2.0),
774
+ max_tps: None,
775
+ },
752
776
  );
753
777
  let atm = WorkerActivityTasks::new(
754
778
  sem.clone(),
@@ -829,15 +853,17 @@ mod tests {
829
853
  let mock_client = Arc::new(mock_client);
830
854
  let sem = fixed_size_permit_dealer(1);
831
855
  let shutdown_token = CancellationToken::new();
832
- let ap = new_activity_task_buffer(
856
+ let ap = LongPollBuffer::new_activity_task(
833
857
  mock_client.clone(),
834
858
  "tq".to_string(),
835
- 1,
859
+ PollerBehavior::SimpleMaximum(1),
836
860
  sem.clone(),
837
- None,
838
861
  shutdown_token.clone(),
839
862
  None::<fn(usize)>,
840
- None,
863
+ ActivityTaskOptions {
864
+ max_worker_acts_per_second: None,
865
+ max_tps: None,
866
+ },
841
867
  );
842
868
  let atm = WorkerActivityTasks::new(
843
869
  sem.clone(),
@@ -900,15 +926,17 @@ mod tests {
900
926
  let mock_client = Arc::new(mock_client);
901
927
  let sem = fixed_size_permit_dealer(1);
902
928
  let shutdown_token = CancellationToken::new();
903
- let ap = new_activity_task_buffer(
929
+ let ap = LongPollBuffer::new_activity_task(
904
930
  mock_client.clone(),
905
931
  "tq".to_string(),
906
- 1,
932
+ PollerBehavior::SimpleMaximum(1),
907
933
  sem.clone(),
908
- None,
909
934
  shutdown_token.clone(),
910
935
  None::<fn(usize)>,
911
- None,
936
+ ActivityTaskOptions {
937
+ max_worker_acts_per_second: None,
938
+ max_tps: None,
939
+ },
912
940
  );
913
941
  let atm = WorkerActivityTasks::new(
914
942
  sem.clone(),
@@ -56,15 +56,15 @@ mockall::mock! {
56
56
  pub(crate) ManualWorkerClient {}
57
57
  #[allow(unused)]
58
58
  impl WorkerClient for ManualWorkerClient {
59
- fn poll_workflow_task<'a, 'b>(&'a self, task_queue: TaskQueue)
59
+ fn poll_workflow_task<'a, 'b>(&'a self, poll_options: PollOptions, wf_options: PollWorkflowOptions)
60
60
  -> impl Future<Output = Result<PollWorkflowTaskQueueResponse>> + Send + 'b
61
61
  where 'a: 'b, Self: 'b;
62
62
 
63
- fn poll_activity_task<'a, 'b>(&self, task_queue: String, max_tasks_per_sec: Option<f64>)
63
+ fn poll_activity_task<'a, 'b>(&self, poll_options: PollOptions, act_options: PollActivityOptions)
64
64
  -> impl Future<Output = Result<PollActivityTaskQueueResponse>> + Send + 'b
65
65
  where 'a: 'b, Self: 'b;
66
66
 
67
- fn poll_nexus_task<'a, 'b>(&self, task_queue: String)
67
+ fn poll_nexus_task<'a, 'b>(&self, poll_options: PollOptions)
68
68
  -> impl Future<Output = Result<PollNexusTaskQueueResponse>> + Send + 'b
69
69
  where 'a: 'b, Self: 'b;
70
70