Add output validation fallback to `ModelFallback`
This pull request was posted by Codex Desktop using gpt-6.1-sol on behalf of David.
Closes #10158
Why we make these changes
Output validation can exhaust retries on one model without trying a fallback. Add an opt-in ModelFallback policy that switches the next ordinary step while preserving feedback, tools, usage, and the current run.
New public surface
ModelFallback(..., output_retry_threshold: int | Mapping[str, int] | None = None): a positive threshold for every model ID, a copied mapping by effective selection ID (canonical IDs for inferred defaults, or resolver aliases), orNonefor request-only fallback. Unlisted models and empty mappings keep request-only behavior.OutputRetryContext,OutputRetrySource,AbstractCapability.on_output_retry,OnOutputRetryHookFunc,Hooks(output_retry=...), andhooks.on.output_retry: observe each output failure that consumes an allowed retry, with response, source, typed retry metadata, and output-tool identity.OutputFallbackEvent: reports an applied switch asmodel_fallback.output_fallback, with source/target selection IDs and triggering retry metadata. The same switch is recorded as an event on the current trace span.
User-visible behavior
Before: ModelFallback(backup) only handles request failures. After: ModelFallback(backup, output_retry_threshold=1) switches the next step after one accepted output retry and stays at that candidate or later ones for this run.
Selection uses normal get_model() precedence: an override, explicit run model, or SelectModel remains authoritative throughout the run and disables output-driven switching. An explicit run or run-spec model warns when it suppresses a configured threshold; use Agent.from_spec/from_file to make a spec model the default. Otherwise the next candidate is selected before settings, tools, and step hooks. Suspended continuation retains priority. Core retry and usage limits remain effective; successful tools are retained. Function-tool and request-hook retries do not advance the policy. A final stream already delivered is not replaced; accepted output-tool sibling retries still notify. With sticky=True, output retirement restricts the remaining candidates for this run; only request-level fallbacks start sticky history.
on_output_retry reports individual retries. OutputFallbackEvent is emitted only when a switch is applied; a successful sibling, exhausted budget, absent next step, or saturated final candidate produces no switch event.
Verification
-
Passed: focused output-retry, routing/override/selector, stable counter reconstruction and alias thresholds, wrapper, event, spec, streaming, smaller-window compaction, and generic selector/resume, and explicit-run warning checks.
tests/test_capability_model_fallback_output.pytests/test_output_retry_hook.py·tests/test_capability_model_fallback_output.py·tests/test_capability_model_fallback_output.py·tests/test_capability_model_fallback_output.py·tests/harness/compaction/test_output_fallback.py -
Passed: all seven recovery backends with no skips, including live-required PostgreSQL, focused Pyright/Ruff, and changed-file pre-commit checks.
tests/durable_exec/temporal/test_output_fallback.py·tests/durable_exec/test_output_fallback_dbos.py·tests/durable_exec/test_output_fallback_prefect.py·tests/harness/absurd/test_output_fallback.py·tests/harness/aws_lambda/test_output_fallback.py·tests/harness/pgtask/test_output_fallback.py·tests/harness/render/test_output_fallback.py -
CI for
16c0deeis pending. The required review remains open for maintainer sign-off on the run-start warning integration; its cancellation and test-layout findings are fixed. The selectedpydanty:review-branchcompleted; its output-fallback findings are addressed, and unrelated walker refactors were removed after required review. Local pre-push review budget is exhausted (3/3); remediation passed targeted checks. -
Passed: absorbed and propagated validator cancellation, distinct model instances sharing an ID, executable fallback examples, streamed final-result sibling notifications, inferred defaults with mapped thresholds, sticky/output policy interaction, and real mid-run recovery before the backup request in pgtask, DBOS and Prefect.
tests/test_output_retry_hook.py·tests/test_capability_model_fallback_output.py·tests/test_capability_model_fallback_output.py
What changes for existing users
Existing ModelFallback behavior is unchanged unless output_retry_threshold is enabled; core retry budgets are unchanged.
PR decisions
2026-10-27 · Research phase boundary · iter -
- Decision: Prepare an ignored implementation proposal and test matrix; do not implement or open a PR in this phase.
- Why: The task requests a research deliverable before implementation decisions.
- Source: https://github.com/pydantic/pydantic-ai/issues/10158#issuecomment-6454431639
- Session: 01a17fae-9ae5-7d42-ad97-8ef440cc6512
2026-10-27 · Precise retry eligibility before Harness policy · iter -
- Decision: Recommend an additive core output-origin retry summary and accepted-retry notification; retain existing retry count semantics.
- Why: Executed probes show output-validator and request-hook retries share the same count, cause, attempt, and budget; a retained response does not disambiguate after-response hooks.
- Source: https://github.com/pydantic/pydantic-ai/issues/10158#issuecomment-6454431639; local-notes/eligibility-probe.py
- Session: 01a17fae-9ae5-7d42-ad97-8ef440cc6512
2026-10-27 · Use settled-node eligibility before adding core state · iter -
- Decision: Recommend a Harness after_node_run observer using public response-processing nodes, settled retry parts, and current invocation definitions; gate correctness on durable replay tests.
- Why: The executed local-notes/node-observer-probe.py routes validator, empty-response, and output-tool failures while excluding request-hook and function-tool retries without a core change.
- Source: https://github.com/pydantic/pydantic-ai/issues/10158#issuecomment-6454431639
- Session: 01a17fae-9ae5-7d42-ad97-8ef440cc6512
- Supersedes: Precise retry eligibility before Harness policy
2026-10-29 · Brief refresh: maintainer routing correction · iter -
- Decision: Keep cross-step get_model escalation and separate ModelFallback; include the single-trace assertion and merged fallback dependency.
- Why: David approved the Oct 29 refresh; the Oct 28 correction supersedes the takeover and RetryModelRequest route in the earlier comment.
- Source: https://github.com/pydantic/pydantic-ai/issues/10158#issuecomment-6482817086
- Session: 01a17fae-9ae5-7d42-ad97-8ef440cc6512
2026-10-29 · Escalation thresholds and budget ownership · iter -
- Decision: Use EscalateOnOutputRetry with EscalationLevel.after_failures measured in accepted output-retry charges; expose required_output_retries while leaving retry budgets explicit and core-enforced.
- Why: Several output calls may fail in one response; cumulative thresholds preserve actual charges and final-level saturation without inventing a second retry budget.
- Source: https://github.com/pydantic/pydantic-ai/issues/10158#issuecomment-6482817086
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-29 · Implementation phase · iter -
- Decision: Implement model-only cross-step escalation in Harness, with behavioral, streaming, durable, spec, and telemetry verification, paired docs, and the PR lifecycle.
- Why: David approved implementation in this dedicated worktree after the research refresh.
- Source: https://github.com/pydantic/pydantic-ai/issues/10158#issuecomment-6482817086
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
- Supersedes: Research phase boundary
2026-10-29 · Respect DBOS step boundaries · iter -
- Decision: Journal the DBOS side-effecting test tool with DBOS.step and construct its agent before workflow execution; retain documented DBOS function-tool semantics.
- Why: An executed comparison reproduced duplicate inline lookup effects with and without agent reconstruction; plain DBOS function tools are not automatically journaled.
- Source: https://github.com/pydantic/pydantic-ai/blob/main/docs/durable_execution/dbos.md
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-29 · Core accepted-output-retry hook · iter -
- Decision: Add a core after_output_retry notification inside response processing and use it for Harness escalation and events.
- Why: David selected this prerequisite after terminal-node notification tests proved the settled-node observer cannot deliver to event-stream consumers.
- Source: https://github.com/pydantic/pydantic-ai/issues/10158#issuecomment-6482817086
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
- Supersedes: Use settled-node eligibility before adding core state
2026-10-29 · pre-push review 1 of 3 at b2417e943548ad9680c9c0cf88cc655e8274bece · iter -
- Decision: Reserved first fresh pre-push review dispatch.
- Why: Reviewed tree e1c346363b0b70b00e9c975b999f2453af87ce28; full scope 446cb61ad2b40f9ed7d1a6c83e1a4fa6c0ad3619..b2417e943548ad9680c9c0cf88cc655e8274bece; policy base ad27fbfe2596b063b06c1c39ca3d2ea4c2becb3e.
- Source: https://github.com/pydantic/pydantic-ai/tree/codex/output-retry-escalation-implementation
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-29 · pre-push review 1 outcome at b2417e943548ad9680c9c0cf88cc655e8274bece · iter -
- Decision: Dismissed the sole finding with executable evidence: OutputRetryEvent inherits tool_name and tool_call_id from CapabilityEvent; construction with both succeeds.
- Why: Reviewed tree e1c346363b0b70b00e9c975b999f2453af87ce28 remains unchanged; inspect.signature includes both fields and terminal output-tool event integration tests pass.
- Source: https://github.com/pydantic/pydantic-ai/tree/b2417e943548ad9680c9c0cf88cc655e8274bece
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-29 · Preserve existing Trio compatibility boundary · iter -
- Decision: Keep this PR focused on accepted-output retries; do not change the existing asyncio-based agent lifecycle or claim new Trio support.
- Why: An unchanged output-hook test reproduces the same no-running-event-loop failure before output processing; the new hook adds no asyncio dependency.
- Source: https://github.com/pydantic/pydantic-ai/blob/446cb61ad2b40f9ed7d1a6c83e1a4fa6c0ad3619/pydantic_ai_slim/pydantic_ai/agent/__init__.py
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-29 · Keep dependency-typed retry callbacks · iter -
- Decision: Retain generic AfterOutputRetryHookFunc and add its API reference link instead of introducing RunContext[Any].
- Why: The callback preserves dependency typing; constructor, decorator, wrapper, and custom-dependency tests pass. Matching older erased signatures adds no runtime benefit.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911#discussion_r4418649125
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-29 · Verify losing-selector telemetry · iter -
- Decision: Keep the selection logic unchanged and add a regression proving a losing selector is not evaluated or traced.
- Why: CombinedCapability selects one contribution before evaluating it; the public Agent test confirms no escalation selection or transition span when a later SelectModel wins.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911#discussion_r4418649117
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-29 · Publish accepted-retry eligibility evidence · iter -
- Decision: Retain the approved accepted-output hook and publish the count-only counterexample on the owning issue.
- Why: A request-hook retry switches a ctx.retry selector despite both outputs being valid; the output-only policy stays primary. Terminal node events also miss stream consumers.
- Source: https://github.com/pydantic/pydantic-ai/issues/10158#issuecomment-6510380192
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-29 · pre-push review 2 of 3 at d203ea85f9835385c73fd6994a0a17c1f30e7284 · iter -
- Decision: Reserved scoped follow-up review of CI and hosted-review corrections.
- Why: Tree 803b39cf504b9fab8ad5fb4a2e31b35196e42357; scope b2417e943548ad9680c9c0cf88cc655e8274bece..d203ea85f9835385c73fd6994a0a17c1f30e7284; policy base 2e0c8ac88f6dc55c03e6457145f93498f65d3eee.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-29 · pre-push review 2 outcome at d203ea85f9835385c73fd6994a0a17c1f30e7284 · iter -
- Decision: Fresh scoped review returned current with no findings.
- Why: Reviewed tree 803b39cf504b9fab8ad5fb4a2e31b35196e42357 is clean and unchanged; scope b2417e943..d203ea85f, full branch available as context.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-29 · Maintainer approval of accepted-output prerequisite · iter -
- Decision: Retain the accepted-output hook selected by dsfaccini, the Pydantic AI maintainer and PR owner, in this implementation session.
- Why: The user explicitly selected this core prerequisite after the terminal-notification reproduction; the reviewer repeated a tradeoff already settled by that maintainer decision.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911#discussion_r4418844422
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-29 · pre-push review 3 of 3 at 8a6b6541f663b28f8edc8c472e83b7583ff20dc9 · iter -
- Decision: Reserve final scoped review for telemetry coverage and documentation corrections.
- Why: Tree 67ec3a4c00a1fee35e8807765578f6b112812bcd; scope d203ea85f9835385c73fd6994a0a17c1f30e7284..8a6b6541f663b28f8edc8c472e83b7583ff20dc9; policy base 8048858d61e025685054b2e7e6b6e1a2351b0deb. Two earlier hosted pushes have comments, so use latest Sol reviewer-deep.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-29 · pre-push review 3 outcome at 8a6b6541f663b28f8edc8c472e83b7583ff20dc9 · iter -
- Decision: Fresh scoped Sol review returned current with no findings.
- Why: Reviewed tree 67ec3a4c00a1fee35e8807765578f6b112812bcd remains clean and unchanged. Third reserved dispatch retried initialization before review started; three substantive reviews used, no fourth.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-29 · Brief refresh: ModelFallback public surface · iter -
- Decision: Replace standalone Harness escalation with an opt-in ModelFallback option; retain the accepted-output hook and work out persistent routing with the per-step chain and sticky proposal.
- Why: Douwe changed the requested public shape and dsfaccini explicitly approved applying it on the issue.
- Source: https://github.com/pydantic/pydantic-ai/issues/10158#issuecomment-6511099298
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
- Supersedes: Escalation thresholds and budget ownership
2026-10-30 · Route output fallback at next-step preparation · iter -
- Decision: Use prepare_model_request at the start of the next ordinary step for output-driven ModelFallback switching, matching the existing continuation-routing path.
- Why: David selected this after an executed probe showed dynamic get_model rejects suspended-history resume before fallback pin routing; preserve validation feedback and per-attempt preparation.
- Source: https://github.com/pydantic/pydantic-ai/issues/10158#issuecomment-6511318966
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
- Supersedes: Brief refresh: ModelFallback public surface
2026-10-30 · Configure output fallback on the existing chain · iter -
- Decision: ModelFallback.output_retries accepts one positive threshold or a copied mapping from selection IDs to positive thresholds; unlisted models retain request-only fallback.
- Why: Preserve the issue contract for per-candidate thresholds without adding level types or a second capability. Accepted charges stay with their actual producer; sibling failures cannot skip an untried candidate.
- Source: https://github.com/pydantic/pydantic-ai/issues/10158
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
- Supersedes: Escalation thresholds and budget ownership
2026-10-30 · Preserve accepted sibling retry notifications · iter -
- Decision: Publish accepted output-tool retry notifications after the core counter charge even when another sibling terminally exhausts its own budget; preserve interrupted history and cancellation behavior.
- Why: Distinct output-tool budget reproduction lost the accepted callback under exhaustive execution; the regression now passes for all end strategies and observer errors do not duplicate callbacks.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-30 · Integrate upstream model identity during merge · iter -
- Decision: Use ModelResponse.model_id for suspended continuation routing, preserve upstream handling of models outside the chain, and retain the output-retirement cursor bound.
- Why: Merged #11807 replaced the unreleased metadata pin; retaining that obsolete pin would discard upstream routing and prevent CI from running against current main.
- Source: https://github.com/pydantic/pydantic-ai/pull/11807
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-30 · Name the threshold and emit applied-switch events · iter -
- Decision: Use output_retry_threshold for the ModelFallback switch threshold and OutputFallbackEvent for an applied switch, carrying source/target model IDs and its triggering retry; observe individual accepted retries through after_output_retry.
- Why: David selected both API changes after hosted review identified budget-name ambiguity and a per-retry event coupled to fallback configuration.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911#discussion_r4420138480; https://github.com/pydantic/pydantic-ai/pull/11911#discussion_r4420138483
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-30 · Preserve wrappers at the final candidate · iter -
- Decision: Keep the serving selection for final-candidate retries while retaining the unwrapped producer solely for retry accounting.
- Why: The public ConcurrencyLimitedModel regression reproduced limiter counts [1,0] before the fix and [1,1] after it; recovery tests pass with the preserved selection.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911#discussion_r4420098235
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-30 · Record switches as trace span events · iter -
- Decision: Record applied output fallback on the current trace span with source and target selection IDs; do not create a separate zero-duration span.
- Why: Repository instrumentation already uses span events for point-in-time decisions; this avoids one empty exported span per switch and aligns trace identifiers with OutputFallbackEvent.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911#discussion_r4420280510
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-30 · Preserve core retry cause types · iter -
- Decision: Expose RetryInfo[RetryFeedbackCause | ToolRetryCause] on OutputRetryContext and OutputFallbackEvent rather than erasing the cause to str.
- Why: Core already stamps those covariant cause types; preserving them lets consumers exhaustively match the new public fields without casts.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911#discussion_r4420356098
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-30 · Select the persistent candidate before step hooks · iter -
- Decision: Replace output-driven preparation redirects with step-start selection, preserving initial explicit or selector precedence and suspended-continuation priority.
- Why: David selected this after the executed probe confirmed retired-model before/wrap contexts, a repeated attempt-2 redirect, and missed smaller-window compaction.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911#discussion_r4425272429
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
- Supersedes: Route output fallback at next-step preparation
2026-10-30 · Keep bootstrap selection and resume guards unchanged · iter -
- Decision: Apply an opt-in private step-model contribution before ordinary graph selection; preserve static ModelFallback bootstrapping and the generic dynamic-selector resume guard.
- Why: This places the persistent candidate before step hooks, settings and tools, supports explicit initial models, and avoids evaluating an ordinary selector after retirement; request-only and generic selector regressions pass.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911#discussion_r4425272429
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-30 · Retain producer identity in grouped retry state · iter -
- Decision: Group the serving producer, selection and threshold into one immutable response snapshot, and index retry counts by object ID while retaining each producer in the value.
- Why: The state is rebuilt during durable replay; retaining producers prevents ID reuse within the run, and all seven recovery backends pass.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911#discussion_r4424997376
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-30 · Name the accepted-retry notification on_output_retry · iter -
- Decision: Rename the new notification to on_output_retry and its callback protocol to OnOutputRetryHookFunc; expose Hooks(output_retry=...) and hooks.on.output_retry using existing registration conventions.
- Why: David selected the notification name because it fires when an allowed retry is charged, before another request; timing, typing and retry-limit ownership are unchanged.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911#discussion_r4425754624
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-30 · Keep output switching within normal model selection precedence · iter -
- Decision: Use get_model for output-driven step selection; an active override, explicit run model, and nondefault capability selection remain authoritative throughout the run. Remove the private step-model tier and restore the documented override guarantee.
- Why: David selected ordinary precedence after review reproduced an output retry escaping a test override; fallback takeover would need a separately agreed public selection API.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911#discussion_r4426031091
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
- Supersedes: Keep bootstrap selection and resume guards unchanged
2026-10-30 · Count output retries by stable selection ID · iter -
- Decision: Key retry counts and threshold lookup by the serving model selection ID, including resolver aliases; remove process-local object IDs and producer-retention bookkeeping.
- Why: The reconstruction regression exhausts retries before the fix because each new object starts a new counter; stable selection IDs preserve the configured threshold and follow issue10158’s state contract.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911#discussion_r4426554189
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
- Supersedes: Retain producer identity in grouped retry state
2026-10-30 · Use the author-selected hosted branch review · iter -
- Decision: David selected pydanty:review-branch as the additional review; run it once after required checks settle, then verify remediation and do not rerun the additional review.
- Why: The XL diff spans public hooks, model selection, output validation, streaming and seven durable recovery backends.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911#issuecomment-6530852308
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-30 · Defer independent Evals timing-test hardening · iter -
- Decision: Leave Evals timeout-test hardening outside this output-fallback PR; track the observed failed/passed CI pair in the PR comment.
- Why: The unchanged Evals test failed once and passed on repeat with the same recorded base and no dependency-version changes; hardening it later does not change the released output-fallback artifact.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911#issuecomment-6530884273
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-30 · Warn when explicit run models suppress output fallback · iter -
- Decision: Keep normal get_model precedence and warn at run setup when an explicit run or run-spec model disables a configured output retry threshold; overrides and capability composition remain silent.
- Why: Expose an explicit configuration conflict before any rejected output without querying skipped selectors.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911#discussion_r4427548104
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-30 · Share output retry source type and defer resume predicate · iter -
- Decision: Expose OutputRetrySource for retry contexts and switch events; give the resume guard a lazy default-selector predicate instead of capability internals.
- Why: Keep the public source values synchronized and preserve lazy capability queries for ordinary runs.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911#discussion_r4427548111
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-30 · Retain provenance-aware run-start diagnostics · iter -
- Decision: Keep the explicit-run warning in Agent setup using established leaf traversal; do not add a generic diagnostic hook or warn on capability-to-capability selection.
- Why: Existing instrumentation and singleton diagnostics use the same traversal; output retry hooks lack provenance and capability composition warnings conflict with repository policy.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911#discussion_r4427910992
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-30 · Attribute output fallback warnings to callers · iter -
- Decision: Skip Pydantic AI, contextlib and asyncio frames when locating the output fallback configuration warning.
- Why: The failing filename regression showed stacklevel2 identified Agent internals; cover run, streaming, iter and sync entrypoints.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911#discussion_r4427910998
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-30 · Bound warning caller attribution to direct runs · iter -
- Decision: Skip Pydantic AI, Pydantic Graph, contextlib and asyncio frames for direct run caller attribution; retain task-local attribution for background event streams.
- Why: The event stream probe shows a separate task with no originating caller frame; adding task provenance solely for a warning would widen this fix.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911#discussion_r4427910998
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
- Supersedes: Attribute output fallback warnings to callers
2026-10-30 · Avoid deprecated spy detection on Python3.14 · iter -
- Decision: Use a wrapped mock for the skipped-getter assertion without changing dependency versions.
- Why: The oldest supported pytest-mock spy calls deprecated asyncio.iscoroutinefunction on Python3.14; the failure is in fixture construction, not the warning behavior.
- Source: https://github.com/pydantic/pydantic-ai/actions/runs/41118233976/job/124278142623
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-30 · Clarify constructor versus runtime spec model precedence · iter -
- Decision: Document that specs with a model and output threshold should construct an agent through from_spec/from_file; runtime spec models remain explicit run choices.
- Why: The same YAML has different model-selection provenance when used to configure an agent versus a run; verify constructor specs with an initial model.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911#discussion_r4428010446
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-30 · Integrate merged sticky policy with output retirement · iter -
- Decision: Preserve sticky request fallback before output retirement; once output switching advances the run, restrict later attempts to the remaining configured suffix. New runs reset output retirement and retain sticky history rules.
- Why: PR11330 merged during hosted review and replaced the ordinary cursor with a remaining-candidate list; preserve its behavior when output thresholds are disabled.
- Source: https://github.com/pydantic/pydantic-ai/pull/11330
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-30 · Reuse identity-preserving wrapper matching from main · iter -
- Decision: Reuse the merged ModelFallback _is_or_wraps predicate for output candidate matching rather than flattening all wrappers through the graph helper.
- Why: Full unwrapping loses a configured wrapper identity when it sits inside another wrapper; main now provides the exact existing predicate in the same module.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911#issuecomment-6532834365
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-30 · Centralize caller-aware warnings and wrapper delegates · iter -
- Decision: Share the counted warning-frame walker in core _warnings with caller-specific skip sets; add unwrap_capability in _ordering and reuse the four existing Agent leaf walks without changing registered traversal.
- Why: The hosted review identified actual repeated implementations; preserve deprecated-warning Harness attribution and avoid introducing a new public hook or model-selection provenance API.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911#issuecomment-6532834365
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-30 · Notify accepted retries from streamed final-result completion · iter -
- Decision: Pass the retry ledger and notify from run_stream final-result completion as well as CallToolsNode; leave delivered final output intact.
- Why: The branch MRE and failing exhaustive/run_stream regression show a charged sibling retry in history with no notification before the fix.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911#issuecomment-6532834365
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-30 · Prove recovery before the fallback request executes · iter -
- Decision: Add mid-run interruptions before the backup request in pgtask, DBOS and Prefect tests, retaining completed-run replay controls for all seven backends.
- Why: A completed-run replay can return a cached backup response despite a lost selection rebuild; the new cases require a real backup call after recovery and pass against live engines.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911#issuecomment-6532834365
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-30 · Keep existing by-name fallback coverage · iter -
- Decision: Do not add a duplicate plain-selection-ID test; the direct Agent alias event and configured-alias counter tests already verify applied switches and per-ID thresholds.
- Why: The hosted finding claims no string default is covered, but both direct constructors use string defaults and their proving tests pass.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911#issuecomment-6532834365
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-30 · Keep sticky history tied to request fallback · iter -
- Decision: Output-only switches do not start sticky conversation history; output retirement resets on each new run, while sticky retains its existing request-fallback rule.
- Why: This preserves the merged sticky contract based on actual failed request attempts and the approved run-local scope of output retirement.
- Source: https://github.com/pydantic/pydantic-ai/pull/11330
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-30 · Cover inferred by-name defaults separately from aliases · iter -
- Decision: Add direct constructor-inference coverage for integer and mapped thresholds, using the effective canonical model ID when the default was already inferred; preserve resolver aliases.
- Why: Alias tests bypass normal constructor inference. The Agent(test) probe reports no explicit selection ID and model_id test:test, which is the existing core fallback identity.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911#issuecomment-6532834365
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
- Supersedes: Keep existing by-name fallback coverage
2026-10-31 · Track output chain position by serving candidate identity · iter -
- Decision: Snapshot the next configured candidate from the actual serving model instance or selected alias, while keeping retry counters keyed by stable model ID.
- Why: Distinct configured TestModel instances can share a model ID; ID-only position lookup skipped an untried backup and failed the executable output-fallback example.
- Source: https://github.com/pydantic/pydantic-ai/actions/runs/41147833916
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-31 · Restore unrelated warning and capability traversal call sites · iter -
- Decision: Restore Advisor, the deprecated fallback shim, and the three existing Agent delegate walkers to main; keep the new output-policy warning traversal inline and remove unused new utilities.
- Why: The required review identified unrelated refactors that widen this feature without fixing an output-fallback defect; broad walker consolidation is deliberately skipped as a separate optional cleanup.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911#discussion_r4429541446
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-31 · Preserve plain-agent cancellation behavior at retry notification · iter -
- Decision: Omit the new pre-notification cancellation recheck; retain existing lifecycle cancellation boundaries and notification only for accepted output retry charges.
- Why: Public Agent probes and regression tests show the extra check aborts a graph child task before retry feedback is recorded when a validator absorbed its own cancellation; ordinary propagation still emits no notification.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911#discussion_r4429602076
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
2026-10-31 · Consolidate feature and notification regression modules · iter -
- Decision: Keep output-fallback regressions together in test_capability_model_fallback_output.py and hook-only regressions in test_output_retry_hook.py, sharing the identical Answer schema.
- Why: The split across nine fallback modules obscured the feature coverage and repeated setup; AST comparison preserved every test definition and the consolidated suites pass.
- Source: https://github.com/pydantic/pydantic-ai/pull/11911#discussion_r4429602080
- Session: 01a1898e-5cb5-7560-8700-03ae978368f9
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. (No compatibility impact.)
- PR title is fit for the release changelog.