Stop Temporal from retrying model errors that can't succeed on retry by default, via `non_retryable_model_errors`

Merged
DO
1mo ago
+135-20

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

TemporalDurability's non_retryable_model_errors defaulted to (). Combined with Temporal's default retry policy, which retries without limit, a model request that can never succeed was retried every 100 seconds forever: a rejected API key, an unknown model, an overflowing context window, an exhausted quota, or a request past its deadline. The workflow hung instead of failing, and the ModelFallback capability, which falls back in workflow code, never got the error to fall back on. The docs told users to opt in to non_retryable_model_errors for exactly these errors. This PR makes that the default.

[!WARNING]
Compatibility impact: A model request activity under TemporalDurability that fails with a ModelRequestRejectedError (including ModelContextWindowExceededError, ModelAuthenticationError and ModelNotFoundError), a ModelQuotaExceededError or a ModelRequestTimeout now fails on its first attempt, instead of being retried as the activity's retry policy says.

Why this can ship in a minor release: it fixes workflows that retry forever, and so hang, on errors no retry can fix. Code that passes non_retryable_model_errors explicitly is unaffected.

Migration: to keep retrying these errors, pass non_retryable_model_errors=().

What changed

  • New default. non_retryable_model_errors now defaults to (ModelRequestRejectedError, ModelQuotaExceededError, ModelRequestTimeout):
    • ModelRequestRejectedError also covers ModelContextWindowExceededError, ModelAuthenticationError and ModelNotFoundError. The provider rejects the same request again.
    • ModelQuotaExceededError: the quota stays exhausted until it resets. Its docstring already says "retrying after a wait won't help".
    • ModelRequestTimeout: the request's deadline ran out, so there's no time left for another attempt. timeouts.md already advised listing it, because "the stalled model would keep being retried". The RetryOnModelErrors capability (#11932) doesn't retry it by default either.
  • Transient errors are unchanged. Rate limits, unavailable or overloaded models, server errors and connection errors are still retried according to the retry policy.
  • Docs.
    • The TemporalDurability docstring and temporal.md "Activity Retries" describe the default and how to extend it or opt out.
    • timeouts.md, model-fallback.md, models/overview.md and retries.md no longer tell users to list these classes themselves.

Related

#12105 fixes a separate bug in the same area: Temporal's non_retryable_error_types matched exact class names, so subclasses of UnexpectedModelBehavior or UserError were retried. This PR doesn't depend on it: non_retryable_model_errors matches with isinstance, so the default's subclasses, like ModelContextWindowExceededError, are covered here already.

Tests

  • New default (test_durability.py): with a 3-attempt policy and no non_retryable_model_errors passed, each of the default classes fails the activity on its first attempt and still reaches the workflow as its own class. A rate limit and an overloaded model are still attempted 3 times.

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