Wait a model error's `retry_after` durably before DBOS retries a model request, via a shared `model_error_retry_after` helper
Part of #13267, which the stacked harness PR #13283 closes.
Why
A model error's retry_after is the wait a provider asked for (Retry-After, retry-after-ms, Gemini RetryInfo). Temporal already waits it before retrying a model request activity (#12106); the other engines ignore it. This PR adds the shared piece and covers the core engines (tracked in #13267):
- Temporal: unchanged behaviour, now via the shared helper.
- DBOS: DBOS retries a step in-process after an
asyncio.sleepthat recovery doesn't remember, with no per-failure delay hook. Whenmodel_step_configallows another attempt and the model error has aretry_after, the model step now records the attempt (returns the wait instead of failing), the workflow waits it with a durableDBOS.sleep_async, and runs the step again with the attempts left, carrying on DBOS's backoff. Cap: DBOS's backoff for that attempt or 60 s, whichever is longer. - Prefect: no durable timer and no per-failure delay, so it's documented that
retry_delay_secondsapplies. No in-process sleep added.
New public surface
pydantic_ai.durable_exec.model_error_retry_after(error, *, maximum) -> float | None: engine-builder helper that finds a model error'sretry_afterin an exception chain (stopping atraise ... from None) and caps it.
User-visible behavior
DBOSDurability(model_step_config=StepConfig(retries_allowed=True, max_attempts=3))
# model raises ModelRateLimitError(retry_after=20)
-steps: model.request (DBOS sleeps 1 s in-process, then retries inside the step)
+steps: model.request, DBOS.sleep (20 s, durable), model.request
Interaction with #11932 (RetryOnModelErrors)
RetryOnModelErrors retries inside the agent run, so under a durable engine it waits inside the durable unit (or in workflow code), not as the engine's retry delay. This PR covers the engine's own retries of the model request's durable unit. The two stack like the other retry layers. Leave retries to the engine if you want Retry-After waited durably. No code from #11932 is touched.
Verification
tests/durable_exec/test_retry_after.py: helper chain walk, cap,from None.tests/durable_exec/test_dbos.py:test_dbos_durability_model_error_retry_after_waits_durably(step/sleep/step journal, replay via fork),..._counts_every_attempt,..._continues_the_backoff,..._caps_at_dbos_maximum_backoff,..._outside_workflow_code_fails_as_before,test_dbos_retry_after_uses_dbos_step_defaults.- Existing Temporal tests cover the refactor:
tests/durable_exec/temporal/test_durability.py::test_durability_model_error_retry_after_delays_next_attempt,tests/durable_exec/temporal/test_model_and_serialization.py::test_a_model_error_that_cannot_be_rebuilt_still_carries_its_retry_delayand::test_a_non_retryable_model_error_gets_no_retry_delay.
What changes for existing users
DBOS users with model_step_config retries now wait a provider's Retry-After durably before the next model request attempt, instead of DBOS's in-process backoff; nothing else changes.
PR decisions
2026-11-12 · Per-engine Retry-After mechanisms · iter -
- Decision: Temporal native (unchanged); DBOS: workflow-side retry loop with DBOS.sleep_async for retry_after errors; Lambda: wrap retry_strategy; Azure: orchestrator-side durable timer; Absurd/pgtask: record attempt + durable sleep_for bounded by remaining attempts; Prefect and Render: document-only, no in-process sleep
- Why: Only Temporal and Lambda have a native per-failure delay; 'No silent in-process sleeps anywhere' (delegating agent, deciding for Douwe)
- Source: https://github.com/pydantic/pydantic-ai/issues/13267
2026-11-12 · Public retry_after helper · iter -
- Decision: Add a minimal public engine-builder helper to pydantic_ai.durable_exec with a keyword-only cap; Temporal uses it
- Why: Harness engines build on the public durable_exec surface, same tier as replay_scope/record_durable_unit
- Source: https://github.com/pydantic/pydantic-ai/issues/13267
2026-11-12 · Lambda cap rule · iter -
- Decision: delay = min(retry_after, max(strategy's own delay for this attempt, 60s)); keep the strategy's should_retry; no new parameter
- Why: A retry_strategy is an opaque callable with no readable maximum; never retry sooner than the user's strategy would
- Source: https://github.com/pydantic/pydantic-ai/issues/13267
2026-11-12 · Absurd and pgtask caps · iter -
- Decision: pgtask cap = max(retry_delay, 60s); Absurd cap = its RetryStrategy max_seconds; both bounded by the task's remaining attempts
- Why: Same rule as Lambda where the engine has no maximum
- Source: https://github.com/pydantic/pydantic-ai/issues/13267
2026-11-12 · PR split · iter -
- Decision: PR1 core: helper + Temporal refactor + DBOS + Prefect docs; PR2 harness: Lambda + Azure + Absurd + pgtask + Render docs, stacked on PR1
- Why: Core primitive vs per-engine split
- Source: https://github.com/pydantic/pydantic-ai/issues/13267
2026-11-12 · DBOS mechanism and cap · iter -
- Decision: Model step returns a {pydantic_ai_retry_after, attempts} marker instead of failing on a retry_after error (when not its last attempt, read via DBOS.step_status); workflow code waits DBOS.sleep_async and re-runs the step via DBOS.run_step_async with the attempts left; cap = max(DBOS backoff for the attempt, 60s), same rule as Lambda
- Why: DBOS has no per-failure delay hook and its in-step retry sleep isn't durable; returning a value records the failed attempt so replay is deterministic without depending on should_retry or exception serialization; DBOSAgent (deprecated) unchanged
- Source: https://github.com/pydantic/pydantic-ai/issues/13267
2026-11-12 · pre-push review 1 of 3 at ac36023cbc5d516229e6c267c6d9f35a457b3607 · iter -
- Decision: dispatched (reserved)
- Why: tree 237eafb6e7e819c62d18ac3203866fd4274393f0; full branch vs merge-base 4ece65be29f4e4af1f898ffeaaab18c33c9dd7a9
- Source: https://github.com/pydantic/pydantic-ai/tree/durable-retry-after
2026-11-12 · pre-push review 1 of 3 at ac36023cbc5d516229e6c267c6d9f35a457b3607 · iter -
- Decision: remediated: DBOS backoff continues across waits (attempt offset contextvar + advanced interval), helper stops at suppress_context, replay fork test, DBOS defaults pinned by test; kept chain walk for Temporal (provider-asked wait in a cause is the issue's case)
- Why: tree 237eafb6e7e819c62d18ac3203866fd4274393f0; 4 findings
- Source: https://github.com/pydantic/pydantic-ai/tree/durable-retry-after
2026-11-12 · pre-push review 2 of 3 at 75532f8cce · iter -
- Decision: dispatched (reserved)
- Why: follow-up scope ac36023cbc..75532f8cce
- Source: https://github.com/pydantic/pydantic-ai/tree/durable-retry-after
2026-11-12 · pre-push review 2 of 3 at 75532f8cce · iter -
- Decision: remediated: added a test pinning the per-attempt cap and the continued interval_seconds (150eab4544, test-only delta, exempt from re-review)
- Why: tree 00dd0b50f9293ecdbb6d67d45fbe822f959aad55; prior 4 findings verified fixed; exemption chains from reviewed 75532f8cce
- Source: https://github.com/pydantic/pydantic-ai/tree/durable-retry-after
2026-11-12 · test-only fix after review 2 · iter -
- Decision: 7f7934a8cc: DEFAULT_STEP_OPTIONS.get for pyright; exempt (test-only), chains from reviewed 75532f8cce
- Why: CI pyright: TypedDict keys NotRequired
- Source: https://github.com/pydantic/pydantic-ai/pull/13270
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.