@temporalio/core-bridge 1.6.0 → 1.7.1

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 (138) hide show
  1. package/Cargo.lock +520 -456
  2. package/lib/index.d.ts +8 -6
  3. package/lib/index.js.map +1 -1
  4. package/package.json +8 -3
  5. package/releases/aarch64-apple-darwin/index.node +0 -0
  6. package/releases/aarch64-unknown-linux-gnu/index.node +0 -0
  7. package/releases/x86_64-apple-darwin/index.node +0 -0
  8. package/releases/x86_64-pc-windows-msvc/index.node +0 -0
  9. package/releases/x86_64-unknown-linux-gnu/index.node +0 -0
  10. package/sdk-core/.buildkite/docker/Dockerfile +2 -2
  11. package/sdk-core/.buildkite/docker/docker-compose.yaml +1 -1
  12. package/sdk-core/.buildkite/pipeline.yml +1 -1
  13. package/sdk-core/.github/workflows/heavy.yml +1 -0
  14. package/sdk-core/README.md +13 -7
  15. package/sdk-core/client/src/lib.rs +27 -9
  16. package/sdk-core/client/src/metrics.rs +17 -8
  17. package/sdk-core/client/src/raw.rs +3 -3
  18. package/sdk-core/core/Cargo.toml +3 -4
  19. package/sdk-core/core/src/abstractions/take_cell.rs +28 -0
  20. package/sdk-core/core/src/abstractions.rs +197 -18
  21. package/sdk-core/core/src/core_tests/activity_tasks.rs +137 -45
  22. package/sdk-core/core/src/core_tests/child_workflows.rs +6 -5
  23. package/sdk-core/core/src/core_tests/determinism.rs +212 -2
  24. package/sdk-core/core/src/core_tests/local_activities.rs +183 -36
  25. package/sdk-core/core/src/core_tests/queries.rs +32 -14
  26. package/sdk-core/core/src/core_tests/workers.rs +8 -5
  27. package/sdk-core/core/src/core_tests/workflow_tasks.rs +340 -51
  28. package/sdk-core/core/src/ephemeral_server/mod.rs +110 -8
  29. package/sdk-core/core/src/internal_flags.rs +141 -0
  30. package/sdk-core/core/src/lib.rs +14 -9
  31. package/sdk-core/core/src/replay/mod.rs +16 -27
  32. package/sdk-core/core/src/telemetry/metrics.rs +69 -35
  33. package/sdk-core/core/src/telemetry/mod.rs +38 -14
  34. package/sdk-core/core/src/telemetry/prometheus_server.rs +19 -13
  35. package/sdk-core/core/src/test_help/mod.rs +65 -13
  36. package/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +119 -160
  37. package/sdk-core/core/src/worker/activities/activity_task_poller_stream.rs +89 -0
  38. package/sdk-core/core/src/worker/activities/local_activities.rs +122 -6
  39. package/sdk-core/core/src/worker/activities.rs +347 -173
  40. package/sdk-core/core/src/worker/client/mocks.rs +22 -2
  41. package/sdk-core/core/src/worker/client.rs +18 -2
  42. package/sdk-core/core/src/worker/mod.rs +137 -44
  43. package/sdk-core/core/src/worker/workflow/history_update.rs +132 -51
  44. package/sdk-core/core/src/worker/workflow/machines/activity_state_machine.rs +207 -166
  45. package/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +6 -7
  46. package/sdk-core/core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +6 -7
  47. package/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +157 -82
  48. package/sdk-core/core/src/worker/workflow/machines/complete_workflow_state_machine.rs +12 -12
  49. package/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +6 -7
  50. package/sdk-core/core/src/worker/workflow/machines/fail_workflow_state_machine.rs +13 -15
  51. package/sdk-core/core/src/worker/workflow/machines/local_activity_state_machine.rs +170 -60
  52. package/sdk-core/core/src/worker/workflow/machines/mod.rs +24 -16
  53. package/sdk-core/core/src/worker/workflow/machines/modify_workflow_properties_state_machine.rs +6 -8
  54. package/sdk-core/core/src/worker/workflow/machines/patch_state_machine.rs +320 -204
  55. package/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +10 -13
  56. package/sdk-core/core/src/worker/workflow/machines/timer_state_machine.rs +15 -23
  57. package/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +187 -46
  58. package/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +237 -111
  59. package/sdk-core/core/src/worker/workflow/machines/workflow_task_state_machine.rs +13 -13
  60. package/sdk-core/core/src/worker/workflow/managed_run/managed_wf_test.rs +10 -6
  61. package/sdk-core/core/src/worker/workflow/managed_run.rs +81 -62
  62. package/sdk-core/core/src/worker/workflow/mod.rs +341 -79
  63. package/sdk-core/core/src/worker/workflow/run_cache.rs +18 -11
  64. package/sdk-core/core/src/worker/workflow/wft_extraction.rs +15 -3
  65. package/sdk-core/core/src/worker/workflow/workflow_stream/saved_wf_inputs.rs +2 -0
  66. package/sdk-core/core/src/worker/workflow/workflow_stream.rs +75 -52
  67. package/sdk-core/core-api/Cargo.toml +0 -1
  68. package/sdk-core/core-api/src/lib.rs +13 -7
  69. package/sdk-core/core-api/src/telemetry.rs +4 -6
  70. package/sdk-core/core-api/src/worker.rs +5 -0
  71. package/sdk-core/fsm/rustfsm_procmacro/src/lib.rs +80 -55
  72. package/sdk-core/fsm/rustfsm_trait/src/lib.rs +22 -68
  73. package/sdk-core/histories/ends_empty_wft_complete.bin +0 -0
  74. package/sdk-core/histories/old_change_marker_format.bin +0 -0
  75. package/sdk-core/protos/api_upstream/.github/CODEOWNERS +2 -1
  76. package/sdk-core/protos/api_upstream/Makefile +1 -1
  77. package/sdk-core/protos/api_upstream/temporal/api/command/v1/message.proto +5 -17
  78. package/sdk-core/protos/api_upstream/temporal/api/common/v1/message.proto +11 -0
  79. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/command_type.proto +1 -6
  80. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/event_type.proto +6 -6
  81. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +5 -0
  82. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/update.proto +22 -6
  83. package/sdk-core/protos/api_upstream/temporal/api/history/v1/message.proto +48 -19
  84. package/sdk-core/protos/api_upstream/temporal/api/namespace/v1/message.proto +2 -0
  85. package/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +3 -0
  86. package/sdk-core/protos/api_upstream/temporal/api/{enums/v1/interaction_type.proto → protocol/v1/message.proto} +29 -11
  87. package/sdk-core/protos/api_upstream/temporal/api/sdk/v1/task_complete_metadata.proto +63 -0
  88. package/sdk-core/protos/api_upstream/temporal/api/update/v1/message.proto +111 -0
  89. package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +59 -28
  90. package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +2 -2
  91. package/sdk-core/protos/local/temporal/sdk/core/activity_result/activity_result.proto +7 -8
  92. package/sdk-core/protos/local/temporal/sdk/core/activity_task/activity_task.proto +10 -7
  93. package/sdk-core/protos/local/temporal/sdk/core/child_workflow/child_workflow.proto +19 -30
  94. package/sdk-core/protos/local/temporal/sdk/core/common/common.proto +1 -0
  95. package/sdk-core/protos/local/temporal/sdk/core/core_interface.proto +1 -0
  96. package/sdk-core/protos/local/temporal/sdk/core/external_data/external_data.proto +8 -0
  97. package/sdk-core/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +65 -60
  98. package/sdk-core/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +85 -84
  99. package/sdk-core/protos/local/temporal/sdk/core/workflow_completion/workflow_completion.proto +9 -3
  100. package/sdk-core/sdk/Cargo.toml +1 -1
  101. package/sdk-core/sdk/src/lib.rs +21 -5
  102. package/sdk-core/sdk/src/workflow_context/options.rs +7 -1
  103. package/sdk-core/sdk/src/workflow_context.rs +24 -17
  104. package/sdk-core/sdk/src/workflow_future.rs +9 -3
  105. package/sdk-core/sdk-core-protos/src/history_builder.rs +114 -89
  106. package/sdk-core/sdk-core-protos/src/history_info.rs +6 -1
  107. package/sdk-core/sdk-core-protos/src/lib.rs +205 -64
  108. package/sdk-core/test-utils/src/canned_histories.rs +106 -296
  109. package/sdk-core/test-utils/src/lib.rs +32 -5
  110. package/sdk-core/tests/heavy_tests.rs +10 -43
  111. package/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +25 -3
  112. package/sdk-core/tests/integ_tests/heartbeat_tests.rs +5 -3
  113. package/sdk-core/tests/integ_tests/metrics_tests.rs +218 -16
  114. package/sdk-core/tests/integ_tests/polling_tests.rs +3 -8
  115. package/sdk-core/tests/integ_tests/queries_tests.rs +4 -2
  116. package/sdk-core/tests/integ_tests/visibility_tests.rs +34 -23
  117. package/sdk-core/tests/integ_tests/workflow_tests/activities.rs +97 -81
  118. package/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +1 -0
  119. package/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +1 -0
  120. package/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +80 -3
  121. package/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +5 -1
  122. package/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +1 -0
  123. package/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +25 -3
  124. package/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +2 -4
  125. package/sdk-core/tests/integ_tests/workflow_tests/patches.rs +30 -0
  126. package/sdk-core/tests/integ_tests/workflow_tests/replay.rs +64 -0
  127. package/sdk-core/tests/integ_tests/workflow_tests/resets.rs +1 -0
  128. package/sdk-core/tests/integ_tests/workflow_tests/signals.rs +4 -0
  129. package/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +3 -1
  130. package/sdk-core/tests/integ_tests/workflow_tests/timers.rs +7 -2
  131. package/sdk-core/tests/integ_tests/workflow_tests/upsert_search_attrs.rs +6 -7
  132. package/sdk-core/tests/integ_tests/workflow_tests.rs +8 -8
  133. package/sdk-core/tests/main.rs +16 -25
  134. package/sdk-core/tests/runner.rs +11 -9
  135. package/src/conversions.rs +14 -8
  136. package/src/runtime.rs +9 -8
  137. package/ts/index.ts +8 -6
  138. package/sdk-core/protos/api_upstream/temporal/api/interaction/v1/message.proto +0 -87
@@ -3,7 +3,8 @@
3
3
  use super::{
4
4
  workflow_machines::MachineResponse, Cancellable, EventInfo, WFMachinesAdapter, WFMachinesError,
5
5
  };
6
- use rustfsm::{fsm, TransitionResult};
6
+ use crate::worker::workflow::machines::HistEventData;
7
+ use rustfsm::{fsm, StateMachine, TransitionResult};
7
8
  use std::{
8
9
  convert::{TryFrom, TryInto},
9
10
  time::SystemTime,
@@ -31,12 +32,12 @@ fsm! {
31
32
 
32
33
  impl WorkflowTaskMachine {
33
34
  pub(super) fn new(wf_task_started_event_id: i64) -> Self {
34
- Self {
35
- state: Created {}.into(),
36
- shared_state: SharedState {
35
+ Self::from_parts(
36
+ Created {}.into(),
37
+ SharedState {
37
38
  wf_task_started_event_id,
38
39
  },
39
- }
40
+ )
40
41
  }
41
42
  }
42
43
 
@@ -63,8 +64,8 @@ impl WFMachinesAdapter for WorkflowTaskMachine {
63
64
  task_started_event_id,
64
65
  time,
65
66
  } => {
66
- let (event_id, event_type, has_next_event) = if let Some(ei) = event_info {
67
- (ei.event_id, ei.event_type, ei.has_next_event)
67
+ let (event_id, event_type) = if let Some(ei) = event_info {
68
+ (ei.event_id, ei.event_type)
68
69
  } else {
69
70
  return Err(WFMachinesError::Fatal(
70
71
  "WF Task machine should never issue a task started trigger \
@@ -74,9 +75,7 @@ impl WFMachinesAdapter for WorkflowTaskMachine {
74
75
  };
75
76
 
76
77
  let cur_event_past_or_at_start = event_id >= task_started_event_id;
77
- if event_type == EventType::WorkflowTaskStarted
78
- && (!cur_event_past_or_at_start || has_next_event)
79
- {
78
+ if event_type == EventType::WorkflowTaskStarted && !cur_event_past_or_at_start {
80
79
  return Ok(vec![]);
81
80
  }
82
81
  Ok(vec![MachineResponse::TriggerWFTaskStarted {
@@ -102,10 +101,11 @@ impl WFMachinesAdapter for WorkflowTaskMachine {
102
101
  }
103
102
  }
104
103
 
105
- impl TryFrom<HistoryEvent> for WorkflowTaskMachineEvents {
104
+ impl TryFrom<HistEventData> for WorkflowTaskMachineEvents {
106
105
  type Error = WFMachinesError;
107
106
 
108
- fn try_from(e: HistoryEvent) -> Result<Self, Self::Error> {
107
+ fn try_from(e: HistEventData) -> Result<Self, Self::Error> {
108
+ let e = e.event;
109
109
  Ok(match e.event_type() {
110
110
  EventType::WorkflowTaskScheduled => Self::WorkflowTaskScheduled,
111
111
  EventType::WorkflowTaskStarted => Self::WorkflowTaskStarted({
@@ -201,7 +201,7 @@ pub(super) struct WFTFailedDat {
201
201
  impl Scheduled {
202
202
  pub(super) fn on_workflow_task_started(
203
203
  self,
204
- shared: SharedState,
204
+ shared: &mut SharedState,
205
205
  WFTStartedDat {
206
206
  current_time_millis,
207
207
  started_event_id,
@@ -3,6 +3,7 @@ use crate::{
3
3
  replay::TestHistoryBuilder,
4
4
  test_help::TEST_Q,
5
5
  worker::{
6
+ client::mocks::DEFAULT_TEST_CAPABILITIES,
6
7
  workflow::{
7
8
  history_update::tests::TestHBExt, machines::WorkflowMachines, WFCommand,
8
9
  WorkflowFetcher,
@@ -87,13 +88,16 @@ impl ManagedWFFunc {
87
88
  completions_q: completions_sync_rx,
88
89
  };
89
90
  let state_machines = WorkflowMachines::new(
90
- "test_namespace".to_string(),
91
- "wfid".to_string(),
92
- "wftype".to_string(),
93
- "runid".to_string(),
94
- hist,
91
+ RunBasics {
92
+ namespace: "test_namespace".to_string(),
93
+ workflow_id: "wfid".to_string(),
94
+ workflow_type: "wftype".to_string(),
95
+ run_id: "runid".to_string(),
96
+ history: hist,
97
+ metrics: MetricsContext::no_op(),
98
+ capabilities: &DEFAULT_TEST_CAPABILITIES,
99
+ },
95
100
  Box::new(driver).into(),
96
- MetricsContext::no_op(),
97
101
  );
98
102
  let mgr = WorkflowManager::new_from_machines(state_machines);
99
103
  Self {
@@ -13,7 +13,7 @@ use crate::{
13
13
  ActivationCompleteOutcome, ActivationCompleteResult, ActivationOrAuto,
14
14
  EvictionRequestResult, FailedActivationWFTReport, HeartbeatTimeoutMsg, HistoryUpdate,
15
15
  LocalActivityRequestSink, LocalResolution, NextPageReq, OutgoingServerCommands,
16
- OutstandingActivation, OutstandingTask, PermittedWFT, RequestEvictMsg,
16
+ OutstandingActivation, OutstandingTask, PermittedWFT, RequestEvictMsg, RunBasics,
17
17
  ServerCommandsWithWorkflowInfo, WFCommand, WFMachinesError, WFTReportStatus,
18
18
  WorkflowBridge, WorkflowTaskInfo, WFT_HEARTBEAT_TIMEOUT_FRACTION,
19
19
  },
@@ -25,7 +25,8 @@ use futures_util::future::AbortHandle;
25
25
  use std::{
26
26
  collections::HashSet,
27
27
  ops::Add,
28
- sync::{mpsc::Sender, Arc},
28
+ rc::Rc,
29
+ sync::mpsc::Sender,
29
30
  time::{Duration, Instant},
30
31
  };
31
32
  use temporal_sdk_core_protos::{
@@ -65,7 +66,7 @@ pub(super) struct ManagedRun {
65
66
  /// pushing things out and then directly back in. The downside is this is the only "impure" part
66
67
  /// of the in/out nature of workflow state management. If there's ever a sensible way to lift it
67
68
  /// up, that'd be nice.
68
- local_activity_request_sink: Arc<dyn LocalActivityRequestSink>,
69
+ local_activity_request_sink: Rc<dyn LocalActivityRequestSink>,
69
70
  /// Set if the run is currently waiting on the execution of some local activities.
70
71
  waiting_on_la: Option<WaitingOnLAs>,
71
72
  /// Is set to true if the machines encounter an error and the only subsequent thing we should
@@ -93,24 +94,12 @@ pub(super) struct ManagedRun {
93
94
  completion_waiting_on_page_fetch: Option<RunActivationCompletion>,
94
95
  }
95
96
  impl ManagedRun {
96
- #[allow(clippy::too_many_arguments)] // Ok with this here. Nothing reusable to extract.
97
97
  pub(super) fn new(
98
- history_update: HistoryUpdate,
99
- namespace: String,
100
- workflow_id: String,
101
- workflow_type: String,
102
- run_id: String,
103
- local_activity_request_sink: Arc<dyn LocalActivityRequestSink>,
104
- metrics: MetricsContext,
98
+ basics: RunBasics,
99
+ local_activity_request_sink: Rc<dyn LocalActivityRequestSink>,
105
100
  ) -> Self {
106
- let wfm = WorkflowManager::new(
107
- history_update,
108
- namespace,
109
- workflow_id,
110
- workflow_type,
111
- run_id,
112
- metrics.clone(),
113
- );
101
+ let metrics = basics.metrics.clone();
102
+ let wfm = WorkflowManager::new(basics);
114
103
  Self {
115
104
  wfm,
116
105
  local_activity_request_sink,
@@ -283,6 +272,10 @@ impl ManagedRun {
283
272
  if let Some(ot) = &retme {
284
273
  self.metrics.wf_task_latency(ot.start_time.elapsed());
285
274
  }
275
+ // Tell the LA manager that we're done with the WFT
276
+ self.local_activity_request_sink.sink_reqs(vec![
277
+ LocalActRequest::IndicateWorkflowTaskCompleted(self.wfm.machines.run_id.clone()),
278
+ ]);
286
279
  }
287
280
 
288
281
  retme
@@ -354,6 +347,7 @@ impl ManagedRun {
354
347
  pub(super) fn successful_completion(
355
348
  &mut self,
356
349
  mut commands: Vec<WFCommand>,
350
+ used_flags: Vec<u32>,
357
351
  resp_chan: Option<oneshot::Sender<ActivationCompleteResult>>,
358
352
  ) -> Result<RunUpdateAct, NextPageReq> {
359
353
  let activation_was_only_eviction = self.activation_has_only_eviction();
@@ -372,7 +366,20 @@ impl ManagedRun {
372
366
  self.run_id()
373
367
  );
374
368
  }
375
- self.reply_to_complete(ActivationCompleteOutcome::DoNothing, resp_chan);
369
+ let outcome = if let Some((tt, reason)) = self.trying_to_evict.as_mut().and_then(|te| {
370
+ te.auto_reply_fail_tt
371
+ .take()
372
+ .map(|tt| (tt, te.message.clone()))
373
+ }) {
374
+ ActivationCompleteOutcome::ReportWFTFail(FailedActivationWFTReport::Report(
375
+ tt,
376
+ WorkflowTaskFailedCause::Unspecified,
377
+ Failure::application_failure(reason, true).into(),
378
+ ))
379
+ } else {
380
+ ActivationCompleteOutcome::DoNothing
381
+ };
382
+ self.reply_to_complete(outcome, resp_chan);
376
383
  return Ok(None);
377
384
  };
378
385
 
@@ -422,6 +429,7 @@ impl ManagedRun {
422
429
  activation_was_only_eviction,
423
430
  has_pending_query,
424
431
  query_responses,
432
+ used_flags,
425
433
  resp_chan,
426
434
  };
427
435
 
@@ -516,6 +524,7 @@ impl ManagedRun {
516
524
  run_id: self.run_id().to_string(),
517
525
  message,
518
526
  reason,
527
+ auto_reply_fail_tt: None,
519
528
  });
520
529
  let should_report = match &evict_req_outcome {
521
530
  EvictionRequestResult::EvictionRequested(Some(attempt), _)
@@ -541,8 +550,15 @@ impl ManagedRun {
541
550
 
542
551
  /// Delete the currently tracked workflow activation and return it, if any. Should be called
543
552
  /// after the processing of the activation completion, and WFT reporting.
544
- pub(super) fn delete_activation(&mut self) -> Option<OutstandingActivation> {
545
- self.activation.take()
553
+ pub(super) fn delete_activation(
554
+ &mut self,
555
+ pred: impl FnOnce(&OutstandingActivation) -> bool,
556
+ ) -> Option<OutstandingActivation> {
557
+ if self.activation().map(pred).unwrap_or_default() {
558
+ self.activation.take()
559
+ } else {
560
+ None
561
+ }
546
562
  }
547
563
 
548
564
  /// Called when local activities resolve
@@ -568,6 +584,8 @@ impl ManagedRun {
568
584
  activation_was_only_eviction: completion.activation_was_only_eviction,
569
585
  };
570
586
 
587
+ self.wfm.machines.add_lang_used_flags(completion.used_flags);
588
+
571
589
  // If this is just bookkeeping after a reply to an only-eviction activation, we can bypass
572
590
  // everything, since there is no reason to continue trying to update machines.
573
591
  if completion.activation_was_only_eviction {
@@ -688,9 +706,6 @@ impl ManagedRun {
688
706
  // Auto-reply WFT complete
689
707
  return true;
690
708
  }
691
- } else {
692
- // If a heartbeat timeout happened, we should always have been waiting on LAs
693
- dbg_panic!("WFT heartbeat timeout fired but we were not waiting on any LAs");
694
709
  }
695
710
  false
696
711
  }
@@ -776,6 +791,8 @@ impl ManagedRun {
776
791
  self.trying_to_evict = Some(info);
777
792
  EvictionRequestResult::EvictionRequested(attempts, self.check_more_activations())
778
793
  } else {
794
+ // Always store the most recent eviction reason
795
+ self.trying_to_evict = Some(info);
779
796
  EvictionRequestResult::EvictionAlreadyRequested(attempts)
780
797
  }
781
798
  }
@@ -844,7 +861,9 @@ impl ManagedRun {
844
861
  None
845
862
  }
846
863
  }
847
- a @ Some(ActivationOrAuto::Autocomplete { .. }) => a,
864
+ a @ Some(
865
+ ActivationOrAuto::Autocomplete { .. } | ActivationOrAuto::AutoFail { .. },
866
+ ) => a,
848
867
  None => {
849
868
  if let Some(reason) = self.trying_to_evict.as_ref() {
850
869
  // If we had nothing to do, but we're trying to evict, just do that now
@@ -906,12 +925,10 @@ impl ManagedRun {
906
925
  )
907
926
  } else {
908
927
  warn!(error=?fail.source, "Error while updating workflow");
909
- self.request_eviction(RequestEvictMsg {
910
- run_id: self.run_id().to_string(),
911
- message: format!("Error while updating workflow: {:?}", fail.source),
912
- reason: fail.source.evict_reason(),
928
+ Some(ActivationOrAuto::AutoFail {
929
+ run_id: self.run_id().to_owned(),
930
+ machines_err: fail.source,
913
931
  })
914
- .into_run_update_resp()
915
932
  };
916
933
  rur
917
934
  }
@@ -919,6 +936,7 @@ impl ManagedRun {
919
936
  }
920
937
 
921
938
  fn insert_outstanding_activation(&mut self, act: &ActivationOrAuto) {
939
+ warn!("Inserting {:?}", act);
922
940
  let act_type = match &act {
923
941
  ActivationOrAuto::LangActivation(act) | ActivationOrAuto::ReadyForQueries(act) => {
924
942
  if act.is_legacy_query() {
@@ -930,7 +948,9 @@ impl ManagedRun {
930
948
  }
931
949
  }
932
950
  }
933
- ActivationOrAuto::Autocomplete { .. } => OutstandingActivation::Autocomplete,
951
+ ActivationOrAuto::Autocomplete { .. } | ActivationOrAuto::AutoFail { .. } => {
952
+ OutstandingActivation::Autocomplete
953
+ }
934
954
  };
935
955
  if let Some(old_act) = self.activation {
936
956
  // This is a panic because we have screwed up core logic if this is violated. It must be
@@ -949,12 +969,18 @@ impl ManagedRun {
949
969
  data: CompletionDataForWFT,
950
970
  due_to_heartbeat_timeout: bool,
951
971
  ) -> FulfillableActivationComplete {
952
- let outgoing_cmds = self.wfm.get_server_commands();
972
+ let mut outgoing_cmds = self.wfm.get_server_commands();
953
973
  if data.activation_was_only_eviction && !outgoing_cmds.commands.is_empty() {
954
- dbg_panic!(
974
+ if self.am_broken {
975
+ // If we broke there could be commands in the pipe that we didn't get a chance to
976
+ // handle properly during replay, just wipe them all out.
977
+ outgoing_cmds.commands = vec![];
978
+ } else {
979
+ dbg_panic!(
955
980
  "There should not be any outgoing commands when preparing a completion response \
956
981
  if the activation was only an eviction. This is an SDK bug."
957
- );
982
+ );
983
+ }
958
984
  }
959
985
 
960
986
  let query_responses = data.query_responses;
@@ -970,7 +996,8 @@ impl ManagedRun {
970
996
  let should_respond = !(self.wfm.machines.has_pending_jobs()
971
997
  || outgoing_cmds.replaying
972
998
  || is_query_playback
973
- || data.activation_was_only_eviction);
999
+ || data.activation_was_only_eviction
1000
+ || self.wfm.machines.have_seen_terminal_event);
974
1001
  // If there are pending LA resolutions, and we're responding to a query here,
975
1002
  // we want to make sure to force a new task, as otherwise once we tell lang about
976
1003
  // the LA resolution there wouldn't be any task to reply to with the result of iterating
@@ -986,16 +1013,14 @@ impl ManagedRun {
986
1013
  force_new_wft,
987
1014
  commands: outgoing_cmds.commands,
988
1015
  query_responses,
1016
+ sdk_metadata: self.wfm.machines.get_metadata_for_wft_complete(),
989
1017
  },
990
1018
  })
991
1019
  } else {
992
1020
  ActivationCompleteOutcome::DoNothing
993
1021
  };
994
1022
  FulfillableActivationComplete {
995
- result: ActivationCompleteResult {
996
- most_recently_processed_event: self.wfm.machines.last_processed_event as usize,
997
- outcome,
998
- },
1023
+ result: self.build_activation_complete_result(outcome),
999
1024
  resp_chan,
1000
1025
  }
1001
1026
  }
@@ -1023,11 +1048,19 @@ impl ManagedRun {
1023
1048
  chan: Option<oneshot::Sender<ActivationCompleteResult>>,
1024
1049
  ) {
1025
1050
  if let Some(chan) = chan {
1026
- chan.send(ActivationCompleteResult {
1027
- most_recently_processed_event: self.most_recently_processed_event_number() as usize,
1028
- outcome,
1029
- })
1030
- .expect("Rcv half of activation reply not dropped");
1051
+ chan.send(self.build_activation_complete_result(outcome))
1052
+ .expect("Rcv half of activation reply not dropped");
1053
+ }
1054
+ }
1055
+
1056
+ fn build_activation_complete_result(
1057
+ &self,
1058
+ outcome: ActivationCompleteOutcome,
1059
+ ) -> ActivationCompleteResult {
1060
+ ActivationCompleteResult {
1061
+ outcome,
1062
+ most_recently_processed_event: self.most_recently_processed_event_number() as usize,
1063
+ replaying: self.wfm.machines.replaying,
1031
1064
  }
1032
1065
  }
1033
1066
 
@@ -1139,24 +1172,9 @@ struct WorkflowManager {
1139
1172
  impl WorkflowManager {
1140
1173
  /// Create a new workflow manager given workflow history and execution info as would be found
1141
1174
  /// in [PollWorkflowTaskQueueResponse]
1142
- fn new(
1143
- history: HistoryUpdate,
1144
- namespace: String,
1145
- workflow_id: String,
1146
- workflow_type: String,
1147
- run_id: String,
1148
- metrics: MetricsContext,
1149
- ) -> Self {
1175
+ fn new(basics: RunBasics) -> Self {
1150
1176
  let (wfb, cmd_sink) = WorkflowBridge::new();
1151
- let state_machines = WorkflowMachines::new(
1152
- namespace,
1153
- workflow_id,
1154
- workflow_type,
1155
- run_id,
1156
- history,
1157
- Box::new(wfb).into(),
1158
- metrics,
1159
- );
1177
+ let state_machines = WorkflowMachines::new(basics, Box::new(wfb).into());
1160
1178
  Self {
1161
1179
  machines: state_machines,
1162
1180
  command_sink: Some(cmd_sink),
@@ -1289,6 +1307,7 @@ struct RunActivationCompletion {
1289
1307
  activation_was_only_eviction: bool,
1290
1308
  has_pending_query: bool,
1291
1309
  query_responses: Vec<QueryResult>,
1310
+ used_flags: Vec<u32>,
1292
1311
  /// Used to notify the worker when the completion is done processing and the completion can
1293
1312
  /// unblock. Must always be `Some` when initialized.
1294
1313
  resp_chan: Option<oneshot::Sender<ActivationCompleteResult>>,