Skip to content

Fix max_active_tis_per_dag for deferred task instances#61769

Draft
SakshamSinghal20 wants to merge 1 commit intoapache:mainfrom
SakshamSinghal20:sok
Draft

Fix max_active_tis_per_dag for deferred task instances#61769
SakshamSinghal20 wants to merge 1 commit intoapache:mainfrom
SakshamSinghal20:sok

Conversation

@SakshamSinghal20
Copy link
Copy Markdown
Contributor

@SakshamSinghal20 SakshamSinghal20 commented Feb 11, 2026

closes: #61700

Description

Deferred tasks were previously excluded from max_active_tis_per_dag and max_active_tis_per_dagrun concurrency checks. This allowed an unlimited number of tasks to enter the DEFERRED state, bypassing configured limits.

This PR enforces these limits for DEFERRED task instances while ensuring that max_active_tasks (which limits worker slot usage) remains unaffected.

Changes:

  • airflow/ti_deps/dependencies_states.py: Introduced TASK_CONCURRENCY_EXECUTION_STATES to include DEFERRED, RUNNING, and QUEUED.
  • airflow/jobs/scheduler_job_runner.py: Updated ConcurrencyMap to count deferred TIs for task-level limits, but explicitly exclude them from dag_run_active_tasks_map.
  • airflow/models/taskinstance.py: Updated get_num_running_task_instances to count deferred TIs for pre-execution dependency checks.

Tests:

Added unit tests covering:

  • Deferred tasks blocking new scheduling attempts.
  • Mixed state scenarios (Running + Deferred).
  • Regression checks ensuring max_active_tasks is not impacted.

Was generative AI tooling used to co-author this PR?
  • Yes (used for guidance and file locating)

@boring-cyborg boring-cyborg bot added the area:Scheduler including HA (high availability) scheduler label Feb 11, 2026
Copy link
Copy Markdown
Contributor

@Nataneljpwd Nataneljpwd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I will check out the tests soon

@SakshamSinghal20
Copy link
Copy Markdown
Contributor Author

Just let me know if everything is right or do i need to change anything else?

@SakshamSinghal20
Copy link
Copy Markdown
Contributor Author

Hi @jscheffl and @Nataneljpwd! I'm a new contributor and I am very interested in participating in GSoC with this organization this year. I've been reading through the contributing guidelines, but I wanted to ask if there are any specific parts of the codebase you'd recommend I focus on to make a meaningful impact?

@jscheffl
Copy link
Copy Markdown
Contributor

Hi @jscheffl and @Nataneljpwd! I'm a new contributor and I am very interested in participating in GSoC with this organization this year. I've been reading through the contributing guidelines, but I wanted to ask if there are any specific parts of the codebase you'd recommend I focus on to make a meaningful impact?

I'd take a look for https://github.com/apache/airflow/issues?q=is%3Aissue%20state%3Aopen%20label%3A%22good%20first%20issue%22

@phanikumv phanikumv requested a review from uranusjr February 25, 2026 06:44
@SakshamSinghal20
Copy link
Copy Markdown
Contributor Author

@uranusjr I have changed the state to Active. also let me know if i need to do anything else before the PR gets merged.
Thank you.

@jscheffl
Copy link
Copy Markdown
Contributor

jscheffl commented Mar 1, 2026

@uranusjr I have changed the state to Active. also let me know if i need to do anything else before the PR gets merged. Thank you.

Discussion in Devlist is still ongoing. I think the outcome of this influenced the implementation strategy of this PR. Please do not merge before settled.

Copy link
Copy Markdown
Contributor

@jscheffl jscheffl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Request changes" mainly to block merge as long as devlist discussion not finalized

@SakshamSinghal20
Copy link
Copy Markdown
Contributor Author

"Request changes" mainly to block merge as long as devlist discussion not finalized

Understood.

@jscheffl
Copy link
Copy Markdown
Contributor

"Request changes" mainly to block merge as long as devlist discussion not finalized

Understood.

Called for LAZY CONSENSUS in devlist in https://lists.apache.org/thread/qvnfj09qlktmbpdpcsgkbdb8pdmfzm77

Would it be OK to prepare the PR towards this so that in 3 days it is ready to be merged?
As this is quite important for me and our setup, let me know if I shall support in making the changes or fixes.

@jscheffl jscheffl dismissed their stale review March 16, 2026 20:02

Reset "Request changes" and looking forward for completion!

@jscheffl
Copy link
Copy Markdown
Contributor

Lazy consensus passed. WOuld it be possible to complete the PR for review by the next 24h?

@potiuk
Copy link
Copy Markdown
Member

potiuk commented Apr 2, 2026

@SakshamSinghal20 This PR has been converted to draft because it does not yet meet our Pull Request quality criteria.

Issues found:

  • Pre-commit / static checks: Failing: CI image checks / Static checks. Run prek run --from-ref main locally to find and fix issues. See Pre-commit / static checks docs.
  • mypy (type checking): Failing: CI image checks / MyPy checks (mypy-airflow-core). Run prek --stage manual mypy-airflow-core --all-files locally to reproduce. You need breeze ci-image build --python 3.10 for Docker-based mypy. See mypy (type checking) docs.
  • Other failing CI checks: Failing: Postgres tests: core / DB-core:Postgres:14:3.10:API...Serialization, MySQL tests: core / DB-core:MySQL:8.0:3.10:API...Serialization, Sqlite tests: core / DB-core:Sqlite:3.10:API...Serialization, Non-DB tests: core / Non-DB-core::3.10:API...Serialization, Integration and System Tests / Integration core kerberos (+3 more). Run prek run --from-ref main locally to reproduce. See static checks docs.
  • ⚠️ Unresolved review comments: This PR has 2 unresolved review threads from maintainers: @jscheffl (MEMBER): 1 unresolved threads; @uranusjr (MEMBER): 1 unresolved threads. Please review and resolve all inline review comments before requesting another review. You can resolve a conversation by clicking 'Resolve conversation' on each thread after addressing the feedback. See pull request guidelines.

Note: Your branch is 1377 commits behind main. Some check failures may be caused by changes in the base branch rather than by your PR. Please rebase your branch and push again to get up-to-date CI results.

What to do next:

  • The comment informs you what you need to do.
  • Fix each issue, then mark the PR as "Ready for review" in the GitHub UI - but only after making sure that all the issues are fixed.
  • There is no rush — take your time and work at your own pace. We appreciate your contribution and are happy to wait for updates.
  • Maintainers will then proceed with a normal review.

Converting a PR to draft is not a rejection — it is an invitation to bring the PR up to the project's standards so that maintainer review time is spent productively. There is no rush — take your time and work at your own pace. We appreciate your contribution and are happy to wait for updates. If you have questions, feel free to ask on the Airflow Slack.

@potiuk potiuk marked this pull request as draft April 2, 2026 17:24
@SakshamSinghal20 SakshamSinghal20 force-pushed the sok branch 2 times, most recently from 2d0f089 to 1a3fd87 Compare April 3, 2026 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Scheduler including HA (high availability) scheduler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

max_active_tis_per_dag not enforced for deferred task instances

5 participants