Make Temporal wait a model error's `retry_after` before retrying the model request activity
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_afternow raises itsApplicationErrorwithnext_retry_delay=timedelta(seconds=retry_after). Temporal waits that long before the next attempt, and the retry policy'smaximum_attemptsstill applies. - Non-retryable errors. An error listed in
non_retryable_model_errorsisn'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
ApplicationErrorwhen it has aretry_after, so the delay applies. Itstypeis its own class name, as before. - Docs.
temporal.md"Activity Retries" says that Temporal waits the error'sretry_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 withretry_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 seesnext_retry_delay == 1son the error'sApplicationError. Onmain, theApplicationErrorhas 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