Skip to content

Show common.ai retry policies why each fallback connection failed - #76999

Merged
Lee-W merged 11 commits into
apache:mainfrom
astronomer:common-ai-fallback-retry-classification
Nov 18, 2026
Merged

Lee-W merged 11 commits into
apache:mainfrom
astronomer:common-ai-fallback-retry-classification

Conversation

@Lee-W

@Lee-W Lee-W commented Nov 13, 2026

Copy link
Copy Markdown
Member

Why

When every connection of a fallback_conn_ids chain fails, LLMOperator and AgentOperator raise pydantic-ai's FallbackExceptionGroup. RetryRule compares one exception type with isinstance, so a rule written for a provider-specific exception such as ModelHTTPError stops matching once a chain is configured. A rule set that retries rate limits but fails bad requests collapses into one rule. The classifier prompt of LLMRetryPolicy and ClassifierRetryPolicy sees only the group's message, not what each connection raised. (This is the gap the previous docs in retry_policies.rst and recovery.rst described.)

What

  • providers/common/ai/src/airflow/providers/common/ai/fallback_exceptions.py (new): adds FallbackChainExhaustedError, a subclass of FallbackExceptionGroup. It exposes member_errors (each connection's error, in chain order) and replayed_steps / recorded_steps (durable journal progress of the failed attempt, None when the run was not durable). It lives outside common.ai.exceptions so that module stays importable without pydantic-ai.
  • .../mixins/cancellable_run.py: run_agent_sync re-raises a FallbackExceptionGroup as FallbackChainExhaustedError, from the original group (kept as __cause__), filling the journal counts from the current journal. An error that is already a FallbackChainExhaustedError is not wrapped again.
  • .../policies/retry.py:
    • fallback_rules of LLMRetryPolicy and ClassifierRetryPolicy are tried, rule by rule in the listed order, against the chain's own error and then against the last connection's error. The last connection decides when members disagree. A decision taken on it ends its reason with (last chain member).
    • The classifier prompt lists each member as chain member N of M: <Type>: <message>, redacted and limited to max_exception_length per member, so one long message cannot push the last member out. With durable=True it also states how many steps the attempt replayed and recorded. The prompt-building code was split into a _limit helper to share the redact-then-truncate step.
    • The include_traceback=True path adds no member lines (it already formats the group).
Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: [Claude] following the guidelines


  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

@Lee-W
Lee-W force-pushed the common-ai-fallback-retry-classification branch from 4a6a184 to ae6caf1 Compare November 16, 2026 03:19
Lee-W added 11 commits November 18, 2026 09:21
FallbackChainExhaustedError.replayed_steps and recorded_steps stay None unless a journal was already recording.
Add find_active_journal(), which reads the journal without creating one.
… rate-limit classes

FallbackChainExhaustedError is only raised by the operators, their
subclasses and the @task.llm and @task.agent decorators. A plain @task
that runs an agent built with PydanticAIHook gets pydantic-ai's own
FallbackExceptionGroup, without member_errors or journal progress, so
provider_fallback, recovery and retry_policies now say which path
raises which error.

Telling a rate limit from a bad request in a rule needs
ModelRateLimitError (pydantic-ai-slim 2.59.0) and
ModelRequestRejectedError (2.62.0). On the provider's 2.46.0 floor both
are a plain ModelHTTPError, so the docs now state the version needs.
The rule order test listed the group catch-all first, so it passed
whether the policy tried rule by rule or target by target. It now lists
the member rule first and the group catch-all after it, and expects the
member rule to win. Looping over targets in the outer loop reaches the
group catch-all first and fails the test.
recovery.rst said every durable task raises FallbackChainExhaustedError
once the chain fails. Only the operators, their subclasses and the
@task.llm and @task.agent decorators do; a plain @task that runs an
agent with AirflowDurability gets pydantic-ai's FallbackExceptionGroup.
Airflow retries both, so the sentence now says so.

retry_policies.rst also claimed that before 2.59.0 no rule can tell a
429 from a 400. From 2.59.0 a 429 is ModelRateLimitError, so a rule can
single out a rate limit but not a rejected request until 2.62.0.

The paragraphs touched by the previous documentation commit are
rewrapped to the surrounding line width.
@Lee-W
Lee-W force-pushed the common-ai-fallback-retry-classification branch from ae6caf1 to 0635735 Compare November 18, 2026 02:04
@Lee-W
Lee-W merged commit 5a0a26f into apache:main Nov 18, 2026
79 checks passed
@Lee-W
Lee-W deleted the common-ai-fallback-retry-classification branch November 18, 2026 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants