Repository navigation
Account for AgentOperator spend on failed runs and across retries - #73706
Merged
Merged
Conversation
Lee-W
force-pushed
the
common-ai-agent-usage-on-failure
branch
2 times, most recently
from
September 29, 2026 09:21
a81bf05 to
c9b5330
Compare
Lee-W
marked this pull request as ready for review
September 29, 2026 09:22
Lee-W
force-pushed
the
common-ai-agent-usage-on-failure
branch
2 times, most recently
from
September 29, 2026 09:24
edfdf92 to
9261e9c
Compare
amoghrajesh
approved these changes
Sep 29, 2026
amoghrajesh
left a comment
Contributor
There was a problem hiding this comment.
Nice fix, thanks @Lee-W.
Compat looks solid too.
- Gated correctly - anything before 3.3, or
usage_limits=None, behaves exactly as before. - The usage xcom keeps its old shape and its old meaning (this attempt's own spend, via the attempt_usage delta), even when the cumulative budget is active underneath.
- A task already paused for tool approval before this lands still resumes fine -
attempt_usagedefaults toNonefor a payload saved by the old code.
Looks good with two nits.
When an agent run raised (a usage limit, a tool crash, a timeout), the usage it had already incurred was never logged or pushed to XCom, so the spend of failed attempts was invisible. usage_limits was also enforced per attempt, so a task with retries could spend (retries + 1) times the configured cap, which defeats a cost limit meant to bound spend. The task state store (Airflow 3.3+) survives retries, which makes it possible to carry spend across attempts. Durable replay used to recount the usage of cached steps; against a cumulative budget that would double-count already-paid work and block retries that make no new calls.
Lee-W
force-pushed
the
common-ai-agent-usage-on-failure
branch
from
September 30, 2026 02:55
9261e9c to
e10b150
Compare
This was referenced Oct 8, 2026
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.
Why
When an agent run raised (a usage limit, a tool crash, a timeout), the usage it had already incurred was never logged or pushed to XCom, so the spend of failed attempts was invisible.
usage_limitswas also enforced per attempt, so a task with retries could spend (retries + 1) times the configured cap, which defeats a cost limit meant to bound spend.What
The task state store (Airflow 3.3+) survives retries, which makes it possible to carry spend across attempts. Durable replay used to recount the usage of cached steps; against a cumulative budget that would double-count already-paid work and block retries that make no new calls.
Was generative AI tooling used to co-author this PR?
Generated-by: [Claude] following the guidelines
{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.