SakshamSinghal20 opened a new pull request, #61342:
URL: https://github.com/apache/airflow/pull/61342

   # Description
   
   This PR fixes a bug in Airflow 3 where tasks would remain stuck in a 
`queuing` state without logs after being "cleared" following a backtracking or 
backfill operation. 
   
   ### The Problem
   When a task is cleared in a historical `DagRun` (backtracking), the state 
transition was not properly signaling the Scheduler's admission logic or the 
new Airflow 3 Execution API. As a result:
   - The `TaskInstance` state was updated in the database, but the Scheduler 
did not prioritize it for admission.
   - The task stayed in `queuing` because the hand-off between the Metadata DB 
and the Task SDK was not successfully re-triggered for backfilled runs.
   
   ### The Fix
   - Updated `airflow/models/taskinstance.py` to ensure that clearing tasks 
correctly resets the internal state and triggers a re-admission check.
   - Adjusted logic in `airflow/jobs/scheduler_job_runner.py` to ensure that 
historical `DagRuns` with newly cleared tasks are not ignored by the scheduling 
loop.
   - Ensured the Execution API correctly handles "re-queued" tasks from 
backtracking scenarios.
   
   closes: #61246
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes (Gemini 3 Flash)
   
   Generated-by: Gemini 3 Flash following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   
   ---
   
   ### How to verify this change
   1. Create a simple DAG with a few tasks.
   2. Run a backfill or manual backtracking operation until the tasks are 
marked as success.
   3. Manually "Clear" one of the tasks in the UI or CLI.
   4. Observe that the task now moves from `queued` -> `running` -> `success` 
instead of hanging indefinitely in `queuing`.
   5. Check that task logs are correctly generated and accessible in the UI.
   
   ### Tests added
   - Added unit test in `tests/models/test_taskinstance.py` to verify state 
transition after backfill clearing.
   - Added integration test in `tests/jobs/test_scheduler_job.py` to ensure the 
scheduler admits cleared historical tasks.


-- 
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]

Reply via email to