Keep queued asset events when a Dag is at max_active_runs - #71992
Closed
Vamsi-klu wants to merge 4 commits into
Closed
Keep queued asset events when a Dag is at max_active_runs#71992Vamsi-klu wants to merge 4 commits into
Vamsi-klu wants to merge 4 commits into
Conversation
Asset events that arrive while a Dag is already at max_active_runs must remain queued and all be consumed by the next run once the cap lifts. Without that contract pinned, a cutoff-and-wipe path can silently drop events unless a later event unsticks them. closes: apache#56050
New tests should pin remaining queue rows and run-creation outcomes directly. Raw log-text checks and issue numbers in docstrings hide regressions that only drop some queued events, not all of them.
The cached exceeds_max_non_backfill flag was applied to every Dag, including asset-triggered ones, and asset create never refreshed it. Leftovers then waited for an unrelated later event. Co-authored-by: Cursor <cursoragent@cursor.com>
The check rejects issue-numbered fragments so the changelog entry links to the change that actually merged. Co-authored-by: Cursor <cursoragent@cursor.com>
This was referenced Aug 23, 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.
Keep queued asset events when a Dag is at max_active_runs
closes: #56050
This is leftover batch consume after the cap lifts, not the one-run-per-event redesign in #56750.
What I did
Reporter timeline: event 1 → run 1; events 2, 3, 4 while at
max_active_runs=1stay in ADRQ; after run 1 finishes, run 2 consumes{2,3,4}; event 5 waits and becomes its own run.dags_needing_dagrunsno longer ANDs the cachedexceeds_max_non_backfillflag onto asset leftovers. Asset create sets that flag aftercreate_dagrun. Live QUEUED+RUNNING exclusion still defers a Dag at cap and does not delete ADRQ. Newsfragment71992.bugfix.rst.Why I did
#56050 dropped events 3 and 4 until a later event unstuck them. That was cutoff-and-wipe. #70972 already removed the wipe. The leftover hole that remained is the stale cache: asset create never refreshed
exceeds_max_non_backfill, so a Dag with queued events stayed hidden after the live cap lifted.How I did
The cached flag is timetable-only:
After a successful asset
create_dagrunandconsumed_asset_events.extend, call_set_exceeds_max_active_runs. Do not set it when no run is created. Nosession.commit()in that path.QUEUED counts toward the cap, not only RUNNING. A stuck MANUAL run counts too. Catchup True/False does not change leftover consume. Partitioned same-key follow-up: events 2/3/4 land on run 2, not on the already-created run 1.
What's the impact
Asset leftovers stay visible once the live cap lifts, even if the cache still says the Dag is full. The next run consumes the leftover batch. This does not implement one run per event.
What's the testing
airflow-core/tests/unit/jobs/test_scheduler_job.pytest_asset_events_queued_while_at_max_active_runs_are_all_consumedtest_asset_events_wait_when_max_active_runs_is_twotest_already_consumed_adrq_after_max_active_runs_lift_does_not_create_empty_runtest_partitioned_same_key_events_during_max_active_runs_land_on_next_runairflow-core/tests/unit/models/test_dag.pytest_dags_needing_dagruns_assets_stale_flag_does_not_hide_adrqtest_dags_needing_dagruns_assets_retains_adrq_at_max_active_runstest_dags_needing_dagruns_assets_max_active_runs_twoWas generative AI tooling used to co-author this PR?
Generated-by: Grok 4.6 following the guidelines