Repository navigation
Conversation
Clearing task instances of a finished run resets last_scheduling_decision and start_date when the run goes back to queued, but marking a run as queued through the API or UI only changed its state. The scheduler orders queued runs by last_scheduling_decision (nulls first) before run_after, so a run that was running and then marked queued kept its old value and could be picked after later runs of the same Dag. With depends_on_past and max_active_runs=1 the later run then waits for the earlier one forever.
seunggabi
requested review from
ephraimbuddy,
jason810496 and
pierrejeambrun
as code owners
November 25, 2026 18:35
This was referenced Nov 25, 2026
session.scalar returns DagRun | None, so reassigning it to the DagRun variable failed mypy. Load the run into a separate variable and assert it is not None, like the other tests in this file.
This branch has not been deployed
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.
Marking a Dag run as queued (UI "Mark run as queued" /
PATCH .../dagRuns/{run_id}withstate=queued) only changesstate. Clearing task instances of a finished run, by contrast, also resetslast_scheduling_decisionandstart_datewhen the run goes back to queued (clear_task_instancesintaskinstance.py).The scheduler picks queued runs ordered by
last_scheduling_decision(nulls first) beforerun_after(DagRun.get_queued_dag_runs_to_set_running).last_scheduling_decisionis only written while a run is running, so a run that was running and is then marked queued keeps an old non-null value, and later runs of the same Dag with a null value are picked first.With
depends_on_past=Trueandmax_active_runs=1this deadlocks the Dag:The earlier run can never start because the later run holds the only active slot, and the later run's tasks never start because they wait for the earlier run. We hit this on a production deployment (hundreds of Dags stuck in this state after runs were re-queued).
This change resets
last_scheduling_decisionandstart_datewhen a run is set to queued, matching what clearing does, so queued runs of the same Dag are picked inrun_afterorder.A unit test covers it; it fails without the change (
assert dr.last_scheduling_decision is None) and passes with it.Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code 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.