Skip to content

Fix Common AI durable retries not replaying tools from a capability without an id - #74314

Merged
eladkal merged 2 commits into
apache:mainfrom
astronomer:commonai-durable-capability-id
Oct 6, 2026
Merged

eladkal merged 2 commits into
apache:mainfrom
astronomer:commonai-durable-capability-id

Conversation

@kaxil

@kaxil kaxil commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

With AgentOperator(durable=True), a retry replays nothing when a tool comes from a capability that has no explicit id, for example capabilities=[Toolset(FunctionToolset([...]))]. Every step runs live again on the retry, so tools with side effects run twice and the model calls are paid for twice. The same tool passed through toolsets= replays correctly.

Since pydantic-ai 2.40, a capability without an id gets a random one for each run (<toolset:d0d75e>, then <toolset:78ba70> on the retry; pydantic-ai documents that it differs every run on purpose) and stamps it on each of its tools as ToolDefinition.capability_id. The durable fingerprint hashed the whole ModelRequestParameters, so the model step-0 fingerprint never matched and CachingModel logged "cached model response does not match the current request" and ran the step live. The live response carries new tool call ids, so the tool steps missed as well.

The fingerprint now leaves out capability ids: capability_id on each function and output tool definition, and deferred_capability_ids. Neither is sent to the model. What they influence, tool visibility and the capability catalogue in the instructions, is already in the hash through tool_visibility, revealed_tool_names and instructions, so renaming an explicit capability id still invalidates the cache, and changing a tool's name, description or schema still does too (new tests cover both). Stripping the ids covers every capability that contributes tools (Toolset, MCP, CodeMode, user capabilities). Asking users to set an id on every capability would not: the failure is silent, and nothing tells them to.

revealed_tool_names is now sorted before hashing. It is a set, and its JSON dump follows iteration order, which differs between processes (PYTHONHASHSEED). A retry runs in a new process, so a durable retry with two or more revealed tools (tool search, deferred capabilities) also missed the cache. deferred_capability_ids had the same problem, which dropping it removes.

Message metadata stays in the hash. pydantic-ai does not send it to the model, but it keeps routing state there under __pydantic_ai__ (for example FallbackModel's continuation pin), so stripping it could replay a response recorded for a different route. A new test pins that down.

test_toolset_capability_tool_replayed_on_retry already passed a Toolset capability but never caught this: it calls _build_agent().run_sync() without CachingModel and uses a fixed tool_call_id. The new test drives AgentOperator.execute twice against the same durable storage, with the model issuing fresh tool call ids as a real provider does. It fails on main with the anonymous capability and passes with an explicit id, and passes for both with this change, on pydantic-ai-slim 2.48 (locked) and 2.52.

Upgrading the provider changes every fingerprint once, so a task that fails before the upgrade and retries after it re-runs its steps live; that is the existing fallback for any request change.

Not in this PR: durable=True together with code mode is still rejected. That follows after #74312.


  • 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.

…ithout an id

pydantic-ai 2.40+ gives a capability without an explicit id a random one
per run and stamps it on each of its tools. The durable fingerprint hashed
the whole request parameters, so a retry never matched its cached model
response and every step re-ran live, including tools with side effects.
The run-local capability ids are now left out of the fingerprint.
…ests

revealed_tool_names is a set and dumped in iteration order, which differs
between processes, so a durable retry with two or more revealed tools also
missed the cache.
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.

3 participants