Wait a model error's `retry_after` durably before retrying a model request on the AWS Lambda, Azure Durable Task, Absurd and pgtask durability capabilities

Merged
DO
17d ago
+863-33

Closes #13267

Stacked on #13270 (shared model_error_retry_after helper, Temporal and DBOS), which should merge first; this PR's base is that branch.

Why

On every durable engine, a model request that fails with a model error carrying retry_after should wait that long, capped, as a durable wait before the engine's next attempt (#13267). This covers the Pydantic AI Harness engines:

EngineHow it waitsCap
AWS Lambdathe model step's retry_strategy (SDK default if unset) keeps deciding whether to retry; its delay becomes retry_after, so the SDK's timed suspension waits itstrategy's delay for the attempt or 60 s, whichever is longer
Azure Durable Taskthe model activity records the wait instead of failing; the orchestration waits it on a durable timer and calls the activity again with the RetryPolicy continued from the attempts so far; when the policy allows no more, a TaskFailedError is rebuilt from the recorded failure details; without a policy that allows another attempt, the activity fails nativelymax_retry_interval, else policy backoff or 60 s
Absurd, pgtaskthe model step checkpoints the failed attempt, sleep_for suspends the task, the step runs again (shared private module pydantic_ai_harness._retry_after, which also holds the model operation IDs and the default cap all four engines use)Absurd: RetryStrategy.max_seconds, else 60 s; pgtask: 60 s (retry_delay isn't readable from the running task)
Render Workflowscan't: task Retry is fixed at registration and there's no durable sleep, so docs say wait_duration_ms/backoff_scaling applyn/a

Errors without retry_after keep each engine's configured backoff. No engine sleeps in process. RetryOnModelErrors (#11932) retries inside the run, not as the engine's durable wait; the two stack like the other retry layers, and its code is untouched.

New public surface

none

User-visible behavior

 Agent(model, name='a', capabilities=[AWSLambdaDurability()])
 # the model raises ModelHTTPError(429, ..., headers={'Retry-After': '20'})
-step retry after the SDK default strategy's backoff (5 s, with jitter)
+step retry after a 20 s timed suspension (capped at a minute here)

Verification

What changes for existing users

On Lambda, Azure Durable Task, Absurd and pgtask, a model request whose error asks for a wait is retried after that capped wait instead of the engine's backoff, and on Azure, Absurd and pgtask the failed attempt is recorded as a completed durable unit carrying the wait.

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 -

2026-11-12 · PR split · iter -

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 -

2026-11-12 · pre-push review 1 of 3 at ac36023cbc5d516229e6c267c6d9f35a457b3607 · iter -

2026-11-12 · pre-push review 2 of 3 at 75532f8cce · iter -

2026-11-12 · pre-push review 2 of 3 at 75532f8cce · iter -

2026-11-12 · Lambda retry_after replaces the delay · iter -

  • Decision: delay = ceil(min(retry_after, max(strategy delay, 60s))), so a shorter Retry-After can retry sooner than the strategy's backoff, as Temporal's next_retry_delay does; only model steps (request, compact, cancel) get the wrapper
  • Why: Read 'never retry sooner than the user's strategy' as the cap floor; mirrors Temporal semantics
  • Source: https://github.com/pydantic/pydantic-ai/issues/13267

2026-11-12 · Azure mechanism · iter -

  • Decision: Model activity returns {retry_after, failure details JSON} instead of raising; orchestrator counts attempts from RetryableTask._attempt_count, waits asyncio.sleep (durable timer via trampoline), re-calls with a continued RetryPolicy (backoff, attempts, retry_timeout); when the policy allows no more (or no policy) raises TaskFailedError rebuilt from the recorded failure details
  • Why: durabletask has no per-failure delay hook and re-schedules native retries under the same action id, so a full own retry loop would break in-flight histories; native retries stay for errors without retry_after
  • Source: https://github.com/pydantic/pydantic-ai/issues/13267

2026-11-12 · Absurd/pgtask mechanism and caps · iter -

  • Decision: Shared harness helper step_waiting_retry_after: model step returns a marker instead of failing, engine sleep_for suspends, step runs again; waits bounded by max_attempts - attempt; Absurd cap = RetryStrategy max_seconds else 60s (reads private ctx._task, no public accessor); pgtask cap = 60s because retry_delay isn't readable from the running task
  • Why: Supersedes pgtask cap = max(retry_delay, 60s): retry_delay lives on the TaskDefinition, not the Task
  • Source: https://github.com/pydantic/pydantic-ai/issues/13267
  • Supersedes: Absurd and pgtask caps

2026-11-12 · Render and Prefect document-only · iter -

2026-11-12 · pre-push review 1 of 3 at 1f44b1ab7dcbbc64c8df888d901f4114eac5803f · iter -

2026-11-12 · pre-push review 1 of 3 at 1f44b1ab7d · iter -

2026-11-12 · pre-push review 2 of 3 at 1f44b1ab7d · iter -

2026-11-12 · pre-push review 2 of 3 at 1f44b1ab7d · iter -

2026-11-12 · pre-push review 3 of 3 at a8d3b346a6d60145815529414058cc42c4cebd46 · iter -

2026-11-12 · pre-push review 3 of 3 at a8d3b346a6 · iter -

2026-11-12 · post-review fix c7aae1dd22090d2bac5d5047ca16a02939439129 · iter -

  • Decision: Macroscope finding: continued Azure first_retry_interval overflowed timedelta; capped in seconds at max_retry_interval; pushed without local review (budget exhausted)
  • Why: valid; reproduced by reasoning: timedelta * 1e14 > timedelta.max
  • Source: https://github.com/pydantic/pydantic-ai/pull/13283

2026-11-12 · Azure backoff pow overflow left as is · iter -

  • Decision: Don't guard float pow overflow in the continued policy/cap
  • Why: Parity with durabletask's own unguarded math.pow in compute_next_delay; only at unrealistic exponents; timedelta overflow already fixed
  • Source: https://github.com/pydantic/pydantic-ai/pull/13283

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.