@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
@@ -64,21 +64,21 @@ use syn::{
64
64
  /// }
65
65
  ///
66
66
  /// impl Locked {
67
- /// fn on_card_readable(&self, shared_dat: SharedState, data: CardData)
67
+ /// fn on_card_readable(&self, shared_dat: &mut SharedState, data: CardData)
68
68
  /// -> CardReaderTransition<ReadingCardOrLocked> {
69
- /// match shared_dat.last_id {
69
+ /// match &shared_dat.last_id {
70
70
  /// // Arbitrarily deny the same person entering twice in a row
71
- /// Some(d) if d == data => TransitionResult::ok(vec![], Locked {}.into()),
71
+ /// Some(d) if d == &data => TransitionResult::ok(vec![], Locked {}.into()),
72
72
  /// _ => {
73
73
  /// // Otherwise issue a processing command. This illustrates using the same handler
74
74
  /// // for different destinations
75
- /// TransitionResult::ok_shared(
75
+ /// shared_dat.last_id = Some(data.clone());
76
+ /// TransitionResult::ok(
76
77
  /// vec![
77
78
  /// Commands::ProcessData(data.clone()),
78
79
  /// Commands::StartBlinkingLight,
79
80
  /// ],
80
- /// ReadingCard { card_data: data.clone() }.into(),
81
- /// SharedState { last_id: Some(data) }
81
+ /// ReadingCard { card_data: data }.into(),
82
82
  /// )
83
83
  /// }
84
84
  /// }
@@ -96,19 +96,19 @@ use syn::{
96
96
  ///
97
97
  /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
98
98
  /// let crs = CardReaderState::Locked(Locked {});
99
- /// let mut cr = CardReader { state: crs, shared_state: SharedState { last_id: None } };
100
- /// let cmds = cr.on_event_mut(CardReaderEvents::CardReadable("badguy".to_string()))?;
99
+ /// let mut cr = CardReader::from_parts(crs, SharedState { last_id: None });
100
+ /// let cmds = cr.on_event(CardReaderEvents::CardReadable("badguy".to_string()))?;
101
101
  /// assert_eq!(cmds[0], Commands::ProcessData("badguy".to_string()));
102
102
  /// assert_eq!(cmds[1], Commands::StartBlinkingLight);
103
103
  ///
104
- /// let cmds = cr.on_event_mut(CardReaderEvents::CardRejected)?;
104
+ /// let cmds = cr.on_event(CardReaderEvents::CardRejected)?;
105
105
  /// assert_eq!(cmds[0], Commands::StopBlinkingLight);
106
106
  ///
107
- /// let cmds = cr.on_event_mut(CardReaderEvents::CardReadable("goodguy".to_string()))?;
107
+ /// let cmds = cr.on_event(CardReaderEvents::CardReadable("goodguy".to_string()))?;
108
108
  /// assert_eq!(cmds[0], Commands::ProcessData("goodguy".to_string()));
109
109
  /// assert_eq!(cmds[1], Commands::StartBlinkingLight);
110
110
  ///
111
- /// let cmds = cr.on_event_mut(CardReaderEvents::CardAccepted)?;
111
+ /// let cmds = cr.on_event(CardReaderEvents::CardAccepted)?;
112
112
  /// assert_eq!(cmds[0], Commands::StopBlinkingLight);
113
113
  /// # Ok(())
114
114
  /// # }
@@ -132,17 +132,17 @@ use syn::{
132
132
  /// The macro will generate a few things:
133
133
  /// * A struct for the overall state machine, named with the provided name. Here:
134
134
  /// ```text
135
- /// struct CardMachine {
136
- /// state: CardMachineState,
137
- /// shared_state: CardId,
135
+ /// struct CardReader {
136
+ /// state: CardReaderState,
137
+ /// shared_state: SharedState,
138
138
  /// }
139
139
  /// ```
140
140
  /// * An enum with a variant for each state, named with the provided name + "State".
141
141
  /// ```text
142
- /// enum CardMachineState {
142
+ /// enum CardReaderState {
143
143
  /// Locked(Locked),
144
144
  /// ReadingCard(ReadingCard),
145
- /// Unlocked(Unlocked),
145
+ /// DoorOpen(DoorOpen),
146
146
  /// }
147
147
  /// ```
148
148
  ///
@@ -154,15 +154,18 @@ use syn::{
154
154
  /// * An enum with a variant for each event. You are expected to define the type (if any) contained
155
155
  /// in the event variant.
156
156
  /// ```text
157
- /// enum CardMachineEvents {
158
- /// CardReadable(CardData)
157
+ /// enum CardReaderEvents {
158
+ /// DoorClosed,
159
+ /// CardAccepted,
160
+ /// CardRejected,
161
+ /// CardReadable(CardData),
159
162
  /// }
160
163
  /// ```
161
164
  /// * An implementation of the [StateMachine](trait.StateMachine.html) trait for the generated state
162
- /// machine enum (in this case, `CardMachine`)
165
+ /// machine enum (in this case, `CardReader`)
163
166
  /// * A type alias for a [TransitionResult](enum.TransitionResult.html) with the appropriate generic
164
167
  /// parameters set for your machine. It is named as your machine with `Transition` appended. In
165
- /// this case, `CardMachineTransition`.
168
+ /// this case, `CardReaderTransition`.
166
169
  #[proc_macro]
167
170
  pub fn fsm(input: TokenStream) -> TokenStream {
168
171
  let def: StateMachineDefinition = parse_macro_input!(input as StateMachineDefinition);
@@ -217,7 +220,7 @@ impl Parse for StateMachineDefinition {
217
220
  // not ideal.
218
221
  let trans_set: HashSet<_> = transitions.iter().collect();
219
222
  if trans_set.len() != transitions.len() {
220
- return Err(syn::Error::new(
223
+ return Err(Error::new(
221
224
  input.span(),
222
225
  "Duplicate transitions are not allowed!",
223
226
  ));
@@ -360,7 +363,7 @@ impl StateMachineDefinition {
360
363
  let machine_struct = quote! {
361
364
  #[derive(Clone)]
362
365
  #visibility struct #name {
363
- state: #state_enum_name,
366
+ state: ::core::option::Option<#state_enum_name>,
364
367
  shared_state: #shared_state_type
365
368
  }
366
369
  };
@@ -424,8 +427,18 @@ impl StateMachineDefinition {
424
427
  statemap.insert(s.clone(), vec![]);
425
428
  }
426
429
  }
430
+ let transition_result_transform = quote! {
431
+ match res.into_cmd_result() {
432
+ Ok((cmds, state)) => {
433
+ self.state = Some(state);
434
+ Ok(cmds)
435
+ }
436
+ Err(e) => Err(e)
437
+ }
438
+ };
427
439
  let mut multi_dest_enums = vec![];
428
440
  let state_branches: Vec<_> = statemap.into_iter().map(|(from, transitions)| {
441
+ let occupied_current_state = quote! { Some(#state_enum_name::#from(state_data)) };
429
442
  // Merge transition dest states with the same handler
430
443
  let transitions = merge_transition_dests(transitions);
431
444
  let event_branches = transitions
@@ -467,27 +480,27 @@ impl StateMachineDefinition {
467
480
  match ts.event.fields {
468
481
  Fields::Unnamed(_) => {
469
482
  let arglist = if ts.mutates_shared {
470
- quote! {self.shared_state, val}
483
+ quote! {&mut self.shared_state, val}
471
484
  } else {
472
485
  quote! {val}
473
486
  };
474
- quote_spanned! {span=>
487
+ quote_spanned! { span =>
475
488
  #events_enum_name::#ev_variant(val) => {
476
489
  let res: #trans_type = state_data.#ts_fn(#arglist);
477
- res.into_general()
490
+ #transition_result_transform
478
491
  }
479
492
  }
480
493
  }
481
494
  Fields::Unit => {
482
495
  let arglist = if ts.mutates_shared {
483
- quote! {self.shared_state}
496
+ quote! {&mut self.shared_state}
484
497
  } else {
485
498
  quote! {}
486
499
  };
487
- quote_spanned! {span=>
500
+ quote_spanned! { span =>
488
501
  #events_enum_name::#ev_variant => {
489
502
  let res: #trans_type = state_data.#ts_fn(#arglist);
490
- res.into_general()
503
+ #transition_result_transform
491
504
  }
492
505
  }
493
506
  }
@@ -498,39 +511,49 @@ impl StateMachineDefinition {
498
511
  // using `Default`.
499
512
  if let [new_state] = ts.to.as_slice() {
500
513
  let span = new_state.span();
501
- let default_trans = quote_spanned! {span=>
502
- TransitionResult::<_, #new_state>::from::<#from>(state_data).into_general()
503
- };
514
+ let default_trans = quote_spanned! { span =>
515
+ let res = TransitionResult::<Self, #new_state>::from::<#from>(state_data);
516
+ #transition_result_transform
517
+ };
504
518
  let span = ts.event.span();
505
519
  match ts.event.fields {
506
- Fields::Unnamed(_) => quote_spanned! {span=>
507
- #events_enum_name::#ev_variant(_val) => {
508
- #default_trans
509
- }
510
- },
511
- Fields::Unit => quote_spanned! {span=>
512
- #events_enum_name::#ev_variant => {
513
- #default_trans
514
- }
515
- },
520
+ Fields::Unnamed(_) => quote_spanned! { span =>
521
+ #events_enum_name::#ev_variant(_val) => {
522
+ #default_trans
523
+ }
524
+ },
525
+ Fields::Unit => quote_spanned! { span =>
526
+ #events_enum_name::#ev_variant => {
527
+ #default_trans
528
+ }
529
+ },
516
530
  Fields::Named(_) => unreachable!(),
517
531
  }
518
-
519
532
  } else {
520
- unreachable!("It should be impossible to have more than one dest state in no-handler transitions")
533
+ unreachable!("It should be impossible to have more than one dest state \
534
+ in no-handler transitions")
521
535
  }
522
536
  }
523
537
  })
524
- // Since most states won't handle every possible event, return an error to that effect
538
+ // Since most states won't handle every possible event, return an error to that
539
+ // effect
525
540
  .chain(std::iter::once(
526
- quote! { _ => { return TransitionResult::InvalidTransition } },
541
+ quote! { _ => {
542
+ // Restore state in event the transition doesn't match
543
+ self.state = #occupied_current_state;
544
+ return Err(::rustfsm::MachineError::InvalidTransition)
545
+ } },
527
546
  ));
528
547
  quote! {
529
- #state_enum_name::#from(state_data) => match event {
548
+ #occupied_current_state => match event {
530
549
  #(#event_branches),*
531
550
  }
532
551
  }
533
- }).collect();
552
+ }).chain(std::iter::once(
553
+ quote! {
554
+ None => Err(::rustfsm::MachineError::InvalidTransition)
555
+ }
556
+ )).collect();
534
557
 
535
558
  let viz_str = self.visualize();
536
559
 
@@ -546,19 +569,21 @@ impl StateMachineDefinition {
546
569
  #name_str
547
570
  }
548
571
 
549
- fn on_event(self, event: #events_enum_name)
550
- -> ::rustfsm::TransitionResult<Self, Self::State> {
551
- match self.state {
572
+ fn on_event(&mut self, event: #events_enum_name)
573
+ -> ::core::result::Result<::std::vec::Vec<Self::Command>,
574
+ ::rustfsm::MachineError<Self::Error>> {
575
+ let taken_state = self.state.take();
576
+ match taken_state {
552
577
  #(#state_branches),*
553
578
  }
554
579
  }
555
580
 
556
581
  fn state(&self) -> &Self::State {
557
- &self.state
582
+ self.state.as_ref().unwrap()
558
583
  }
559
584
 
560
585
  fn set_state(&mut self, new: Self::State) {
561
- self.state = new
586
+ self.state = Some(new)
562
587
  }
563
588
 
564
589
  fn shared_state(&self) -> &Self::SharedState{
@@ -566,11 +591,11 @@ impl StateMachineDefinition {
566
591
  }
567
592
 
568
593
  fn has_reached_final_state(&self) -> bool {
569
- self.state.is_final()
594
+ self.state.as_ref().unwrap().is_final()
570
595
  }
571
596
 
572
- fn from_parts(shared: Self::SharedState, state: Self::State) -> Self {
573
- Self { shared_state: shared, state }
597
+ fn from_parts(state: Self::State, shared: Self::SharedState) -> Self {
598
+ Self { shared_state: shared, state: Some(state) }
574
599
  }
575
600
 
576
601
  fn visualizer() -> &'static str {
@@ -19,44 +19,12 @@ pub trait StateMachine: Sized {
19
19
  /// The type used to represent commands the machine issues upon transitions.
20
20
  type Command;
21
21
 
22
- /// Handle an incoming event, returning a transition result which represents updates to apply
23
- /// to the state machine.
24
- fn on_event(self, event: Self::Event) -> TransitionResult<Self, Self::State>;
25
-
26
- /// Handle an incoming event and mutate the state machine to update to the new state and apply
27
- /// any changes to shared state.
28
- ///
29
- /// Returns the commands issued by the transition on success, otherwise a [MachineError]
30
- fn on_event_mut(
22
+ /// Handle an incoming event, returning any new commands or an error. Implementations may
23
+ /// mutate current state, possibly moving to a new state.
24
+ fn on_event(
31
25
  &mut self,
32
26
  event: Self::Event,
33
- ) -> Result<Vec<Self::Command>, MachineError<Self::Error>>
34
- where
35
- Self: Clone,
36
- {
37
- // NOTE: This clone is actually nice in some sense, giving us a kind of transactionality.
38
- // However if there are really big things in state it could be an issue.
39
- let res = self.clone().on_event(event);
40
- match res {
41
- TransitionResult::Ok {
42
- commands,
43
- new_state,
44
- shared_state,
45
- } => {
46
- *self = Self::from_parts(shared_state, new_state);
47
- Ok(commands)
48
- }
49
- TransitionResult::OkNoShare {
50
- commands,
51
- new_state,
52
- } => {
53
- self.set_state(new_state);
54
- Ok(commands)
55
- }
56
- TransitionResult::InvalidTransition => Err(MachineError::InvalidTransition),
57
- TransitionResult::Err(e) => Err(MachineError::Underlying(e)),
58
- }
59
- }
27
+ ) -> Result<Vec<Self::Command>, MachineError<Self::Error>>;
60
28
 
61
29
  fn name(&self) -> &str;
62
30
 
@@ -71,7 +39,7 @@ pub trait StateMachine: Sized {
71
39
  fn has_reached_final_state(&self) -> bool;
72
40
 
73
41
  /// Given the shared data and new state, create a new instance.
74
- fn from_parts(shared: Self::SharedState, state: Self::State) -> Self;
42
+ fn from_parts(state: Self::State, shared: Self::SharedState) -> Self;
75
43
 
76
44
  /// Return a PlantUML definition of the fsm that can be used to visualize it
77
45
  fn visualizer() -> &'static str;
@@ -136,12 +104,6 @@ where
136
104
  Ok {
137
105
  commands: Vec<Machine::Command>,
138
106
  new_state: DestinationState,
139
- shared_state: Machine::SharedState,
140
- },
141
- /// The transition was successful with no shared state change
142
- OkNoShare {
143
- commands: Vec<Machine::Command>,
144
- new_state: DestinationState,
145
107
  },
146
108
  /// There was some error performing the transition
147
109
  Err(Machine::Error),
@@ -157,24 +119,10 @@ where
157
119
  pub fn ok<CI>(commands: CI, new_state: Ds) -> Self
158
120
  where
159
121
  CI: IntoIterator<Item = Sm::Command>,
160
- {
161
- Self::OkNoShare {
162
- commands: commands.into_iter().collect(),
163
- new_state,
164
- }
165
- }
166
-
167
- /// Produce a transition with the provided commands to the provided state with shared state
168
- /// changes
169
- pub fn ok_shared<CI, SS>(commands: CI, new_state: Ds, new_shared: SS) -> Self
170
- where
171
- CI: IntoIterator<Item = Sm::Command>,
172
- SS: Into<Sm::SharedState>,
173
122
  {
174
123
  Self::Ok {
175
124
  commands: commands.into_iter().collect(),
176
125
  new_state,
177
- shared_state: new_shared.into(),
178
126
  }
179
127
  }
180
128
 
@@ -185,7 +133,7 @@ where
185
133
  CurrentState: Into<Ds>,
186
134
  {
187
135
  let as_dest: Ds = current_state.into();
188
- Self::OkNoShare {
136
+ Self::Ok {
189
137
  commands: vec![],
190
138
  new_state: as_dest,
191
139
  }
@@ -202,7 +150,7 @@ where
202
150
  where
203
151
  CI: IntoIterator<Item = Sm::Command>,
204
152
  {
205
- Self::OkNoShare {
153
+ Self::Ok {
206
154
  commands: commands.into_iter().collect(),
207
155
  new_state: Ds::default(),
208
156
  }
@@ -215,7 +163,7 @@ where
215
163
  Ds: Into<Sm::State> + Default,
216
164
  {
217
165
  fn default() -> Self {
218
- Self::OkNoShare {
166
+ Self::Ok {
219
167
  commands: vec![],
220
168
  new_state: Ds::default(),
221
169
  }
@@ -234,20 +182,26 @@ where
234
182
  TransitionResult::Ok {
235
183
  commands,
236
184
  new_state,
237
- shared_state,
238
185
  } => TransitionResult::Ok {
239
186
  commands,
240
187
  new_state: new_state.into(),
241
- shared_state,
242
188
  },
243
- TransitionResult::OkNoShare {
244
- commands,
189
+ TransitionResult::Err(e) => TransitionResult::Err(e),
190
+ }
191
+ }
192
+
193
+ /// Transforms the transition result into a machine-ready outcome with commands and new state,
194
+ /// or a [MachineError]
195
+ #[allow(clippy::type_complexity)]
196
+ pub fn into_cmd_result(self) -> Result<(Vec<Sm::Command>, Sm::State), MachineError<Sm::Error>> {
197
+ let general = self.into_general();
198
+ match general {
199
+ TransitionResult::Ok {
245
200
  new_state,
246
- } => TransitionResult::OkNoShare {
247
201
  commands,
248
- new_state: new_state.into(),
249
- },
250
- TransitionResult::Err(e) => TransitionResult::Err(e),
202
+ } => Ok((commands, new_state)),
203
+ TransitionResult::InvalidTransition => Err(MachineError::InvalidTransition),
204
+ TransitionResult::Err(e) => Err(MachineError::Underlying(e)),
251
205
  }
252
206
  }
253
207
  }
@@ -1,4 +1,5 @@
1
1
  # Syntax is here:
2
2
  # https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners#codeowners-syntax
3
3
 
4
- * @temporalio/server @temporalio/sdk
4
+ * @temporalio/server @temporalio/sdk
5
+ api/temporal/api/sdk/* @temporalio/sdk
@@ -37,7 +37,7 @@ go-grpc: clean $(PROTO_OUT)
37
37
 
38
38
  gogo-grpc: clean $(PROTO_OUT)
39
39
  printf $(COLOR) "Compile for gogo-gRPC..."
40
- $(foreach PROTO_DIR,$(PROTO_DIRS),protoc --fatal_warnings $(PROTO_IMPORTS) --gogoslick_out=Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/descriptor.proto=github.com/golang/protobuf/protoc-gen-go/descriptor,Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,plugins=grpc,paths=source_relative:$(PROTO_OUT) $(PROTO_DIR)*.proto;)
40
+ $(foreach PROTO_DIR,$(PROTO_DIRS),protoc --fatal_warnings $(PROTO_IMPORTS) --gogoslick_out=Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/descriptor.proto=github.com/golang/protobuf/protoc-gen-go/descriptor,Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,plugins=grpc,paths=source_relative:$(PROTO_OUT) $(PROTO_DIR)*.proto;)
41
41
 
42
42
  fix-path:
43
43
  mv -f $(PROTO_OUT)/temporal/api/* $(PROTO_OUT) && rm -rf $(PROTO_OUT)/temporal
@@ -39,7 +39,6 @@ import "temporal/api/enums/v1/workflow.proto";
39
39
  import "temporal/api/enums/v1/command_type.proto";
40
40
  import "temporal/api/common/v1/message.proto";
41
41
  import "temporal/api/failure/v1/message.proto";
42
- import "temporal/api/interaction/v1/message.proto";
43
42
  import "temporal/api/taskqueue/v1/message.proto";
44
43
 
45
44
  message ScheduleActivityTaskCommandAttributes {
@@ -221,19 +220,9 @@ message StartChildWorkflowExecutionCommandAttributes {
221
220
  temporal.api.common.v1.SearchAttributes search_attributes = 16;
222
221
  }
223
222
 
224
- message AcceptWorkflowUpdateCommandAttributes {
225
- temporal.api.interaction.v1.Meta meta = 1;
226
- temporal.api.interaction.v1.Input input = 2;
227
- }
228
-
229
- message CompleteWorkflowUpdateCommandAttributes {
230
- temporal.api.interaction.v1.Meta meta = 1;
231
- temporal.api.interaction.v1.Output output = 2;
232
- }
233
-
234
- message RejectWorkflowUpdateCommandAttributes {
235
- temporal.api.interaction.v1.Meta meta = 1;
236
- temporal.api.failure.v1.Failure failure = 2;
223
+ message ProtocolMessageCommandAttributes {
224
+ // The message ID of the message to which this command is a pointer.
225
+ string message_id = 1;
237
226
  }
238
227
 
239
228
  message Command {
@@ -252,9 +241,8 @@ message Command {
252
241
  StartChildWorkflowExecutionCommandAttributes start_child_workflow_execution_command_attributes = 12;
253
242
  SignalExternalWorkflowExecutionCommandAttributes signal_external_workflow_execution_command_attributes = 13;
254
243
  UpsertWorkflowSearchAttributesCommandAttributes upsert_workflow_search_attributes_command_attributes = 14;
255
- AcceptWorkflowUpdateCommandAttributes accept_workflow_update_command_attributes = 15;
256
- CompleteWorkflowUpdateCommandAttributes complete_workflow_update_command_attributes = 16;
244
+ ProtocolMessageCommandAttributes protocol_message_command_attributes = 15;
245
+ // 16 is available for use - it was used as part of a prototype that never made it into a release
257
246
  ModifyWorkflowPropertiesCommandAttributes modify_workflow_properties_command_attributes = 17;
258
- RejectWorkflowUpdateCommandAttributes reject_workflow_update_command_attributes = 18;
259
247
  }
260
248
  }
@@ -110,3 +110,14 @@ message RetryPolicy {
110
110
  // this is not a substring match, the error *type* (not message) must match exactly.
111
111
  repeated string non_retryable_error_types = 5;
112
112
  }
113
+
114
+ // Metadata relevant for metering purposes
115
+ message MeteringMetadata {
116
+ // Count of local activities which have begun an execution attempt during this workflow task,
117
+ // and whose first attempt occurred in some previous task. This is used for metering
118
+ // purposes, and does not affect workflow state.
119
+ //
120
+ // (-- api-linter: core::0141::forbidden-types=disabled
121
+ // aip.dev/not-precedent: Negative values make no sense to represent. --)
122
+ uint32 nonfirst_local_activity_execution_attempts = 13;
123
+ }
@@ -47,11 +47,6 @@ enum CommandType {
47
47
  COMMAND_TYPE_START_CHILD_WORKFLOW_EXECUTION = 11;
48
48
  COMMAND_TYPE_SIGNAL_EXTERNAL_WORKFLOW_EXECUTION = 12;
49
49
  COMMAND_TYPE_UPSERT_WORKFLOW_SEARCH_ATTRIBUTES = 13;
50
- // Indicates that an update has been accepted for processing workflow code
51
- COMMAND_TYPE_ACCEPT_WORKFLOW_UPDATE = 14;
52
- // Indicates that an update has completed and carries either the success or
53
- // failure outcome of said update.
54
- COMMAND_TYPE_COMPLETE_WORKFLOW_UPDATE = 15;
50
+ COMMAND_TYPE_PROTOCOL_MESSAGE = 14;
55
51
  COMMAND_TYPE_MODIFY_WORKFLOW_PROPERTIES = 16;
56
- COMMAND_TYPE_REJECT_WORKFLOW_UPDATE = 17;
57
52
  }
@@ -151,12 +151,12 @@ enum EventType {
151
151
  EVENT_TYPE_EXTERNAL_WORKFLOW_EXECUTION_SIGNALED = 39;
152
152
  // Workflow search attributes should be updated and synchronized with the visibility store
153
153
  EVENT_TYPE_UPSERT_WORKFLOW_SEARCH_ATTRIBUTES = 40;
154
- // Workflow update request has been received
155
- EVENT_TYPE_WORKFLOW_UPDATE_REJECTED = 41;
156
- // Workflow update request has been accepted by user workflow code
157
- EVENT_TYPE_WORKFLOW_UPDATE_ACCEPTED = 42;
158
- // Workflow update has been completed
159
- EVENT_TYPE_WORKFLOW_UPDATE_COMPLETED = 43;
154
+ // An update was accepted (i.e. validated)
155
+ EVENT_TYPE_WORKFLOW_EXECUTION_UPDATE_ACCEPTED = 41;
156
+ // An update was rejected (i.e. failed validation)
157
+ EVENT_TYPE_WORKFLOW_EXECUTION_UPDATE_REJECTED = 42;
158
+ // An update completed
159
+ EVENT_TYPE_WORKFLOW_EXECUTION_UPDATE_COMPLETED = 43;
160
160
  // Some property or properties of the workflow as a whole have changed by non-workflow code.
161
161
  // The distinction of external vs. command-based modification is important so the SDK can
162
162
  // maintain determinism when using the command-based approach.
@@ -85,6 +85,11 @@ enum WorkflowTaskFailedCause {
85
85
  // Similarly, we have a buffer of pending requests to cancel other workflows. We return this error
86
86
  // when our capacity for pending cancel requests is already reached.
87
87
  WORKFLOW_TASK_FAILED_CAUSE_PENDING_REQUEST_CANCEL_LIMIT_EXCEEDED = 29;
88
+ // Workflow execution update message (update.Acceptance, update.Rejection, or update.Response)
89
+ // has wrong format, or missing required fields.
90
+ WORKFLOW_TASK_FAILED_CAUSE_BAD_UPDATE_WORKFLOW_EXECUTION_MESSAGE = 30;
91
+ // Similar to WORKFLOW_TASK_FAILED_CAUSE_UNHANDLED_COMMAND, but for updates.
92
+ WORKFLOW_TASK_FAILED_CAUSE_UNHANDLED_UPDATE = 31;
88
93
  }
89
94
 
90
95
  enum StartChildWorkflowExecutionFailedCause {
@@ -31,10 +31,26 @@ option java_outer_classname = "UpdateProto";
31
31
  option ruby_package = "Temporalio::Api::Enums::V1";
32
32
  option csharp_namespace = "Temporalio.Api.Enums.V1";
33
33
 
34
- enum WorkflowUpdateResultAccessStyle {
35
- WORKFLOW_UPDATE_RESULT_ACCESS_STYLE_UNSPECIFIED = 0;
36
-
37
- // Indicates that the update response _must_ be included as part of the gRPC
38
- // response body
39
- WORKFLOW_UPDATE_RESULT_ACCESS_STYLE_REQUIRE_INLINE = 1;
34
+ // UpdateWorkflowExecutionLifecycleStage is specified by clients invoking
35
+ // workflow execution updates and used to indicate to the server how long the
36
+ // client wishes to wait for a return value from the RPC. If any value other
37
+ // than UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_COMPLETED is sent by the
38
+ // client then the RPC will complete before the update is finished and will
39
+ // return a handle to the running update so that it can later be polled for
40
+ // completion.
41
+ enum UpdateWorkflowExecutionLifecycleStage {
42
+ // An unspecified vale for this enum.
43
+ UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_UNSPECIFIED = 0;
44
+ // The gRPC call will not return until the update request has been admitted
45
+ // by the server - it may be the case that due to a considerations like load
46
+ // or resource limits that an update is made to wait before the server will
47
+ // indicate that it has been received and will be processed. This value
48
+ // does not wait for any sort of acknowledgement from a worker.
49
+ UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_ADMITTED = 1;
50
+ // The gRPC call will not return until the update has passed validation on
51
+ // a worker.
52
+ UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_ACCEPTED = 2;
53
+ // The gRPC call will not return until the update has executed to completion
54
+ // on a worker and has either been rejected or returned a value or an error.
55
+ UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_COMPLETED = 3;
40
56
  }