From 31ae59773ae8f932160e2f99e591a1db140998c6 Mon Sep 17 00:00:00 2001 From: Maciej Dudkowski Date: Mon, 15 Sep 2025 14:26:12 -0400 Subject: [PATCH] Added first_execution_run_id to Workflow::Info --- .../lib/temporalio/internal/worker/workflow_instance.rb | 1 + temporalio/lib/temporalio/workflow/info.rb | 3 +++ temporalio/sig/temporalio/workflow/info.rbs | 2 ++ temporalio/test/worker_workflow_test.rb | 5 +++++ 4 files changed, 11 insertions(+) diff --git a/temporalio/lib/temporalio/internal/worker/workflow_instance.rb b/temporalio/lib/temporalio/internal/worker/workflow_instance.rb index 2eba80cd..92e8f81d 100644 --- a/temporalio/lib/temporalio/internal/worker/workflow_instance.rb +++ b/temporalio/lib/temporalio/internal/worker/workflow_instance.rb @@ -125,6 +125,7 @@ def initialize(details) continued_run_id: ProtoUtils.string_or(@init_job.continued_from_execution_run_id), cron_schedule: ProtoUtils.string_or(@init_job.cron_schedule), execution_timeout: ProtoUtils.duration_to_seconds(@init_job.workflow_execution_timeout), + first_execution_run_id: @init_job.first_execution_run_id, headers: ProtoUtils.headers_from_proto_map(@init_job.headers, @payload_converter) || {}, last_failure: if @init_job.continued_failure @failure_converter.from_failure(@init_job.continued_failure, @payload_converter) diff --git a/temporalio/lib/temporalio/workflow/info.rb b/temporalio/lib/temporalio/workflow/info.rb index 9280f084..6cc6d4fe 100644 --- a/temporalio/lib/temporalio/workflow/info.rb +++ b/temporalio/lib/temporalio/workflow/info.rb @@ -7,6 +7,7 @@ module Workflow :continued_run_id, :cron_schedule, :execution_timeout, + :first_execution_run_id, :headers, :last_failure, :last_result, @@ -35,6 +36,8 @@ module Workflow # @return [String, nil] Cron schedule if applicable. # @!attribute execution_timeout # @return [Float, nil] Execution timeout for the workflow. + # @!attribute first_execution_run_id + # @return [String] The very first run ID the workflow ever had, following continuation chains. # @!attribute headers # @return [Hash] Headers. # @!attribute last_failure diff --git a/temporalio/sig/temporalio/workflow/info.rbs b/temporalio/sig/temporalio/workflow/info.rbs index 0a719209..596a92ab 100644 --- a/temporalio/sig/temporalio/workflow/info.rbs +++ b/temporalio/sig/temporalio/workflow/info.rbs @@ -5,6 +5,7 @@ module Temporalio attr_reader continued_run_id: String? attr_reader cron_schedule: String? attr_reader execution_timeout: Float? + attr_reader first_execution_run_id: String attr_reader headers: Hash[String, untyped] attr_reader last_failure: Exception? attr_reader last_result: Object? @@ -26,6 +27,7 @@ module Temporalio continued_run_id: String?, cron_schedule: String?, execution_timeout: Float?, + first_execution_run_id: String, headers: Hash[String, untyped], last_failure: Exception?, last_result: Object?, diff --git a/temporalio/test/worker_workflow_test.rb b/temporalio/test/worker_workflow_test.rb index b0a7d423..e1b69f6d 100644 --- a/temporalio/test/worker_workflow_test.rb +++ b/temporalio/test/worker_workflow_test.rb @@ -4,6 +4,7 @@ require 'gc_utils' require 'net/http' require 'temporalio/client' +require 'temporalio/error' require 'temporalio/testing' require 'temporalio/worker' require 'temporalio/workflow' @@ -542,6 +543,10 @@ def execute(past_run_ids) return past_run_ids if past_run_ids.size == 5 past_run_ids << Temporalio::Workflow.info.continued_run_id if Temporalio::Workflow.info.continued_run_id + if !past_run_ids.empty? && Temporalio::Workflow.info.first_execution_run_id != past_run_ids.first + raise Temporalio::Error::ApplicationError.new('wrong first_execution_run_id', non_retryable: true) + end + raise Temporalio::Workflow::ContinueAsNewError.new( past_run_ids, memo: { past_run_id_count: past_run_ids.size },