Skip to content

temporal-ruby SDK: Add support for next_retry_delay in Activity errors to more intelligently back off activity retries - #7

Open
kstewartfigma wants to merge 3 commits into
masterfrom
kstewart/ruby-activity-retry-delay
Open

kstewartfigma wants to merge 3 commits into
masterfrom
kstewart/ruby-activity-retry-delay

Conversation

@kstewartfigma

@kstewartfigma kstewartfigma commented Oct 9, 2026 •

Copy link
Copy Markdown

Written with AI

Description

Activities can opt into specifying a particular retry delay when an external service supplies Retry-After. An exception class includes Temporal::RetryDelay, sets next_retry_delay in seconds, and keeps its original class and exception payload across legacy and v2 serialization. The delay replaces the retry interval; Temporal still enforces maximum attempts and timeouts.

Outbound delays must be at least 1 nanosecond because Temporal Server 1.32 treats a zero custom delay as a retry timeout. Historical inbound zero delays remain readable and are omitted if the error is raised again.

Changes

  • Backport ApplicationFailureInfo.next_retry_delay onto the pinned API descriptor with an idempotent Ruby script run by make proto.

  • Serialize and reconstruct opted-in error metadata while leaving ordinary exceptions unchanged.

  • Add unit and opt-in live server coverage, API documentation, and a first-party parity map against the pinned official Ruby SDK revision.

  • Run CI on Ruby 3.4 to satisfy the existing protobuf dependency. Explicitly load OpenStruct in test setup, pass replay-fixture inputs as a positional hash, and accept qualified Ruby 3.4 method names in stack-trace assertions.

Test Plan

November 16 validation on Coder, Ruby 3.4.7, with isolated freshly resolved dependencies (protobuf 4.33.6, gRPC 1.85.0, Fabrication 3.0.0, RSpec 3.10):

  • bundle exec rspec: 653 examples, 0 failures, 1 pending. The pending test is the opt-in live retry-delay spec requiring TEMPORAL_TEST_PORT; it was not enabled in this run.
  • Full examples/ suite with CI's Temporal Server 1.22.0, Cassandra 3.11, and the general, encryption, and v2-error workers: 91 examples, 0 failures.
  • Includes the fractional duration regression added in abeeff1: combine seconds and nanoseconds before converting to Float, matching the first-party SDK.
  • CI workflow YAML parses and both jobs select Ruby 3.4; git diff --check passes.
  • Fresh-context independent Sol 6.1 / high review of the five-file CI repair: no actionable findings. Runtime SDK files are unchanged by that repair.

The failed previous CI run stopped during dependency resolution: Ruby 3.0.3 could not install the existing protobuf 4.33 dependency, which requires Ruby >=3.1. After upgrading the runtime, the test-fixture fixes also resolve the previously recorded replay/stack-trace failures and the missing OpenStruct load.

Earlier live contract and generation validation

On October 19, the original feature head 2ac619e4b6126918b45462e529862a558cbc1c91 passed its live retry-delay integration test against Temporal Server 1.32.0 on Coder. It verified failure metadata seconds=2/nanos=300000000, a 2.3-second custom delay overriding a one-second policy maximum, exactly two activity attempts, and preservation of the error class, message, and delay. Bundled make proto ran twice with pinned submodule ae312b0724003957b96fb966e3fe25a02abaade4 and exactly reproduced the committed generated files. These results supersede the earlier authentication/macOS tooling blockers.

Limits: the live 1.32 contract test and protobuf regeneration were not rerun for the subsequent rounding and CI-only changes. The hosted Ruby 3.4 patch can differ from Coder's 3.4.7; the new GitHub run validates that environment. The 1.22 example suite does not establish support for the new retry-delay server feature.

@kstewartfigma
kstewartfigma requested review from a team, adirar-figma and yfang-figma and removed request for a team October 30, 2026 23:08
@kstewartfigma kstewartfigma changed the title temporal: Add opt-in Activity retry delays temporal-ruby SDK: Add support for next_retry_delay in Activity errors to more intelligently back off activity retries Oct 30, 2026
@kstewartfigma
kstewartfigma marked this pull request as ready for review October 30, 2026 23:10
Comment thread lib/temporal/workflow/errors.rb Outdated
if retry_delay
# Older failures may carry zero; preserve their metadata without applying outbound validation.
Temporal::RetryDelay.restore(exception,
retry_delay.seconds + retry_delay.nanos.quo(1_000_000_000).to_f)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI suggested that this is different than (retry_delay.seconds + retry_delay.nanos.quo(1_000_000_000)).to_f which is used in the first party sdk, https://github.com/temporalio/sdk-ruby/blob/3aa06a665402e340100b64890143ba966a49a536/temporalio/lib/temporalio/internal/proto_utils.rb#L16-L24.
Let's keep them consistent?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants