temporalio 0.0.1 → 0.1.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 (310) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +180 -7
  3. data/bridge/Cargo.lock +208 -76
  4. data/bridge/Cargo.toml +5 -2
  5. data/bridge/sdk-core/Cargo.toml +1 -1
  6. data/bridge/sdk-core/README.md +20 -10
  7. data/bridge/sdk-core/client/Cargo.toml +1 -1
  8. data/bridge/sdk-core/client/src/lib.rs +227 -59
  9. data/bridge/sdk-core/client/src/metrics.rs +17 -8
  10. data/bridge/sdk-core/client/src/raw.rs +13 -12
  11. data/bridge/sdk-core/client/src/retry.rs +132 -43
  12. data/bridge/sdk-core/core/Cargo.toml +28 -15
  13. data/bridge/sdk-core/core/benches/workflow_replay.rs +13 -10
  14. data/bridge/sdk-core/core/src/abstractions.rs +225 -36
  15. data/bridge/sdk-core/core/src/core_tests/activity_tasks.rs +217 -79
  16. data/bridge/sdk-core/core/src/core_tests/determinism.rs +165 -2
  17. data/bridge/sdk-core/core/src/core_tests/local_activities.rs +565 -34
  18. data/bridge/sdk-core/core/src/core_tests/queries.rs +247 -90
  19. data/bridge/sdk-core/core/src/core_tests/workers.rs +3 -5
  20. data/bridge/sdk-core/core/src/core_tests/workflow_cancels.rs +1 -1
  21. data/bridge/sdk-core/core/src/core_tests/workflow_tasks.rs +430 -67
  22. data/bridge/sdk-core/core/src/ephemeral_server/mod.rs +106 -12
  23. data/bridge/sdk-core/core/src/internal_flags.rs +136 -0
  24. data/bridge/sdk-core/core/src/lib.rs +148 -34
  25. data/bridge/sdk-core/core/src/protosext/mod.rs +1 -1
  26. data/bridge/sdk-core/core/src/replay/mod.rs +185 -41
  27. data/bridge/sdk-core/core/src/telemetry/log_export.rs +190 -0
  28. data/bridge/sdk-core/core/src/telemetry/metrics.rs +219 -140
  29. data/bridge/sdk-core/core/src/telemetry/mod.rs +326 -315
  30. data/bridge/sdk-core/core/src/telemetry/prometheus_server.rs +20 -14
  31. data/bridge/sdk-core/core/src/test_help/mod.rs +85 -21
  32. data/bridge/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +112 -156
  33. data/bridge/sdk-core/core/src/worker/activities/activity_task_poller_stream.rs +89 -0
  34. data/bridge/sdk-core/core/src/worker/activities/local_activities.rs +364 -128
  35. data/bridge/sdk-core/core/src/worker/activities.rs +263 -170
  36. data/bridge/sdk-core/core/src/worker/client/mocks.rs +23 -3
  37. data/bridge/sdk-core/core/src/worker/client.rs +48 -6
  38. data/bridge/sdk-core/core/src/worker/mod.rs +186 -75
  39. data/bridge/sdk-core/core/src/worker/workflow/bridge.rs +1 -3
  40. data/bridge/sdk-core/core/src/worker/workflow/driven_workflow.rs +13 -24
  41. data/bridge/sdk-core/core/src/worker/workflow/history_update.rs +879 -226
  42. data/bridge/sdk-core/core/src/worker/workflow/machines/activity_state_machine.rs +101 -48
  43. data/bridge/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +8 -12
  44. data/bridge/sdk-core/core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +6 -9
  45. data/bridge/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +90 -32
  46. data/bridge/sdk-core/core/src/worker/workflow/machines/complete_workflow_state_machine.rs +6 -9
  47. data/bridge/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +7 -10
  48. data/bridge/sdk-core/core/src/worker/workflow/machines/fail_workflow_state_machine.rs +6 -9
  49. data/bridge/sdk-core/core/src/worker/workflow/machines/local_activity_state_machine.rs +160 -83
  50. data/bridge/sdk-core/core/src/worker/workflow/machines/mod.rs +36 -54
  51. data/bridge/sdk-core/core/src/worker/workflow/machines/modify_workflow_properties_state_machine.rs +179 -0
  52. data/bridge/sdk-core/core/src/worker/workflow/machines/patch_state_machine.rs +104 -157
  53. data/bridge/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +8 -12
  54. data/bridge/sdk-core/core/src/worker/workflow/machines/timer_state_machine.rs +9 -13
  55. data/bridge/sdk-core/core/src/worker/workflow/machines/transition_coverage.rs +10 -4
  56. data/bridge/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +14 -11
  57. data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_machines/local_acts.rs +6 -17
  58. data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +395 -299
  59. data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_task_state_machine.rs +12 -20
  60. data/bridge/sdk-core/core/src/worker/workflow/managed_run/managed_wf_test.rs +33 -18
  61. data/bridge/sdk-core/core/src/worker/workflow/managed_run.rs +1032 -374
  62. data/bridge/sdk-core/core/src/worker/workflow/mod.rs +525 -392
  63. data/bridge/sdk-core/core/src/worker/workflow/run_cache.rs +40 -57
  64. data/bridge/sdk-core/core/src/worker/workflow/wft_extraction.rs +125 -0
  65. data/bridge/sdk-core/core/src/worker/workflow/wft_poller.rs +3 -6
  66. data/bridge/sdk-core/core/src/worker/workflow/workflow_stream/saved_wf_inputs.rs +117 -0
  67. data/bridge/sdk-core/core/src/worker/workflow/workflow_stream/tonic_status_serde.rs +24 -0
  68. data/bridge/sdk-core/core/src/worker/workflow/workflow_stream.rs +456 -681
  69. data/bridge/sdk-core/core-api/Cargo.toml +6 -4
  70. data/bridge/sdk-core/core-api/src/errors.rs +1 -34
  71. data/bridge/sdk-core/core-api/src/lib.rs +7 -45
  72. data/bridge/sdk-core/core-api/src/telemetry.rs +141 -0
  73. data/bridge/sdk-core/core-api/src/worker.rs +27 -1
  74. data/bridge/sdk-core/etc/deps.svg +115 -140
  75. data/bridge/sdk-core/etc/regen-depgraph.sh +5 -0
  76. data/bridge/sdk-core/fsm/rustfsm_procmacro/src/lib.rs +18 -15
  77. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/no_handle_conversions_require_into_fail.stderr +1 -1
  78. data/bridge/sdk-core/fsm/rustfsm_trait/src/lib.rs +8 -3
  79. data/bridge/sdk-core/histories/evict_while_la_running_no_interference-16_history.bin +0 -0
  80. data/bridge/sdk-core/histories/evict_while_la_running_no_interference-23_history.bin +0 -0
  81. data/bridge/sdk-core/histories/evict_while_la_running_no_interference-85_history.bin +0 -0
  82. data/bridge/sdk-core/protos/api_upstream/buf.yaml +0 -3
  83. data/bridge/sdk-core/protos/api_upstream/build/go.mod +7 -0
  84. data/bridge/sdk-core/protos/api_upstream/build/go.sum +5 -0
  85. data/bridge/sdk-core/protos/api_upstream/{temporal/api/enums/v1/cluster.proto → build/tools.go} +7 -18
  86. data/bridge/sdk-core/protos/api_upstream/go.mod +6 -0
  87. data/bridge/sdk-core/protos/api_upstream/temporal/api/batch/v1/message.proto +12 -9
  88. data/bridge/sdk-core/protos/api_upstream/temporal/api/command/v1/message.proto +15 -26
  89. data/bridge/sdk-core/protos/api_upstream/temporal/api/common/v1/message.proto +13 -2
  90. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/batch_operation.proto +3 -2
  91. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/command_type.proto +4 -9
  92. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/common.proto +3 -2
  93. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/event_type.proto +10 -8
  94. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +28 -2
  95. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/namespace.proto +2 -2
  96. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/query.proto +2 -2
  97. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/reset.proto +2 -2
  98. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/schedule.proto +2 -2
  99. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/task_queue.proto +2 -2
  100. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/update.proto +24 -19
  101. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/workflow.proto +2 -2
  102. data/bridge/sdk-core/protos/api_upstream/temporal/api/errordetails/v1/message.proto +2 -2
  103. data/bridge/sdk-core/protos/api_upstream/temporal/api/failure/v1/message.proto +2 -2
  104. data/bridge/sdk-core/protos/api_upstream/temporal/api/filter/v1/message.proto +2 -2
  105. data/bridge/sdk-core/protos/api_upstream/temporal/api/history/v1/message.proto +62 -26
  106. data/bridge/sdk-core/protos/api_upstream/temporal/api/namespace/v1/message.proto +4 -2
  107. data/bridge/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +24 -61
  108. data/bridge/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/service.proto +2 -21
  109. data/bridge/sdk-core/protos/api_upstream/temporal/api/protocol/v1/message.proto +57 -0
  110. data/bridge/sdk-core/protos/api_upstream/temporal/api/query/v1/message.proto +2 -2
  111. data/bridge/sdk-core/protos/api_upstream/temporal/api/replication/v1/message.proto +2 -2
  112. data/bridge/sdk-core/protos/api_upstream/temporal/api/schedule/v1/message.proto +110 -31
  113. data/bridge/sdk-core/protos/api_upstream/temporal/api/sdk/v1/task_complete_metadata.proto +63 -0
  114. data/bridge/sdk-core/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +4 -4
  115. data/bridge/sdk-core/protos/api_upstream/temporal/api/update/v1/message.proto +71 -6
  116. data/bridge/sdk-core/protos/api_upstream/temporal/api/version/v1/message.proto +2 -2
  117. data/bridge/sdk-core/protos/api_upstream/temporal/api/workflow/v1/message.proto +3 -2
  118. data/bridge/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +111 -36
  119. data/bridge/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +19 -5
  120. data/bridge/sdk-core/protos/local/temporal/sdk/core/activity_result/activity_result.proto +1 -0
  121. data/bridge/sdk-core/protos/local/temporal/sdk/core/activity_task/activity_task.proto +1 -0
  122. data/bridge/sdk-core/protos/local/temporal/sdk/core/child_workflow/child_workflow.proto +1 -0
  123. data/bridge/sdk-core/protos/local/temporal/sdk/core/common/common.proto +1 -0
  124. data/bridge/sdk-core/protos/local/temporal/sdk/core/core_interface.proto +1 -0
  125. data/bridge/sdk-core/protos/local/temporal/sdk/core/external_data/external_data.proto +1 -0
  126. data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +9 -0
  127. data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +9 -1
  128. data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_completion/workflow_completion.proto +6 -0
  129. data/bridge/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/request_response.proto +2 -2
  130. data/bridge/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/service.proto +2 -2
  131. data/bridge/sdk-core/sdk/Cargo.toml +4 -3
  132. data/bridge/sdk-core/sdk/src/interceptors.rs +36 -3
  133. data/bridge/sdk-core/sdk/src/lib.rs +94 -25
  134. data/bridge/sdk-core/sdk/src/workflow_context.rs +13 -2
  135. data/bridge/sdk-core/sdk/src/workflow_future.rs +10 -13
  136. data/bridge/sdk-core/sdk-core-protos/Cargo.toml +5 -2
  137. data/bridge/sdk-core/sdk-core-protos/build.rs +36 -2
  138. data/bridge/sdk-core/sdk-core-protos/src/history_builder.rs +164 -104
  139. data/bridge/sdk-core/sdk-core-protos/src/history_info.rs +27 -23
  140. data/bridge/sdk-core/sdk-core-protos/src/lib.rs +252 -74
  141. data/bridge/sdk-core/sdk-core-protos/src/task_token.rs +12 -2
  142. data/bridge/sdk-core/test-utils/Cargo.toml +4 -1
  143. data/bridge/sdk-core/test-utils/src/canned_histories.rs +106 -296
  144. data/bridge/sdk-core/test-utils/src/histfetch.rs +1 -1
  145. data/bridge/sdk-core/test-utils/src/lib.rs +161 -50
  146. data/bridge/sdk-core/test-utils/src/wf_input_saver.rs +50 -0
  147. data/bridge/sdk-core/test-utils/src/workflows.rs +29 -0
  148. data/bridge/sdk-core/tests/fuzzy_workflow.rs +130 -0
  149. data/bridge/sdk-core/tests/{load_tests.rs → heavy_tests.rs} +125 -51
  150. data/bridge/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +25 -3
  151. data/bridge/sdk-core/tests/integ_tests/heartbeat_tests.rs +10 -5
  152. data/bridge/sdk-core/tests/integ_tests/metrics_tests.rs +239 -0
  153. data/bridge/sdk-core/tests/integ_tests/polling_tests.rs +4 -60
  154. data/bridge/sdk-core/tests/integ_tests/queries_tests.rs +5 -128
  155. data/bridge/sdk-core/tests/integ_tests/visibility_tests.rs +83 -25
  156. data/bridge/sdk-core/tests/integ_tests/workflow_tests/activities.rs +93 -69
  157. data/bridge/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +1 -0
  158. data/bridge/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +6 -13
  159. data/bridge/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +1 -0
  160. data/bridge/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +6 -2
  161. data/bridge/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +3 -10
  162. data/bridge/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +151 -116
  163. data/bridge/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +54 -0
  164. data/bridge/sdk-core/tests/integ_tests/workflow_tests/patches.rs +7 -28
  165. data/bridge/sdk-core/tests/integ_tests/workflow_tests/replay.rs +115 -24
  166. data/bridge/sdk-core/tests/integ_tests/workflow_tests/resets.rs +1 -0
  167. data/bridge/sdk-core/tests/integ_tests/workflow_tests/signals.rs +18 -14
  168. data/bridge/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +6 -20
  169. data/bridge/sdk-core/tests/integ_tests/workflow_tests/timers.rs +10 -21
  170. data/bridge/sdk-core/tests/integ_tests/workflow_tests/upsert_search_attrs.rs +6 -4
  171. data/bridge/sdk-core/tests/integ_tests/workflow_tests.rs +27 -18
  172. data/bridge/sdk-core/tests/main.rs +8 -16
  173. data/bridge/sdk-core/tests/runner.rs +75 -36
  174. data/bridge/sdk-core/tests/wf_input_replay.rs +32 -0
  175. data/bridge/src/connection.rs +117 -82
  176. data/bridge/src/lib.rs +356 -42
  177. data/bridge/src/runtime.rs +10 -3
  178. data/bridge/src/test_server.rs +153 -0
  179. data/bridge/src/worker.rs +133 -9
  180. data/lib/gen/temporal/api/batch/v1/message_pb.rb +8 -6
  181. data/lib/gen/temporal/api/command/v1/message_pb.rb +10 -16
  182. data/lib/gen/temporal/api/common/v1/message_pb.rb +5 -1
  183. data/lib/gen/temporal/api/enums/v1/batch_operation_pb.rb +2 -1
  184. data/lib/gen/temporal/api/enums/v1/command_type_pb.rb +3 -3
  185. data/lib/gen/temporal/api/enums/v1/common_pb.rb +2 -1
  186. data/lib/gen/temporal/api/enums/v1/event_type_pb.rb +5 -4
  187. data/lib/gen/temporal/api/enums/v1/failed_cause_pb.rb +9 -1
  188. data/lib/gen/temporal/api/enums/v1/namespace_pb.rb +1 -1
  189. data/lib/gen/temporal/api/enums/v1/query_pb.rb +1 -1
  190. data/lib/gen/temporal/api/enums/v1/reset_pb.rb +1 -1
  191. data/lib/gen/temporal/api/enums/v1/schedule_pb.rb +1 -1
  192. data/lib/gen/temporal/api/enums/v1/task_queue_pb.rb +1 -1
  193. data/lib/gen/temporal/api/enums/v1/update_pb.rb +7 -10
  194. data/lib/gen/temporal/api/enums/v1/workflow_pb.rb +1 -1
  195. data/lib/gen/temporal/api/errordetails/v1/message_pb.rb +1 -1
  196. data/lib/gen/temporal/api/failure/v1/message_pb.rb +1 -1
  197. data/lib/gen/temporal/api/filter/v1/message_pb.rb +1 -1
  198. data/lib/gen/temporal/api/history/v1/message_pb.rb +34 -25
  199. data/lib/gen/temporal/api/namespace/v1/message_pb.rb +2 -1
  200. data/lib/gen/temporal/api/operatorservice/v1/request_response_pb.rb +14 -51
  201. data/lib/gen/temporal/api/operatorservice/v1/service_pb.rb +1 -1
  202. data/lib/gen/temporal/api/protocol/v1/message_pb.rb +30 -0
  203. data/lib/gen/temporal/api/query/v1/message_pb.rb +1 -1
  204. data/lib/gen/temporal/api/replication/v1/message_pb.rb +1 -1
  205. data/lib/gen/temporal/api/schedule/v1/message_pb.rb +22 -1
  206. data/lib/gen/temporal/api/sdk/v1/task_complete_metadata_pb.rb +23 -0
  207. data/lib/gen/temporal/api/taskqueue/v1/message_pb.rb +2 -2
  208. data/lib/gen/temporal/api/testservice/v1/request_response_pb.rb +49 -0
  209. data/lib/gen/temporal/api/testservice/v1/service_pb.rb +21 -0
  210. data/lib/gen/temporal/api/update/v1/message_pb.rb +49 -3
  211. data/lib/gen/temporal/api/version/v1/message_pb.rb +1 -1
  212. data/lib/gen/temporal/api/workflow/v1/message_pb.rb +2 -1
  213. data/lib/gen/temporal/api/workflowservice/v1/request_response_pb.rb +47 -20
  214. data/lib/gen/temporal/api/workflowservice/v1/service_pb.rb +1 -1
  215. data/lib/gen/temporal/sdk/core/activity_result/activity_result_pb.rb +13 -9
  216. data/lib/gen/temporal/sdk/core/activity_task/activity_task_pb.rb +10 -6
  217. data/lib/gen/temporal/sdk/core/child_workflow/child_workflow_pb.rb +13 -9
  218. data/lib/gen/temporal/sdk/core/common/common_pb.rb +7 -3
  219. data/lib/gen/temporal/sdk/core/core_interface_pb.rb +9 -3
  220. data/lib/gen/temporal/sdk/core/external_data/external_data_pb.rb +7 -3
  221. data/lib/gen/temporal/sdk/core/workflow_activation/workflow_activation_pb.rb +28 -21
  222. data/lib/gen/temporal/sdk/core/workflow_commands/workflow_commands_pb.rb +32 -24
  223. data/lib/gen/temporal/sdk/core/workflow_completion/workflow_completion_pb.rb +12 -5
  224. data/lib/temporalio/activity/context.rb +102 -0
  225. data/lib/temporalio/activity/info.rb +67 -0
  226. data/lib/temporalio/activity.rb +85 -0
  227. data/lib/temporalio/bridge/connect_options.rb +15 -0
  228. data/lib/temporalio/bridge/error.rb +8 -0
  229. data/lib/temporalio/bridge/retry_config.rb +24 -0
  230. data/lib/temporalio/bridge/tls_options.rb +19 -0
  231. data/lib/temporalio/bridge.rb +14 -0
  232. data/lib/{temporal → temporalio}/client/implementation.rb +57 -56
  233. data/lib/{temporal → temporalio}/client/workflow_handle.rb +35 -35
  234. data/lib/{temporal → temporalio}/client.rb +19 -32
  235. data/lib/temporalio/connection/retry_config.rb +44 -0
  236. data/lib/temporalio/connection/service.rb +20 -0
  237. data/lib/temporalio/connection/test_service.rb +92 -0
  238. data/lib/temporalio/connection/tls_options.rb +51 -0
  239. data/lib/temporalio/connection/workflow_service.rb +731 -0
  240. data/lib/temporalio/connection.rb +86 -0
  241. data/lib/{temporal → temporalio}/data_converter.rb +76 -35
  242. data/lib/{temporal → temporalio}/error/failure.rb +6 -6
  243. data/lib/{temporal → temporalio}/error/workflow_failure.rb +4 -2
  244. data/lib/{temporal → temporalio}/errors.rb +19 -1
  245. data/lib/{temporal → temporalio}/failure_converter/base.rb +5 -5
  246. data/lib/{temporal → temporalio}/failure_converter/basic.rb +58 -52
  247. data/lib/temporalio/failure_converter.rb +7 -0
  248. data/lib/temporalio/interceptor/activity_inbound.rb +22 -0
  249. data/lib/temporalio/interceptor/activity_outbound.rb +24 -0
  250. data/lib/{temporal → temporalio}/interceptor/chain.rb +7 -6
  251. data/lib/{temporal → temporalio}/interceptor/client.rb +27 -2
  252. data/lib/temporalio/interceptor.rb +22 -0
  253. data/lib/{temporal → temporalio}/payload_codec/base.rb +5 -5
  254. data/lib/{temporal → temporalio}/payload_converter/base.rb +3 -3
  255. data/lib/{temporal → temporalio}/payload_converter/bytes.rb +4 -3
  256. data/lib/{temporal → temporalio}/payload_converter/composite.rb +7 -5
  257. data/lib/{temporal → temporalio}/payload_converter/encoding_base.rb +4 -4
  258. data/lib/{temporal → temporalio}/payload_converter/json.rb +4 -3
  259. data/lib/{temporal → temporalio}/payload_converter/nil.rb +4 -3
  260. data/lib/temporalio/payload_converter.rb +14 -0
  261. data/lib/{temporal → temporalio}/retry_policy.rb +17 -7
  262. data/lib/{temporal → temporalio}/retry_state.rb +1 -1
  263. data/lib/temporalio/runtime.rb +25 -0
  264. data/lib/temporalio/testing/time_skipping_handle.rb +32 -0
  265. data/lib/temporalio/testing/time_skipping_interceptor.rb +23 -0
  266. data/lib/temporalio/testing/workflow_environment.rb +112 -0
  267. data/lib/temporalio/testing.rb +175 -0
  268. data/lib/{temporal → temporalio}/timeout_type.rb +2 -2
  269. data/lib/temporalio/version.rb +3 -0
  270. data/lib/temporalio/worker/activity_runner.rb +114 -0
  271. data/lib/temporalio/worker/activity_worker.rb +164 -0
  272. data/lib/temporalio/worker/reactor.rb +46 -0
  273. data/lib/temporalio/worker/runner.rb +63 -0
  274. data/lib/temporalio/worker/sync_worker.rb +124 -0
  275. data/lib/temporalio/worker/thread_pool_executor.rb +51 -0
  276. data/lib/temporalio/worker.rb +204 -0
  277. data/lib/temporalio/workflow/async.rb +46 -0
  278. data/lib/{temporal → temporalio}/workflow/execution_info.rb +4 -4
  279. data/lib/{temporal → temporalio}/workflow/execution_status.rb +1 -1
  280. data/lib/temporalio/workflow/future.rb +138 -0
  281. data/lib/{temporal → temporalio}/workflow/id_reuse_policy.rb +6 -6
  282. data/lib/temporalio/workflow/info.rb +76 -0
  283. data/lib/{temporal → temporalio}/workflow/query_reject_condition.rb +5 -5
  284. data/lib/temporalio.rb +12 -3
  285. data/temporalio.gemspec +11 -6
  286. metadata +137 -64
  287. data/bridge/sdk-core/Cargo.lock +0 -2606
  288. data/bridge/sdk-core/bridge-ffi/Cargo.toml +0 -24
  289. data/bridge/sdk-core/bridge-ffi/LICENSE.txt +0 -23
  290. data/bridge/sdk-core/bridge-ffi/build.rs +0 -25
  291. data/bridge/sdk-core/bridge-ffi/include/sdk-core-bridge.h +0 -249
  292. data/bridge/sdk-core/bridge-ffi/src/lib.rs +0 -825
  293. data/bridge/sdk-core/bridge-ffi/src/wrappers.rs +0 -211
  294. data/bridge/sdk-core/core/src/log_export.rs +0 -62
  295. data/bridge/sdk-core/core/src/worker/workflow/machines/mutable_side_effect_state_machine.rs +0 -127
  296. data/bridge/sdk-core/core/src/worker/workflow/machines/side_effect_state_machine.rs +0 -71
  297. data/bridge/sdk-core/protos/api_upstream/temporal/api/cluster/v1/message.proto +0 -83
  298. data/bridge/sdk-core/protos/local/temporal/sdk/core/bridge/bridge.proto +0 -210
  299. data/bridge/sdk-core/sdk/src/conversions.rs +0 -8
  300. data/lib/bridge.so +0 -0
  301. data/lib/gen/temporal/api/cluster/v1/message_pb.rb +0 -67
  302. data/lib/gen/temporal/api/enums/v1/cluster_pb.rb +0 -26
  303. data/lib/gen/temporal/sdk/core/bridge/bridge_pb.rb +0 -222
  304. data/lib/temporal/bridge.rb +0 -14
  305. data/lib/temporal/connection.rb +0 -736
  306. data/lib/temporal/failure_converter.rb +0 -8
  307. data/lib/temporal/payload_converter.rb +0 -14
  308. data/lib/temporal/runtime.rb +0 -22
  309. data/lib/temporal/version.rb +0 -3
  310. data/lib/temporal.rb +0 -8
@@ -1,9 +1,13 @@
1
1
  #![allow(clippy::large_enum_variant)]
2
2
 
3
3
  use super::{
4
- workflow_machines::MachineResponse, Cancellable, EventInfo, MachineKind, NewMachineWithCommand,
4
+ workflow_machines::MachineResponse, Cancellable, EventInfo, NewMachineWithCommand,
5
5
  OnEventWrapper, WFMachinesAdapter, WFMachinesError,
6
6
  };
7
+ use crate::{
8
+ internal_flags::CoreInternalFlags,
9
+ worker::workflow::{machines::HistEventData, InternalFlagsRef},
10
+ };
7
11
  use rustfsm::{fsm, MachineError, StateMachine, TransitionResult};
8
12
  use std::convert::{TryFrom, TryInto};
9
13
  use temporal_sdk_core_protos::{
@@ -37,7 +41,7 @@ fsm! {
37
41
  Created --(Schedule, on_schedule)--> ScheduleCommandCreated;
38
42
 
39
43
  ScheduleCommandCreated --(CommandScheduleActivityTask) --> ScheduleCommandCreated;
40
- ScheduleCommandCreated --(ActivityTaskScheduled(i64),
44
+ ScheduleCommandCreated --(ActivityTaskScheduled(ActTaskScheduledData),
41
45
  shared on_activity_task_scheduled) --> ScheduledEventRecorded;
42
46
  ScheduleCommandCreated --(Cancel, shared on_canceled) --> Canceled;
43
47
 
@@ -94,34 +98,41 @@ pub(super) enum ActivityMachineCommand {
94
98
  RequestCancellation(Command),
95
99
  }
96
100
 
97
- /// Creates a new activity state machine and a command to schedule it on the server.
98
- pub(super) fn new_activity(attribs: ScheduleActivity) -> NewMachineWithCommand {
99
- let (activity, add_cmd) = ActivityMachine::new_scheduled(attribs);
100
- NewMachineWithCommand {
101
- command: add_cmd,
102
- machine: activity.into(),
103
- }
101
+ pub(super) struct ActTaskScheduledData {
102
+ event_id: i64,
103
+ act_type: String,
104
+ act_id: String,
105
+ last_task_in_history: bool,
104
106
  }
105
107
 
106
108
  impl ActivityMachine {
107
109
  /// Create a new activity and immediately schedule it.
108
- fn new_scheduled(attribs: ScheduleActivity) -> (Self, Command) {
110
+ pub(super) fn new_scheduled(
111
+ attrs: ScheduleActivity,
112
+ internal_flags: InternalFlagsRef,
113
+ ) -> NewMachineWithCommand {
109
114
  let mut s = Self {
110
115
  state: Created {}.into(),
111
116
  shared_state: SharedState {
112
- cancellation_type: ActivityCancellationType::from_i32(attribs.cancellation_type)
117
+ cancellation_type: ActivityCancellationType::from_i32(attrs.cancellation_type)
113
118
  .unwrap(),
114
- attrs: attribs,
115
- ..Default::default()
119
+ attrs,
120
+ internal_flags,
121
+ scheduled_event_id: 0,
122
+ started_event_id: 0,
123
+ cancelled_before_sent: false,
116
124
  },
117
125
  };
118
126
  OnEventWrapper::on_event_mut(&mut s, ActivityMachineEvents::Schedule)
119
127
  .expect("Scheduling activities doesn't fail");
120
- let cmd = Command {
128
+ let command = Command {
121
129
  command_type: CommandType::ScheduleActivityTask as i32,
122
130
  attributes: Some(s.shared_state().attrs.clone().into()),
123
131
  };
124
- (s, cmd)
132
+ NewMachineWithCommand {
133
+ command,
134
+ machine: s.into(),
135
+ }
125
136
  }
126
137
 
127
138
  fn machine_responses_from_cancel_request(&self, cancel_cmd: Command) -> Vec<MachineResponse> {
@@ -169,12 +180,30 @@ impl ActivityMachine {
169
180
  }
170
181
  }
171
182
 
172
- impl TryFrom<HistoryEvent> for ActivityMachineEvents {
183
+ impl TryFrom<HistEventData> for ActivityMachineEvents {
173
184
  type Error = WFMachinesError;
174
185
 
175
- fn try_from(e: HistoryEvent) -> Result<Self, Self::Error> {
186
+ fn try_from(e: HistEventData) -> Result<Self, Self::Error> {
187
+ let last_task_in_history = e.current_task_is_last_in_history;
188
+ let e = e.event;
176
189
  Ok(match e.event_type() {
177
- EventType::ActivityTaskScheduled => Self::ActivityTaskScheduled(e.event_id),
190
+ EventType::ActivityTaskScheduled => {
191
+ if let Some(history_event::Attributes::ActivityTaskScheduledEventAttributes(
192
+ attrs,
193
+ )) = e.attributes
194
+ {
195
+ Self::ActivityTaskScheduled(ActTaskScheduledData {
196
+ event_id: e.event_id,
197
+ act_id: attrs.activity_id,
198
+ act_type: attrs.activity_type.unwrap_or_default().name,
199
+ last_task_in_history,
200
+ })
201
+ } else {
202
+ return Err(WFMachinesError::Fatal(format!(
203
+ "Activity scheduled attributes were unset: {e}"
204
+ )));
205
+ }
206
+ }
178
207
  EventType::ActivityTaskStarted => Self::ActivityTaskStarted(e.event_id),
179
208
  EventType::ActivityTaskCompleted => {
180
209
  if let Some(history_event::Attributes::ActivityTaskCompletedEventAttributes(
@@ -184,8 +213,7 @@ impl TryFrom<HistoryEvent> for ActivityMachineEvents {
184
213
  Self::ActivityTaskCompleted(attrs)
185
214
  } else {
186
215
  return Err(WFMachinesError::Fatal(format!(
187
- "Activity completion attributes were unset: {}",
188
- e
216
+ "Activity completion attributes were unset: {e}"
189
217
  )));
190
218
  }
191
219
  }
@@ -196,8 +224,7 @@ impl TryFrom<HistoryEvent> for ActivityMachineEvents {
196
224
  Self::ActivityTaskFailed(attrs)
197
225
  } else {
198
226
  return Err(WFMachinesError::Fatal(format!(
199
- "Activity failure attributes were unset: {}",
200
- e
227
+ "Activity failure attributes were unset: {e}"
201
228
  )));
202
229
  }
203
230
  }
@@ -208,8 +235,7 @@ impl TryFrom<HistoryEvent> for ActivityMachineEvents {
208
235
  Self::ActivityTaskTimedOut(attrs)
209
236
  } else {
210
237
  return Err(WFMachinesError::Fatal(format!(
211
- "Activity timeout attributes were unset: {}",
212
- e
238
+ "Activity timeout attributes were unset: {e}"
213
239
  )));
214
240
  }
215
241
  }
@@ -221,15 +247,13 @@ impl TryFrom<HistoryEvent> for ActivityMachineEvents {
221
247
  Self::ActivityTaskCanceled(attrs)
222
248
  } else {
223
249
  return Err(WFMachinesError::Fatal(format!(
224
- "Activity cancellation attributes were unset: {}",
225
- e
250
+ "Activity cancellation attributes were unset: {e}"
226
251
  )));
227
252
  }
228
253
  }
229
254
  _ => {
230
255
  return Err(WFMachinesError::Nondeterminism(format!(
231
- "Activity machine does not handle this event: {}",
232
- e
256
+ "Activity machine does not handle this event: {e}"
233
257
  )))
234
258
  }
235
259
  })
@@ -288,10 +312,6 @@ impl WFMachinesAdapter for ActivityMachine {
288
312
  | EventType::ActivityTaskCanceled
289
313
  )
290
314
  }
291
-
292
- fn kind(&self) -> MachineKind {
293
- MachineKind::Activity
294
- }
295
315
  }
296
316
 
297
317
  impl TryFrom<CommandType> for ActivityMachineEvents {
@@ -343,7 +363,7 @@ impl Cancellable for ActivityMachine {
343
363
  )
344
364
  .into()]
345
365
  }
346
- x => panic!("Invalid cancel event response {:?}", x),
366
+ x => panic!("Invalid cancel event response {x:?}"),
347
367
  })
348
368
  .collect();
349
369
  Ok(res)
@@ -354,13 +374,14 @@ impl Cancellable for ActivityMachine {
354
374
  }
355
375
  }
356
376
 
357
- #[derive(Default, Clone)]
377
+ #[derive(Clone)]
358
378
  pub(super) struct SharedState {
359
379
  scheduled_event_id: i64,
360
380
  started_event_id: i64,
361
381
  attrs: ScheduleActivity,
362
382
  cancellation_type: ActivityCancellationType,
363
383
  cancelled_before_sent: bool,
384
+ internal_flags: InternalFlagsRef,
364
385
  }
365
386
 
366
387
  #[derive(Default, Clone)]
@@ -380,17 +401,37 @@ impl ScheduleCommandCreated {
380
401
  pub(super) fn on_activity_task_scheduled(
381
402
  self,
382
403
  dat: SharedState,
383
- scheduled_event_id: i64,
404
+ sched_dat: ActTaskScheduledData,
384
405
  ) -> ActivityMachineTransition<ScheduledEventRecorded> {
406
+ if dat.internal_flags.borrow_mut().try_use(
407
+ CoreInternalFlags::IdAndTypeDeterminismChecks,
408
+ sched_dat.last_task_in_history,
409
+ ) {
410
+ if sched_dat.act_id != dat.attrs.activity_id {
411
+ return TransitionResult::Err(WFMachinesError::Nondeterminism(format!(
412
+ "Activity id of scheduled event '{}' does not \
413
+ match activity id of activity command '{}'",
414
+ sched_dat.act_id, dat.attrs.activity_id
415
+ )));
416
+ }
417
+ if sched_dat.act_type != dat.attrs.activity_type {
418
+ return TransitionResult::Err(WFMachinesError::Nondeterminism(format!(
419
+ "Activity type of scheduled event '{}' does not \
420
+ match activity type of activity command '{}'",
421
+ sched_dat.act_type, dat.attrs.activity_type
422
+ )));
423
+ }
424
+ }
385
425
  ActivityMachineTransition::ok_shared(
386
426
  vec![],
387
427
  ScheduledEventRecorded::default(),
388
428
  SharedState {
389
- scheduled_event_id,
429
+ scheduled_event_id: sched_dat.event_id,
390
430
  ..dat
391
431
  },
392
432
  )
393
433
  }
434
+
394
435
  pub(super) fn on_canceled(self, dat: SharedState) -> ActivityMachineTransition<Canceled> {
395
436
  let canceled_state = SharedState {
396
437
  cancelled_before_sent: true,
@@ -652,8 +693,7 @@ impl Canceled {
652
693
  } else {
653
694
  TransitionResult::Err(WFMachinesError::Nondeterminism(format!(
654
695
  "Non-Abandon cancel mode activities cannot be started after being cancelled. \
655
- Seq: {:?}",
656
- seq_num
696
+ Seq: {seq_num:?}"
657
697
  )))
658
698
  }
659
699
  }
@@ -667,8 +707,7 @@ impl Canceled {
667
707
  TransitionResult::default()
668
708
  } else {
669
709
  TransitionResult::Err(WFMachinesError::Nondeterminism(format!(
670
- "Non-Abandon cancel mode activities cannot be completed after being cancelled: {:?}",
671
- attrs
710
+ "Non-Abandon cancel mode activities cannot be completed after being cancelled: {attrs:?}"
672
711
  )))
673
712
  }
674
713
  }
@@ -773,8 +812,7 @@ fn convert_payloads(
773
812
  ) -> Result<Option<Payload>, WFMachinesError> {
774
813
  result.map(TryInto::try_into).transpose().map_err(|pe| {
775
814
  WFMachinesError::Fatal(format!(
776
- "Not exactly one payload in activity result ({}) for event: {:?}",
777
- pe, event_info
815
+ "Not exactly one payload in activity result ({pe}) for event: {event_info:?}"
778
816
  ))
779
817
  })
780
818
  }
@@ -783,15 +821,17 @@ fn convert_payloads(
783
821
  mod test {
784
822
  use super::*;
785
823
  use crate::{
786
- replay::TestHistoryBuilder, test_help::canned_histories, worker::workflow::ManagedWFFunc,
824
+ internal_flags::InternalFlags, replay::TestHistoryBuilder, test_help::canned_histories,
825
+ worker::workflow::ManagedWFFunc,
787
826
  };
788
827
  use rstest::{fixture, rstest};
789
- use std::mem::discriminant;
828
+ use std::{cell::RefCell, mem::discriminant, rc::Rc};
790
829
  use temporal_sdk::{
791
830
  ActivityOptions, CancellableFuture, WfContext, WorkflowFunction, WorkflowResult,
792
831
  };
793
- use temporal_sdk_core_protos::coresdk::workflow_activation::{
794
- workflow_activation_job, WorkflowActivationJob,
832
+ use temporal_sdk_core_protos::{
833
+ coresdk::workflow_activation::{workflow_activation_job, WorkflowActivationJob},
834
+ DEFAULT_ACTIVITY_TYPE,
795
835
  };
796
836
 
797
837
  #[fixture]
@@ -811,7 +851,13 @@ mod test {
811
851
  }
812
852
 
813
853
  async fn activity_wf(command_sink: WfContext) -> WorkflowResult<()> {
814
- command_sink.activity(ActivityOptions::default()).await;
854
+ command_sink
855
+ .activity(ActivityOptions {
856
+ activity_id: Some("activity-id-1".to_string()),
857
+ activity_type: DEFAULT_ACTIVITY_TYPE.to_string(),
858
+ ..Default::default()
859
+ })
860
+ .await;
815
861
  Ok(().into())
816
862
  }
817
863
 
@@ -901,7 +947,14 @@ mod test {
901
947
  ] {
902
948
  let mut s = ActivityMachine {
903
949
  state: state.clone(),
904
- shared_state: Default::default(),
950
+ shared_state: SharedState {
951
+ scheduled_event_id: 0,
952
+ started_event_id: 0,
953
+ attrs: Default::default(),
954
+ cancellation_type: Default::default(),
955
+ cancelled_before_sent: false,
956
+ internal_flags: Rc::new(RefCell::new(InternalFlags::new(&Default::default()))),
957
+ },
905
958
  };
906
959
  let cmds = s.cancel().unwrap();
907
960
  assert_eq!(cmds.len(), 0);
@@ -1,7 +1,8 @@
1
1
  use super::{
2
- workflow_machines::MachineResponse, Cancellable, EventInfo, MachineKind, NewMachineWithCommand,
2
+ workflow_machines::MachineResponse, Cancellable, EventInfo, NewMachineWithCommand,
3
3
  OnEventWrapper, WFMachinesAdapter, WFMachinesError,
4
4
  };
5
+ use crate::worker::workflow::machines::HistEventData;
5
6
  use rustfsm::{fsm, TransitionResult};
6
7
  use std::convert::TryFrom;
7
8
  use temporal_sdk_core_protos::{
@@ -145,10 +146,11 @@ impl TryFrom<CommandType> for CancelExternalMachineEvents {
145
146
  }
146
147
  }
147
148
 
148
- impl TryFrom<HistoryEvent> for CancelExternalMachineEvents {
149
+ impl TryFrom<HistEventData> for CancelExternalMachineEvents {
149
150
  type Error = WFMachinesError;
150
151
 
151
- fn try_from(e: HistoryEvent) -> Result<Self, Self::Error> {
152
+ fn try_from(e: HistEventData) -> Result<Self, Self::Error> {
153
+ let e = e.event;
152
154
  Ok(match e.event_type() {
153
155
  EventType::ExternalWorkflowExecutionCancelRequested => {
154
156
  Self::ExternalWorkflowExecutionCancelRequested
@@ -161,15 +163,13 @@ impl TryFrom<HistoryEvent> for CancelExternalMachineEvents {
161
163
  Self::RequestCancelExternalWorkflowExecutionFailed(attrs.cause())
162
164
  } else {
163
165
  return Err(WFMachinesError::Fatal(format!(
164
- "Cancelworkflow failed attributes were unset: {}",
165
- e
166
+ "Cancelworkflow failed attributes were unset: {e}"
166
167
  )));
167
168
  }
168
169
  }
169
170
  _ => {
170
171
  return Err(WFMachinesError::Nondeterminism(format!(
171
- "Cancel external WF machine does not handle this event: {}",
172
- e
172
+ "Cancel external WF machine does not handle this event: {e}"
173
173
  )))
174
174
  }
175
175
  })
@@ -199,7 +199,7 @@ impl WFMachinesAdapter for CancelExternalMachine {
199
199
  vec![ResolveRequestCancelExternalWorkflow {
200
200
  seq: self.shared_state.seq,
201
201
  failure: Some(Failure {
202
- message: format!("Unable to cancel external workflow because {}", reason),
202
+ message: format!("Unable to cancel external workflow because {reason}"),
203
203
  failure_info: Some(FailureInfo::ApplicationFailureInfo(
204
204
  ApplicationFailureInfo {
205
205
  r#type: f.to_string(),
@@ -222,10 +222,6 @@ impl WFMachinesAdapter for CancelExternalMachine {
222
222
  | EventType::RequestCancelExternalWorkflowExecutionInitiated
223
223
  )
224
224
  }
225
-
226
- fn kind(&self) -> MachineKind {
227
- MachineKind::CancelExternalWorkflow
228
- }
229
225
  }
230
226
 
231
227
  impl Cancellable for CancelExternalMachine {}
@@ -1,7 +1,8 @@
1
1
  use super::{
2
- workflow_machines::MachineResponse, Cancellable, EventInfo, HistoryEvent, MachineKind,
2
+ workflow_machines::MachineResponse, Cancellable, EventInfo, HistoryEvent,
3
3
  NewMachineWithCommand, OnEventWrapper, WFMachinesAdapter, WFMachinesError,
4
4
  };
5
+ use crate::worker::workflow::machines::HistEventData;
5
6
  use rustfsm::{fsm, TransitionResult};
6
7
  use std::convert::TryFrom;
7
8
  use temporal_sdk_core_protos::{
@@ -72,16 +73,16 @@ impl Created {
72
73
  }
73
74
  }
74
75
 
75
- impl TryFrom<HistoryEvent> for CancelWorkflowMachineEvents {
76
+ impl TryFrom<HistEventData> for CancelWorkflowMachineEvents {
76
77
  type Error = WFMachinesError;
77
78
 
78
- fn try_from(e: HistoryEvent) -> Result<Self, Self::Error> {
79
+ fn try_from(e: HistEventData) -> Result<Self, Self::Error> {
80
+ let e = e.event;
79
81
  Ok(match EventType::from_i32(e.event_type) {
80
82
  Some(EventType::WorkflowExecutionCanceled) => Self::WorkflowExecutionCanceled,
81
83
  _ => {
82
84
  return Err(WFMachinesError::Nondeterminism(format!(
83
- "Cancel workflow machine does not handle this event: {}",
84
- e
85
+ "Cancel workflow machine does not handle this event: {e}"
85
86
  )))
86
87
  }
87
88
  })
@@ -111,10 +112,6 @@ impl WFMachinesAdapter for CancelWorkflowMachine {
111
112
  fn matches_event(&self, event: &HistoryEvent) -> bool {
112
113
  event.event_type() == EventType::WorkflowExecutionCanceled
113
114
  }
114
-
115
- fn kind(&self) -> MachineKind {
116
- MachineKind::CancelWorkflow
117
- }
118
115
  }
119
116
 
120
117
  impl Cancellable for CancelWorkflowMachine {}
@@ -1,7 +1,11 @@
1
1
  use super::{
2
- workflow_machines::MachineResponse, Cancellable, EventInfo, MachineKind, NewMachineWithCommand,
2
+ workflow_machines::MachineResponse, Cancellable, EventInfo, NewMachineWithCommand,
3
3
  OnEventWrapper, WFMachinesAdapter, WFMachinesError,
4
4
  };
5
+ use crate::{
6
+ internal_flags::CoreInternalFlags,
7
+ worker::workflow::{machines::HistEventData, InternalFlagsRef},
8
+ };
5
9
  use rustfsm::{fsm, MachineError, TransitionResult};
6
10
  use std::convert::{TryFrom, TryInto};
7
11
  use temporal_sdk_core_protos::{
@@ -41,7 +45,7 @@ fsm! {
41
45
 
42
46
  Created --(Schedule, on_schedule) --> StartCommandCreated;
43
47
  StartCommandCreated --(CommandStartChildWorkflowExecution) --> StartCommandCreated;
44
- StartCommandCreated --(StartChildWorkflowExecutionInitiated(i64),
48
+ StartCommandCreated --(StartChildWorkflowExecutionInitiated(ChildWorkflowInitiatedData),
45
49
  shared on_start_child_workflow_execution_initiated) --> StartEventRecorded;
46
50
  StartCommandCreated --(Cancel, shared on_cancelled) --> Cancelled;
47
51
 
@@ -71,6 +75,7 @@ fsm! {
71
75
  // Ignore any spurious cancellations after resolution
72
76
  Cancelled --(Cancel) --> Cancelled;
73
77
  Failed --(Cancel) --> Failed;
78
+ StartFailed --(Cancel) --> StartFailed;
74
79
  TimedOut --(Cancel) --> TimedOut;
75
80
  Completed --(Cancel) --> Completed;
76
81
  }
@@ -98,6 +103,13 @@ pub(super) enum ChildWorkflowCommand {
98
103
  IssueCancelAfterStarted { reason: String },
99
104
  }
100
105
 
106
+ pub(super) struct ChildWorkflowInitiatedData {
107
+ event_id: i64,
108
+ wf_type: String,
109
+ wf_id: String,
110
+ last_task_in_history: bool,
111
+ }
112
+
101
113
  #[derive(Default, Clone)]
102
114
  pub(super) struct Cancelled {}
103
115
 
@@ -123,13 +135,32 @@ impl StartCommandCreated {
123
135
  pub(super) fn on_start_child_workflow_execution_initiated(
124
136
  self,
125
137
  state: SharedState,
126
- initiated_event_id: i64,
138
+ event_dat: ChildWorkflowInitiatedData,
127
139
  ) -> ChildWorkflowMachineTransition<StartEventRecorded> {
140
+ if state.internal_flags.borrow_mut().try_use(
141
+ CoreInternalFlags::IdAndTypeDeterminismChecks,
142
+ event_dat.last_task_in_history,
143
+ ) {
144
+ if event_dat.wf_id != state.workflow_id {
145
+ return TransitionResult::Err(WFMachinesError::Nondeterminism(format!(
146
+ "Child workflow id of scheduled event '{}' does not \
147
+ match child workflow id of activity command '{}'",
148
+ event_dat.wf_id, state.workflow_id
149
+ )));
150
+ }
151
+ if event_dat.wf_type != state.workflow_type {
152
+ return TransitionResult::Err(WFMachinesError::Nondeterminism(format!(
153
+ "Child workflow type of scheduled event '{}' does not \
154
+ match child workflow type of activity command '{}'",
155
+ event_dat.wf_type, state.workflow_type
156
+ )));
157
+ }
158
+ }
128
159
  ChildWorkflowMachineTransition::ok_shared(
129
160
  vec![],
130
161
  StartEventRecorded::default(),
131
162
  SharedState {
132
- initiated_event_id,
163
+ initiated_event_id: event_dat.event_id,
133
164
  ..state
134
165
  },
135
166
  )
@@ -298,7 +329,7 @@ pub(super) struct Terminated {}
298
329
  #[derive(Default, Clone)]
299
330
  pub(super) struct TimedOut {}
300
331
 
301
- #[derive(Default, Clone, Debug)]
332
+ #[derive(Clone, Debug)]
302
333
  pub(super) struct SharedState {
303
334
  initiated_event_id: i64,
304
335
  started_event_id: i64,
@@ -309,20 +340,15 @@ pub(super) struct SharedState {
309
340
  workflow_type: String,
310
341
  cancelled_before_sent: bool,
311
342
  cancel_type: ChildWorkflowCancellationType,
312
- }
313
-
314
- /// Creates a new child workflow state machine and a command to start it on the server.
315
- pub(super) fn new_child_workflow(attribs: StartChildWorkflowExecution) -> NewMachineWithCommand {
316
- let (wf, add_cmd) = ChildWorkflowMachine::new_scheduled(attribs);
317
- NewMachineWithCommand {
318
- command: add_cmd,
319
- machine: wf.into(),
320
- }
343
+ internal_flags: InternalFlagsRef,
321
344
  }
322
345
 
323
346
  impl ChildWorkflowMachine {
324
347
  /// Create a new child workflow and immediately schedule it.
325
- pub(crate) fn new_scheduled(attribs: StartChildWorkflowExecution) -> (Self, Command) {
348
+ pub(super) fn new_scheduled(
349
+ attribs: StartChildWorkflowExecution,
350
+ internal_flags: InternalFlagsRef,
351
+ ) -> NewMachineWithCommand {
326
352
  let mut s = Self {
327
353
  state: Created {}.into(),
328
354
  shared_state: SharedState {
@@ -331,7 +357,11 @@ impl ChildWorkflowMachine {
331
357
  workflow_type: attribs.workflow_type.clone(),
332
358
  namespace: attribs.namespace.clone(),
333
359
  cancel_type: attribs.cancellation_type(),
334
- ..Default::default()
360
+ internal_flags,
361
+ run_id: "".to_string(),
362
+ initiated_event_id: 0,
363
+ started_event_id: 0,
364
+ cancelled_before_sent: false,
335
365
  },
336
366
  };
337
367
  OnEventWrapper::on_event_mut(&mut s, ChildWorkflowMachineEvents::Schedule)
@@ -340,7 +370,10 @@ impl ChildWorkflowMachine {
340
370
  command_type: CommandType::StartChildWorkflowExecution as i32,
341
371
  attributes: Some(attribs.into()),
342
372
  };
343
- (s, cmd)
373
+ NewMachineWithCommand {
374
+ command: cmd,
375
+ machine: s.into(),
376
+ }
344
377
  }
345
378
 
346
379
  fn resolve_cancelled_msg(&self) -> ResolveChildWorkflowExecution {
@@ -371,13 +404,31 @@ impl ChildWorkflowMachine {
371
404
  }
372
405
  }
373
406
 
374
- impl TryFrom<HistoryEvent> for ChildWorkflowMachineEvents {
407
+ impl TryFrom<HistEventData> for ChildWorkflowMachineEvents {
375
408
  type Error = WFMachinesError;
376
409
 
377
- fn try_from(e: HistoryEvent) -> Result<Self, Self::Error> {
410
+ fn try_from(e: HistEventData) -> Result<Self, Self::Error> {
411
+ let last_task_in_history = e.current_task_is_last_in_history;
412
+ let e = e.event;
378
413
  Ok(match EventType::from_i32(e.event_type) {
379
414
  Some(EventType::StartChildWorkflowExecutionInitiated) => {
380
- Self::StartChildWorkflowExecutionInitiated(e.event_id)
415
+ if let Some(
416
+ history_event::Attributes::StartChildWorkflowExecutionInitiatedEventAttributes(
417
+ attrs,
418
+ ),
419
+ ) = e.attributes
420
+ {
421
+ Self::StartChildWorkflowExecutionInitiated(ChildWorkflowInitiatedData {
422
+ event_id: e.event_id,
423
+ wf_type: attrs.workflow_type.unwrap_or_default().name,
424
+ wf_id: attrs.workflow_id,
425
+ last_task_in_history,
426
+ })
427
+ } else {
428
+ return Err(WFMachinesError::Fatal(
429
+ "StartChildWorkflowExecutionInitiated attributes were unset".to_string(),
430
+ ));
431
+ }
381
432
  }
382
433
  Some(EventType::StartChildWorkflowExecutionFailed) => {
383
434
  if let Some(
@@ -470,8 +521,7 @@ impl TryFrom<HistoryEvent> for ChildWorkflowMachineEvents {
470
521
  }
471
522
  _ => {
472
523
  return Err(WFMachinesError::Fatal(format!(
473
- "Child workflow machine does not handle this event: {:?}",
474
- e
524
+ "Child workflow machine does not handle this event: {e:?}"
475
525
  )))
476
526
  }
477
527
  })
@@ -584,10 +634,6 @@ impl WFMachinesAdapter for ChildWorkflowMachine {
584
634
  | EventType::ChildWorkflowExecutionCanceled
585
635
  )
586
636
  }
587
-
588
- fn kind(&self) -> MachineKind {
589
- MachineKind::ChildWorkflow
590
- }
591
637
  }
592
638
 
593
639
  impl TryFrom<CommandType> for ChildWorkflowMachineEvents {
@@ -615,7 +661,7 @@ impl Cancellable for ChildWorkflowMachine {
615
661
  | c @ ChildWorkflowCommand::IssueCancelAfterStarted { .. } => {
616
662
  self.adapt_response(c, None)
617
663
  }
618
- x => panic!("Invalid cancel event response {:?}", x),
664
+ x => panic!("Invalid cancel event response {x:?}"),
619
665
  })
620
666
  .collect::<Result<Vec<_>, _>>()?
621
667
  .into_iter()
@@ -653,8 +699,7 @@ fn convert_payloads(
653
699
  ) -> Result<Option<Payload>, WFMachinesError> {
654
700
  result.map(TryInto::try_into).transpose().map_err(|pe| {
655
701
  WFMachinesError::Fatal(format!(
656
- "Not exactly one payload in child workflow result ({}) for event: {:?}",
657
- pe, event_info
702
+ "Not exactly one payload in child workflow result ({pe}) for event: {event_info:?}"
658
703
  ))
659
704
  })
660
705
  }
@@ -663,11 +708,12 @@ fn convert_payloads(
663
708
  mod test {
664
709
  use super::*;
665
710
  use crate::{
666
- replay::TestHistoryBuilder, test_help::canned_histories, worker::workflow::ManagedWFFunc,
711
+ internal_flags::InternalFlags, replay::TestHistoryBuilder, test_help::canned_histories,
712
+ worker::workflow::ManagedWFFunc,
667
713
  };
668
714
  use anyhow::anyhow;
669
715
  use rstest::{fixture, rstest};
670
- use std::mem::discriminant;
716
+ use std::{cell::RefCell, mem::discriminant, rc::Rc};
671
717
  use temporal_sdk::{
672
718
  CancellableFuture, ChildWorkflowOptions, WfContext, WorkflowFunction, WorkflowResult,
673
719
  };
@@ -845,12 +891,24 @@ mod test {
845
891
  for state in [
846
892
  ChildWorkflowMachineState::Cancelled(Cancelled {}),
847
893
  Failed {}.into(),
894
+ StartFailed {}.into(),
848
895
  TimedOut {}.into(),
849
896
  Completed {}.into(),
850
897
  ] {
851
898
  let mut s = ChildWorkflowMachine {
852
899
  state: state.clone(),
853
- shared_state: Default::default(),
900
+ shared_state: SharedState {
901
+ initiated_event_id: 0,
902
+ started_event_id: 0,
903
+ lang_sequence_number: 0,
904
+ namespace: "".to_string(),
905
+ workflow_id: "".to_string(),
906
+ run_id: "".to_string(),
907
+ workflow_type: "".to_string(),
908
+ cancelled_before_sent: false,
909
+ cancel_type: Default::default(),
910
+ internal_flags: Rc::new(RefCell::new(InternalFlags::new(&Default::default()))),
911
+ },
854
912
  };
855
913
  let cmds = s.cancel().unwrap();
856
914
  assert_eq!(cmds.len(), 0);