seunggabi opened a new pull request, #77603:
URL: https://github.com/apache/airflow/pull/77603
Marking a Dag run as **queued** (UI "Mark run as queued" / `PATCH
.../dagRuns/{run_id}` with `state=queued`) only changes `state`. Clearing task
instances of a finished run, by contrast, also resets
`last_scheduling_decision` and `start_date` when the run goes back to queued
(`clear_task_instances` in `taskinstance.py`).
The scheduler picks queued runs ordered by `last_scheduling_decision` (nulls
first) before `run_after` (`DagRun.get_queued_dag_runs_to_set_running`).
`last_scheduling_decision` is 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=True` and `max_active_runs=1` this deadlocks the Dag:
```
2026-08-24 queued <- marked queued, keeps last_scheduling_decision,
picked last
2026-08-25 running <- picked first; every task waits for 08-24
(depends_on_past)
```
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_decision` and `start_date` when a run is
set to queued, matching what clearing does, so queued runs of the same Dag are
picked in `run_after` order.
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?
- [X] Yes (please specify the tool below)
Generated-by: Claude Code following [the
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
---
* Read the **[Pull Request
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#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](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
is needed.
* When adding dependency, check compliance with the [ASF 3rd Party License
Policy](https://www.apache.org/legal/resolved.html#category-x).
* For significant user-facing changes create newsfragment:
`{pr_number}.significant.rst`, in
[airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
You can add this file in a follow-up commit after the PR is created so you
know the PR number.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]