Skip to content

Fix Common AI durable retries and tool-approval resumes on pydantic-ai 2.50+ - #74313

Merged
eladkal merged 1 commit into
apache:mainfrom
astronomer:commonai-usage-float-fields
Oct 6, 2026
Merged

eladkal merged 1 commit into
apache:mainfrom
astronomer:commonai-usage-float-fields

Conversation

@kaxil

@kaxil kaxil commented Oct 6, 2026

Copy link
Copy Markdown
Member

On pydantic-ai-slim 2.50 or later, an AgentOperator retry with durable=True, and the resume after a tool approval, fail on Airflow 3.3+ when they load the usage the earlier attempt saved:

ValueError: 'run_usage'['audio_seconds'] in the task state store is not an int (got 0.0); delete the key to reset.

pydantic-ai 2.50 added audio_seconds: float to RunUsage (seconds of audio billed, for voice models). load_run_usage in utils/usage_budget.py walks every RunUsage field and, apart from cost and details, requires an int. The first attempt saves the usage with audio_seconds=0.0, so the retry or resume cannot read it back. The provider allows pydantic-ai-slim>=2.33.0, so any install that has picked up 2.50+ is affected; CI did not catch it because uv.lock pins 2.48.0.

Fields declared as float now load as floats, still rejecting strings and bools; count fields keep the int check. The loader already carries any new RunUsage field through automatically, so this only teaches it the second numeric type.

With pydantic-ai-slim 2.52.0 installed, 15 existing tests in test_agent.py (durable usage-budget retries) and test_agent_tool_approval.py (approve, reject, timeout and cancel on resume) fail on main with the error above and pass with this change. The new tests include a round trip through TypeAdapter(RunUsage), the path the resume uses, which runs on every pydantic-ai version, so a future field of another type fails it instead of being skipped.


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

…i 2.50+

pydantic-ai 2.50 added a float field to RunUsage, audio_seconds. The task
state store loader required every count field to be an int, so the usage
it had saved on the first attempt (audio_seconds=0.0) failed to load on the
retry or resume with "is not an int (got 0.0)". Float fields now load as
floats.
@eladkal
eladkal merged commit 77b21f3 into apache:main Oct 6, 2026
85 checks passed
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