Skip to content

Add auto-clear of failed child tasks to TriggerDagRunOperator (#53402) - #71730

Open
eugeneo17 wants to merge 3 commits into
apache:mainfrom
CloudGeometry:feat/53402-auto-clear-failed-tasks
Open

eugeneo17 wants to merge 3 commits into
apache:mainfrom
CloudGeometry:feat/53402-auto-clear-failed-tasks

Conversation

@eugeneo17

Copy link
Copy Markdown

closes: #53402

TriggerDagRunOperator gains an opt-in auto_clear_failed_tasks flag (default False) that lets a parent-task retry resume a failed child run from its point of failure instead of dead-ending.

Motivation
Chained-DAG pipelines commonly pin the child's trigger_run_id (or its logical_date) so the child run is idempotent, one run per business date/key, so a parent retry doesn't spawn duplicate child runs. But with wait_for_completion=True, that same stability makes retries a dead end: once the pinned child run has failed, re-running the parent task raises DagRunAlreadyExists, and the only escape today is reset_dag_run=True, which wipes the whole child and re-runs tasks that already succeeded. There is no way to resume a failed child from where it stopped without manual cleanup.

What this does
On the parent task's retry, when the pinned child run already exists in a terminal failed state, auto_clear_failed_tasks=True clears only the failed tasks (and their downstream) of that run and re-runs them, preserving already-successful tasks - the child resumes rather than restarts or errors.

The failed-only clear is delivered server-side via a new Execution API version (2026-11-13, AddOnlyFailedToClearDagRunPayload); the only_failed flag is threaded operator → task-runner → supervisor → SDK client, and on a 409 conflict the client routes the trigger to the /clear endpoint with only_failed=true.
reset_dag_run keeps precedence: if both are set the whole run is cleared, and at most one clear ever happens.
It is version-gated, against a core older than 2026-11-13 the operator raises NotImplementedError rather than silently downgrading to a whole-run clear.

Scope and notes
Synchronous only (wait_for_completion=True); not supported with deferrable=True (setting both raises ValueError).
Because previously-successful child tasks are not re-run and failed ones are, the triggered DAG's tasks should be idempotent - called out in the operator docstring and the operator guide.
A healed child run's final state reads success, so run-level alerting won't see the transient failure (per-attempt logs are preserved). Emitting a metric/event when a heal fires would close that gap and is proposed as a follow-up rather than part of this PR.

Testing
Unit tests for the operator, the Task SDK (comms/supervisor/task-runner/client), and the Execution API version + payload. Includes a regression test asserting the failed-only clear is reached when reset_dag_run=False (the auto_clear path), which fails against a client that gates the clear on reset_dag_run alone.

Was generative AI tooling used to co-author this PR?
[X] Yes (please specify the tool below)
Generated-by: Claude Code (Opus 4.8) following the guidelines

@boring-cyborg

boring-cyborg Bot commented Aug 17, 2026

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example Dag that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@eugeneo17
eugeneo17 force-pushed the feat/53402-auto-clear-failed-tasks branch from fa12a66 to c4c565a Compare September 14, 2026 10:31
@eugeneo17
eugeneo17 force-pushed the feat/53402-auto-clear-failed-tasks branch 2 times, most recently from b34ec5a to e038c69 Compare September 24, 2026 12:02
eugeneo17 added a commit to CloudGeometry/airflow that referenced this pull request Sep 25, 2026
Document the new Execution API version 2026-11-13 and the opt-in
auto_clear_failed_tasks behavior on TriggerDagRunOperator.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@eugeneo17

Copy link
Copy Markdown
Author

Hi, this PR implements #53402: an opt-in auto_clear_failed_tasks flag for TriggerDagRunOperator (default False), so a parent retry can resume a failed child run instead of dead-ending. I've just merged the latest main (no conflicts). It's my first contribution here, so the CI workflows need approval to run. Could a committer approve them and take a look when there's time? Happy to adjust anything.

eugeneo17 and others added 2 commits October 15, 2026 03:16
When TriggerDagRunOperator waits for a triggered child run
(wait_for_completion=True) and that child fails, retrying the parent task
previously dead-ended on DagRunAlreadyExists, or with reset_dag_run re-ran
the entire child from scratch and discarded already-successful tasks.

This adds an opt-in auto_clear_failed_tasks flag: on the parent task's
retry it clears only the failed tasks (and their downstream) of the
existing child run so the child resumes from its point of failure while
preserving work that already succeeded. reset_dag_run keeps precedence when
both are set. The failed-only clear is delivered server-side through a new
Execution API version (2026-11-13); against an older core the operator
raises rather than silently downgrading to a whole-run clear.

Includes operator, task-SDK and execution-API unit tests, plus a regression
test asserting the failed-only clear is reached when reset_dag_run=False
(the gap that let the feature ship as a no-op).

closes: apache#53402
Document the new Execution API version 2026-11-13 and the opt-in
auto_clear_failed_tasks behavior on TriggerDagRunOperator.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@eugeneo17
eugeneo17 force-pushed the feat/53402-auto-clear-failed-tasks branch from 6c39c95 to 5e3865d Compare October 15, 2026 07:17

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for automatic clearing of failed child DAG tasks in TriggerDagRunOperator

1 participant