Make Temporal wait a model error's `retry_after` before retrying the model request activity

Merged
DO
1mo ago
+159-4

No issue: found while auditing how errors are retried under durable execution.

Under TemporalDurability, a model request activity raises a model error as an ApplicationError, so the workflow can rebuild the error as its own class. The error's retry_after, read from the provider's Retry-After or retry-after-ms header, wasn't carried onto it. So Temporal retried a rate-limited request on its retry policy's backoff, which by default first waits 1 second, rather than waiting as long as the provider asked.

What changed

  • Retry delay. A retryable model error with a retry_after now raises its ApplicationError with next_retry_delay=timedelta(seconds=retry_after). Temporal waits that long before the next attempt, and the retry policy's maximum_attempts still applies.
  • Non-retryable errors. An error listed in non_retryable_model_errors isn't retried, so it gets no delay.
  • Errors that can't be rebuilt. A model error the workflow can't rebuild, like an application-defined subclass, used to be re-raised as is. It's now also raised as an ApplicationError when it has a retry_after, so the delay applies. Its type is its own class name, as before.
  • Docs. temporal.md "Activity Retries" says that Temporal waits the error's retry_after.

Behavior change

A model activity that fails with a retry_after is retried after that delay, not after the retry policy's backoff. That's what the provider asked for. For a long Retry-After, the run waits longer before its next attempt; ModelSettings['request_timeout'] still bounds the request as a workflow timer.

Tests

  • Delay is honoured (test_durability.py): a model raises a 429 with retry_after=1.0, under a 2-attempt policy with a 10 ms initial interval. The second attempt now starts at least 1 second after the first, and the workflow sees next_retry_delay == 1s on the error's ApplicationError. On main, the ApplicationError has no delay and the second attempt comes after the 10 ms backoff.

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
  • PR title is fit for the release changelog.

šŸ¤– Generated with Claude Code