Skip to content

Reject cyclic TaskGroup dependencies during Dag parsing - #73087

Open
dheerajturaga wants to merge 3 commits into
apache:mainfrom
dheerajturaga:reject-cyclic-taskgroup-dependencies
Open

dheerajturaga wants to merge 3 commits into
apache:mainfrom
dheerajturaga:reject-cyclic-taskgroup-dependencies

Conversation

@dheerajturaga

@dheerajturaga dheerajturaga commented Sep 13, 2026 •

Copy link
Copy Markdown
Member

Task graphs can be acyclic while cross-group edges create a cycle when sibling TaskGroups are treated as units. Downstream consumers require an unambiguous group ordering, so this rejects the configuration during Dag parsing instead of allowing it to fail later in Grid or Graph endpoints.

The check covers root and nested TaskGroup scopes, reports the offending scope, documents the restriction, and adds Task SDK and DagBag regression tests.

Before this PR, a Dag with cyclic TaskGroup dependencies could parse and run its tasks normally. #69933 fixed the group-level topological sort used by Grid and Graph to actually detect group-to-group and cross-group edges — it previously ignored them and rendered an arbitrary, incorrect order instead of failing. That turned a pre-existing cycle in a Dag's TaskGroups into an unhandled error from the Grid/Graph API endpoints rather than a rendering quirk. This PR moves that failure to Dag parsing time instead, where it raises a clear import error naming the offending TaskGroup.

This supersedes #72822

image
Was generative AI tooling used to co-author this PR?
  • Yes — Codex (GPT-5), Claude Code (Sonnet 5)

Generated-by: Codex (GPT-5) and Claude Code (Sonnet 5) following the guidelines

TaskGroup dependency projections must remain acyclic because downstream consumers require an unambiguous group ordering.

@Vamsi-klu Vamsi-klu left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

​

…gment

Review feedback on the parse-time TaskGroup cycle check: the doc's example
claimed any cross-group task pairing triggers rejection, but the check only
projects edges landing on a group's root tasks, so it understated what is
and isn't caught. Reworded with an accurate example, and added the
newsfragment the check's user-facing behavior change was missing, noting
that apache#69933 is what turned a pre-existing cyclic-TaskGroup Dag from a
silent rendering quirk into an unhandled Grid/Graph error, which is what
this PR now catches earlier at parse time instead.
@dheerajturaga

Copy link
Copy Markdown
Member Author

@ashb , If you are happy with this can we merge? looking to merge in time for 3.3.2

@dheerajturaga

Copy link
Copy Markdown
Member Author

@vatsrahul1001, Any chance to get this in 3.3.2 ?

Review feedback on the parse-time TaskGroup cycle check: the exception only
named the containing TaskGroup, which collapses to the uninformative <root>
for a cycle between top-level siblings and gives no hint which nodes to
fix on a Dag with many groups. The sweep and pass-numbering sort passes
already know which nodes never got processed, so surface those ids on
the exception and include them in the message.

Also documented and tested a second cycle shape the docs missed: a task
with no upstream inside its own TaskGroup counts as a root of that group,
so an external task can bridge two of a group's own tasks and close a
cycle without a second TaskGroup in sight -- something that reads like an
ordinary Dag until it fails to parse.
@dheerajturaga dheerajturaga added the ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green. label Sep 15, 2026
task_group_dict = self.task_group.get_task_group_dict()
for task_group in task_group_dict.values():
try:
task_group.topological_sort(group_dict=task_group_dict)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Non-blocking: I found a case where the full Dag passes this validation, but filtering it still causes Graph and Grid to return HTTP 500.

from airflow.providers.standard.operators.empty import EmptyOperator
from airflow.sdk import DAG, TaskGroup

with DAG("filter_cycle", schedule=None) as dag:
    with TaskGroup("g"):
        first = EmptyOperator(task_id="first")
        second = EmptyOperator(task_id="second")
        guard = EmptyOperator(task_id="guard")
        guard >> second
    bridge = EmptyOperator(task_id="bridge")
    first >> bridge >> second

Tested in Breeze on f0677f67705, using SQLite and the actual FastAPI routes:

  • Parsing and dag.check_cycle() succeed; unfiltered Graph and Grid requests return 200.
  • Adding root=g.first&include_downstream=true makes both requests return 500. With server exceptions enabled, both raise ValueError("A cyclic dependency occurred in dag: ...").

Filtering removes g.guard, so g.second becomes a group root and the projected dependencies become g ↔ bridge. I also executed the same dependency shape with four PythonOperator tasks: all succeeded, but the filtered requests still failed afterwards.

A control using the base revision's DAG.check_cycle() reproduces the same failure, so this is pre-existing, not a regression introduced by this PR. Would you consider this filtered-view case in scope here, or leave it for a separate follow-up?


Drafted-by: Codex (GPT-5); reviewed by @shubhamraj-git before posting

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks for the thorough repro. I agree this is out of scope here. Root membership is recomputed on the filtered subset, so partial_subset() can turn a non-root into a root and create a group-level cycle that doesn't exist in the full Dag. Parse-time validation can't prevent that without rejecting far more Dags. The fix belongs in the Grid/Graph ordering, which needs to tolerate group-level cycles either way. I'll track this in #73678 as part of the "fix the Grid/Graph 500" track and handle it in a separate PR.


Drafted-by: Claude Code (Opus 5.5); reviewed by @dheerajturaga before posting

@michiel-de-muynck

Copy link
Copy Markdown

As a user who would be affected by this PR (we have DAGs where the task groups are logical groupings, per database schema, with no bearing on Airflow dependencies), I have two questions:

  1. Is this not considered a breaking change? Should it not follow the deprecation policy in the Airflow release process, i.e., print deprecation warnings now, make the DAGs invalid starting from Airflow 4.0.0? I'm particularly concerned that you seem to be targeting a patch-level release for this PR.
  2. There is no GitHub issue for the broken grid view in the UI described in this PR and in the PR UI: Fix Grid view for bidirectional TaskGroup dependencies #72822 that was closed in favor of this PR. Should we make one? Do you want me to make one?

@dheerajturaga

Copy link
Copy Markdown
Member Author

As a user who would be affected by this PR (we have DAGs where the task groups are logical groupings, per database schema, with no bearing on Airflow dependencies), I have two questions:

  1. Is this not considered a breaking change? Should it not follow the deprecation policy in the Airflow release process, i.e., print deprecation warnings now, make the DAGs invalid starting from Airflow 4.0.0? I'm particularly concerned that you seem to be targeting a patch-level release for this PR.
  2. There is no GitHub issue for the broken grid view in the UI described in this PR and in the PR UI: Fix Grid view for bidirectional TaskGroup dependencies #72822 that was closed in favor of this PR. Should we make one? Do you want me to make one?

I agree here. Let me create an issue and discussion thread so that we can get some consensus from the community. stay tuned

@dheerajturaga

dheerajturaga commented Sep 24, 2026 •

Copy link
Copy Markdown
Member Author

Related: #73678, which is a community discussion on how to handle cyclic TaskGroup dependencies and how to roll out any breaking change.

Discussion: https://lists.apache.org/thread/sossl7b2w2ftyk4028qrhps2tcdxj2px

Drafted-by: Claude Code (Opus 5.5); reviewed by @dheerajturaga before posting

@dheerajturaga dheerajturaga removed this from the Airflow 3.4.0 milestone Sep 26, 2026
@dheerajturaga dheerajturaga removed backport-to-v3-3-test ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green. labels Sep 26, 2026
@dheerajturaga

Copy link
Copy Markdown
Member Author

This PR will mostlikely be merged after 3.4 targeting milestone 3.5

@michiel-de-muynck

Copy link
Copy Markdown

If that is the decision of the maintainers, can I ask you to update the deprecation policy? Because that makes an explicit promise that is not being kept here.

@dheerajturaga dheerajturaga added this to the Airflow 3.5.0 milestone Oct 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions Bot added the stale Stale PRs per the .github/workflows/stale.yml policy file label Nov 27, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:dag-processor area:task-sdk kind:documentation stale Stale PRs per the .github/workflows/stale.yml policy file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants