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
Contributor

Choose a reason for hiding this comment

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

Comment thread airflow-core/docs/core-concepts/dags.rst Outdated
Comment thread airflow-core/docs/core-concepts/dags.rst Outdated
…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 ?

Comment thread task-sdk/src/airflow/sdk/definitions/dag.py Outdated
Comment thread airflow-core/docs/core-concepts/dags.rst
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 after triaging when all criteria pass. label Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants