Add TaskGroup-level retries to retry a whole group as a unit
related: #21867
Implements the minimal v1 scope for TaskGroup retries I proposed on the dev list, a first step toward #21867. A TaskGroup can now be retried as a unit, the way SubDag once could. The richer options from the issue and thread are left for follow-up PRs.
What's in this v1
@task_group(retries=2) # or: with TaskGroup("g", retries=2): ...
def collect_and_publish():
publish(collect())
- When any task in the group fails (after its own task-level retries), the whole group is cleared and re-run, up to retries times; once exhausted the run fails as usual. Default retries=0 keeps today's behavior.
- Tasks outside the group are untouched (no upstream_failed spill-over) and running siblings are restarted. Nested groups retry innermost-first with independent counters.
Group retries run at the top of DagRun.update_state, before scheduling decisions, so a failure is cleared before it can propagate downstream. Covered by SDK, serialization, and scheduler integration tests.
Out of v1 (follow-ups) retry_condition (any/last/custom), retry_strategy (all / only-failed), group-level retry_delay, mapped-group retries.
Demo
The example DAG has a collect_and_publish group with retries=2, and publish is intentionally made to fail on its first two attempts and succeed on the third, so the group is retried twice before it goes green. In the run below:
collectandpublishboth run 3 times. A group retry re-runs every task in the group, not just the one that failed.startandfinish, which sit outside the group, each run once.
https://github.com/user-attachments/assets/807e3086-3412-4bfe-a912-57f2256e0678
Was generative AI tooling used to co-author this PR?
- [x] Yes (please specify the tool below)
- Opus 4.8
- Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
- For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
- When adding dependency, check compliance with the ASF 3rd Party License Policy.
- For significant user-facing changes create newsfragment:
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.
@yuseok89 — I've removed the ready for maintainer review label because the next step here is yours: this branch now has merge conflicts with main. It'll go back into the maintainer queue automatically once you rebase onto the latest main and push — no need to re-add the label by hand. There's no rush.
Automated triage note drafted by an AI-assisted tool — may get things wrong; a real Apache Airflow maintainer takes the next look once it's green. (why automated)
Drafted-by: Claude Code (Opus 4.8); reviewed by @potiuk before posting