cipheraxat opened a new pull request, #69770: URL: https://github.com/apache/airflow/pull/69770
## Summary When a pool has `include_deferred=True`, deferred tasks correctly occupy slots, but after the trigger fires the task instance goes `deferred → scheduled` and previously **stopped counting** until it was queued/running again. That undercounts pool usage and weakens pools as a semaphore around external resources (the motivation for including deferred tasks in the first place). This change counts **post-deferral** `scheduled` task instances — those with `next_method` set — toward pool occupancy when `include_deferred` is enabled: - `Pool.occupied_slots()` / `Pool.slots_stats()` open calculation - `Pool.task_instance_occupies_slot()` used by `PoolSlotsAvailableDep` so a TI that already holds a slot does not block itself First-lifetime `scheduled` tasks (no `next_method`) are **not** counted, which would otherwise deadlock scheduling when `open = total - scheduled`. * closes: #69187 ## Test plan - [x] `test_open_slots_including_deferred_counts_post_deferral_scheduled` - [x] `test_open_slots_excluding_deferred_ignores_post_deferral_scheduled` - [x] `test_post_deferral_scheduled_pooled_task_pass` (pool slots available dep) - [x] Existing pool / deferred occupancy tests still pass - [x] `prek` on changed files --- ##### Was generative AI tooling used to co-author this PR? - [x] Yes (please specify the tool below) <!-- Generated-by: Cursor following the guidelines https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions --> Generated-by: Cursor 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. -- 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]
