Repository navigation
Reject cyclic TaskGroup dependencies during Dag parsing - #73087
dheerajturaga wants to merge 3 commits into
Conversation
TaskGroup dependency projections must remain acyclic because downstream consumers require an unambiguous group ordering.
…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.
|
@ashb , If you are happy with this can we merge? looking to merge in time for 3.3.2 |
|
@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.
| 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) |
There was a problem hiding this comment.
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 >> secondTested 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=truemakes both requests return 500. With server exceptions enabled, both raiseValueError("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
There was a problem hiding this comment.
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
|
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:
|
I agree here. Let me create an issue and discussion thread so that we can get some consensus from the community. stay tuned |
|
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/sossl7b2w2ftyk4028qrhps2tcdxj2pxDrafted-by: Claude Code (Opus 5.5); reviewed by @dheerajturaga before posting |
|
This PR will mostlikely be merged after 3.4 targeting milestone 3.5 |
|
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. |
|
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. |
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
Was generative AI tooling used to co-author this PR?
Generated-by: Codex (GPT-5) and Claude Code (Sonnet 5) following the guidelines