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
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:
| Engine | How it waits | Cap |
|---|---|---|
| AWS Lambda | the 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 it | strategy's delay for the attempt or 60 s, whichever is longer |
| Azure Durable Task | the 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 natively | max_retry_interval, else policy backoff or 60 s |
| Absurd, pgtask | the 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 Workflows | can't: task Retry is fixed at registration and there's no durable sleep, so docs say wait_duration_ms/backoff_scaling apply | n/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
- Lambda:
test_aws_lambda.py::TestRetryAfter(delay, rounding, both caps,should_retrykept, tool steps untouched). - Azure:
test_capability.py::TestAzureDurableTaskDurability::test_model_retry_after_waits_on_a_durable_timeron the in-memory worker (wait,max_retry_interval, policy-backoff and one-minute caps, a backoff too long for atimedelta, attempts exhausted,retry_timeout; with no policy or a single attempt the activity fails natively). - Absurd, on real Postgres:
test_absurd.py::TestRetryAfter(wait and replay, suspension,max_secondsand default one-minute caps, no attempts left, no attempt limit, noretry_after). - pgtask, on real Postgres:
test_pgtask.py::TestRetryAfter. (wait and replay, no attempts left)
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 -
- 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 · 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 -
- Decision: Render: task Retry fixed at registration, no durable sleep; documented that wait_duration_ms/backoff_scaling apply
- Why: No per-failure hook or durable timer; no in-process sleeps
- Source: https://github.com/pydantic/pydantic-ai/issues/13267
2026-11-12 · pre-push review 1 of 3 at 1f44b1ab7dcbbc64c8df888d901f4114eac5803f · iter -
- Decision: dispatched (reserved)
- Why: scope: stacked on durable-retry-after 7f7934a8ccbb64810914d83ad010dcd1e1b50c0d..1f44b1ab7dcbbc64c8df888d901f4114eac5803f
- Source: https://github.com/pydantic/pydantic-ai/tree/durable-retry-after-harness
2026-11-12 · pre-push review 1 of 3 at 1f44b1ab7d · iter -
- Decision: report not delivered (background task finished, output lost); re-dispatched as call 2 on the same candidate
- Why: tree 9b10fa1a5ec5fd901584a9bcd563d917b9a6aa81
- Source: https://github.com/pydantic/pydantic-ai/tree/durable-retry-after-harness
2026-11-12 · pre-push review 2 of 3 at 1f44b1ab7d · iter -
- Decision: dispatched (reserved)
- Why: same scope as call 1
- Source: https://github.com/pydantic/pydantic-ai/tree/durable-retry-after-harness
2026-11-12 · pre-push review 2 of 3 at 1f44b1ab7d · iter -
- Decision: remediated: docs say per-request wait budget and that an Absurd wait uses no attempt, step tables list .retry_after, private-helper unit tests replaced by capability tests (cap, exhausted, no retry_after), pgtask test uses the real sleep_for(0), Azure docs describe the rebuilt TaskFailedError; kept Azure message wording (task id not exposed)
- Why: tree 9b10fa1a5ec5fd901584a9bcd563d917b9a6aa81; 5 findings
- Source: https://github.com/pydantic/pydantic-ai/tree/durable-retry-after-harness
2026-11-12 · pre-push review 3 of 3 at a8d3b346a6d60145815529414058cc42c4cebd46 · iter -
- Decision: dispatched (reserved)
- Why: follow-up scope 1f44b1ab7d..a8d3b346a6d60145815529414058cc42c4cebd46
- Source: https://github.com/pydantic/pydantic-ai/tree/durable-retry-after-harness
2026-11-12 · pre-push review 3 of 3 at a8d3b346a6 · iter -
- Decision: remediated: pgtask comment wording, skill paragraph wrap (d396179727); budget exhausted
- Why: tree 3e846c13e1cfcea90bcb3add20a253ae630de64d; prior findings verified fixed
- Source: https://github.com/pydantic/pydantic-ai/tree/durable-retry-after-harness
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.