Repository navigation
Fix Common AI durable retries not replaying tools from a capability without an id - #74314
Merged
Merged
Conversation
…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.
vatsrahul1001
approved these changes
Oct 6, 2026
eladkal
approved these changes
Oct 6, 2026
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
AgentOperator(durable=True), a retry replays nothing when a tool comes from a capability that has no explicitid, for examplecapabilities=[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 throughtoolsets=replays correctly.Since pydantic-ai 2.40, a capability without an
idgets 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 asToolDefinition.capability_id. The durable fingerprint hashed the wholeModelRequestParameters, so the model step-0 fingerprint never matched andCachingModellogged "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_idon each function and output tool definition, anddeferred_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 throughtool_visibility,revealed_tool_namesandinstructions, 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 anidon every capability would not: the failure is silent, and nothing tells them to.revealed_tool_namesis now sorted before hashing. It is aset, 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_idshad the same problem, which dropping it removes.Message
metadatastays in the hash. pydantic-ai does not send it to the model, but it keeps routing state there under__pydantic_ai__(for exampleFallbackModel'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_retryalready passed aToolsetcapability but never caught this: it calls_build_agent().run_sync()withoutCachingModeland uses a fixedtool_call_id. The new test drivesAgentOperator.executetwice against the same durable storage, with the model issuing fresh tool call ids as a real provider does. It fails onmainwith the anonymous capability and passes with an explicitid, 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=Truetogether with code mode is still rejected. That follows after #74312.{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.