Repository navigation
temporal-ruby SDK: Add support for next_retry_delay in Activity errors to more intelligently back off activity retries #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2ac619e
Add opt-in Activity retry delay metadata
kstewartfigma abeeff1
Match first-party retry delay rounding
kstewartfigma 67e8ded
fix(ci): run SDK tests on Ruby 3.4
kstewartfigma b21db9a
Merge master and preserve retry-delay protobuf backport
kstewartfigma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Per-failure retry delay parity | ||
|
|
||
| The first-party Ruby SDK reference is [`temporalio/sdk-ruby` at `2169e3e0dc2b4f59dbf9cc93205e19c2c01a037e`](https://github.com/temporalio/sdk-ruby/tree/2169e3e0dc2b4f59dbf9cc93205e19c2c01a037e). Its [Activity failure test](https://github.com/temporalio/sdk-ruby/blob/2169e3e0dc2b4f59dbf9cc93205e19c2c01a037e/temporalio/test/worker_activity_test.rb#L200-L251) sets a fractional `next_retry_delay: 1.23` on a non-retryable `ApplicationError` and checks that the client receives its message, type, details, non-retryable flag, and retry delay. That test proves metadata round-trip; its non-retryable setting means it does not verify a scheduled retry. The [first-party failure converter](https://github.com/temporalio/sdk-ruby/blob/2169e3e0dc2b4f59dbf9cc93205e19c2c01a037e/temporalio/lib/temporalio/converters/failure_converter.rb#L40-L54) writes the delay to `ApplicationFailureInfo`; [deserialization](https://github.com/temporalio/sdk-ruby/blob/2169e3e0dc2b4f59dbf9cc93205e19c2c01a037e/temporalio/lib/temporalio/converters/failure_converter.rb#L140-L154) restores it. The [wire field](https://github.com/temporalio/api/blob/v1.44.0/temporal/api/failure/v1/message.proto) is field 4, a protobuf `Duration`. | ||
|
|
||
| | First-party behavior or boundary | This fork's coverage | | ||
| | --- | --- | | ||
| | Fractional delay survives serialization and deserialization | `failure_spec.rb`: `preserves a fractional retry delay...` runs for both legacy and v2 exception serialization, checks seconds/nanos, original class, message, and reconstructed delay. | | ||
| | Original error type, details, and stack trace survive as appropriate to converter mode | Existing `failure_spec.rb` full/legacy/fallback cases and `workflow/errors_spec.rb` reconstruction cases remain in the focused suite. New fractional cases assert class and message for both modes. | | ||
| | Retry-delay metadata remains available when the original class is not installed on the reader | `workflow/errors_spec.rb`: `retains a retry delay when the original error class is unavailable`. This is specific to the fork's class-based reconstruction. | | ||
| | Server schedules the next remote Activity attempt using the override, instead of the retry policy interval | `spec/integration/retry_delay_spec.rb` inspects `DescribeWorkflowExecution` pending failure for the fractional field and waits for the second actual Activity attempt; policy interval and maximum interval are 1 second, while the override is 2.3 seconds. Run with `TEMPORAL_TEST_PORT` against an isolated Temporal server. | | ||
| | Inbound delay `0` is distinct from an absent override | `failure_spec.rb`: `preserves an inbound zero delay without emitting one by default` also reserializes the restored error without an invalid override. The [first-party converter](https://github.com/temporalio/sdk-ruby/blob/2169e3e0dc2b4f59dbf9cc93205e19c2c01a037e/temporalio/lib/temporalio/internal/proto_utils.rb#L8-L20) preserves zero. This fork reads it for interoperability but does not emit it on re-raise because Temporal Server 1.32 treats a zero custom delay as a retry timeout. | | ||
| | Ordinary errors remain retryable without an opt-in delay | `failure_spec.rb`: `does not infer an override...`; existing ordinary error tests. Only exceptions including `Temporal::RetryDelay` emit the field. | | ||
| | Invalid inputs cannot create malformed duration or silently lose Activity failure reports | `failure_spec.rb`: `rejects invalid delay values before an error can be raised`. Setter rejects zero, sub-nanosecond, negative, non-finite, non-real, non-numeric, and out-of-range values; valid fractional values serialize at nanosecond precision. | | ||
| | Retry caps and total timeouts still apply | The [Temporal retry-policy contract](https://docs.temporal.io/encyclopedia/retry-policies#per-error-next-retry-delay) states the override replaces the interval while limits remain in force. The SDK sends an ordinary `ApplicationFailureInfo` with the additional duration; server owns enforcement. The integration test uses `max_attempts: 2` and checks exactly two attempts. | | ||
| | First-party non-retryable flag, arbitrary `ApplicationError` details, and cause chain | This fork keeps its existing class-based non-retriable policy and legacy/v2 exception payload behavior. Adding a separate ApplicationError wrapper or per-instance non-retryable API is outside this retry-delay change. The first-party test's non-retryable flag is used to terminate promptly, not to test retry scheduling. | | ||
| | First-party Go local Activity delay tests | [Go `ErrorWithNextDelay`](https://github.com/temporalio/sdk-go/blob/733b222690ef005e9cb09e684a11372fe7241a68/test/activity_test.go#L70) and [local Activity test](https://github.com/temporalio/sdk-go/blob/733b222690ef005e9cb09e684a11372fe7241a68/test/workflow_test.go#L90) exercise local Activities, which this fork does not implement. They are not a direct remote Activity parity test. | | ||
|
|
||
| This table maps behaviors, not raw test counts. The live integration assertion is required to claim server scheduling behavior; a skipped test only establishes that the test harness is present. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #!/usr/bin/env ruby | ||
| # Restore the additive next_retry_delay field after regenerating the pinned API proto. | ||
|
|
||
| require 'google/protobuf/descriptor_pb' | ||
|
|
||
| path = File.expand_path('../lib/gen/temporal/api/failure/v1/message_pb.rb', __dir__) | ||
| source = File.read(path) | ||
| match = source.match(/^descriptor_data = (".*")$/) | ||
| raise 'Unexpected generated failure descriptor' unless match | ||
|
|
||
| descriptor = Google::Protobuf::FileDescriptorProto.decode(match[1].undump) | ||
| raise 'Unexpected failure proto' unless descriptor.name == 'temporal/api/failure/v1/message.proto' | ||
| application = descriptor.message_type.find { |message| message.name == 'ApplicationFailureInfo' } | ||
| raise 'Missing ApplicationFailureInfo' unless application | ||
| field = application.field.find { |item| item.name == 'next_retry_delay' } | ||
| if field | ||
| raise 'Unexpected next_retry_delay field' unless field.number == 4 && field.type_name == '.google.protobuf.Duration' | ||
| exit 0 | ||
| end | ||
| raise 'Field 4 is occupied' if application.field.any? { |item| item.number == 4 } | ||
| raise 'Duration already imported' if descriptor.dependency.include?('google/protobuf/duration.proto') | ||
|
|
||
| application.field << Google::Protobuf::FieldDescriptorProto.new( | ||
| name: 'next_retry_delay', number: 4, | ||
| label: :LABEL_OPTIONAL, type: :TYPE_MESSAGE, type_name: '.google.protobuf.Duration' | ||
| ) | ||
| descriptor.dependency << 'google/protobuf/duration.proto' | ||
| source.sub!(match[0]) { "descriptor_data = #{Google::Protobuf::FileDescriptorProto.encode(descriptor).dump}" } | ||
| old_require = "require 'temporal/api/enums/v1/workflow_pb'" | ||
| raise 'Unexpected generated failure imports' unless source.scan(old_require).size == 1 | ||
| source.sub!(old_require, "#{old_require}\nrequire 'google/protobuf/duration_pb'") | ||
| File.write(path, source) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.