Skip to content

Cover clearing task state based on dag run clear #72929

Description

@amoghrajesh

Why?

#72100 added discard-by-default behavior for task_state_store entries when a task instance
is cleared via the POST /dags/{dag_id}/clearTaskInstances endpoint — checkpoints are
discarded unless keep_task_state is set, so a cleared task starts over instead of silently
resuming from a stale checkpoint after the underlying code/data was fixed.

That fix only applies to that one endpoint. Every other way of clearing a task instance still
keeps task state unconditionally, because each of them calls clear_task_instances() directly
instead of going through the new discard logic:

  • Clearing an entire Dag run (the "Clear Run" dialog / API) —
    perform_clear_dag_run -> dag.clear() -> clear_task_instances().
  • Marking a task as failed/success, which clears downstream tasks as a side effect.
  • airflow dags clear / airflow tasks clear (core CLI) —
    cli/commands/dag_command.py -> clear_task_instances() directly.

Follow-up work

Thread keep_task_state (or an equivalent opt-out) through clear_task_instances() itself, so
every caller (REST endpoint, Dag-run clear, CLI, mark-as-success/failed) converges on the same
discard-by-default behavior. This likely needs:

  • A keep_task_state parameter on clear_task_instances().
  • Plumbing it through dag.clear(), perform_clear_dag_run, and the core CLI's
    airflow dags clear / airflow tasks clear.
  • Deciding the right default/UX for callers that have no request body to carry the flag today
    (e.g. CLI defaults, mark-as-success/failed).

Acceptance criteria

  • Clearing a Dag run discards task_state_store entries by default, matching the task-instance
    clear endpoint, with an equivalent opt-out to keep state.
  • airflow dags clear / airflow tasks clear behave consistently with the REST endpoints.
  • Docs (resumable-tasks.rst) no longer need to caveat which clear surface actually discards.

Activity

  1. self-assigned this
    on Sep 11, 2026
  2. added this to the Airflow 3.4.0 milestone on Sep 11, 2026
  3. added theissue type on Sep 13, 2026
  4. yi-wang-ai commented on Oct 1, 2026

    @yi-wang-ai

    Reproduced on current main: clearing a Dag run leaves its task_state_store checkpoint behind. The new regression fails before the fix, while the existing clear test passes.

    A local fix moves deletion into clear_task_instances() and threads the preservation option through single/bulk Dag-run clear and both core CLI clear commands. Tests cover default deletion, explicit preservation, dry-run, untouched scopes, and downstream clearing. The related PostgreSQL suite passed with 1,057 tests; an additional Dag/clear suite passed with 335 tests (the suites overlap).

    The patch and PR description are prepared locally; a PR has not been opened yet.


    Drafted-by: OpenAI Codex (GPT-6) (no human review before posting)

  5. amoghrajesh commented on Oct 5, 2026

    @amoghrajesh
    ContributorAuthor

    Adding a comment here. This is waiting on a draft AIP - AIP-123.

  6. cmarteepants commented on Nov 9, 2026

    @cmarteepants
    Collaborator

    @amoghrajesh I don't think we should block this on AIP-123. AIP-123 adds a new scope, but this issue is about task state that’s already shipped. Clearing a task instance discards it by default, while clearing a Dag run keeps it. We should be consistent. I’d add keep_task_state to Dag run clear now and let AIP-123 add its own flag for run state.

    It’s also going to come up a lot more as we increase coverage with durable operators. Today, clearing a Dag run skips any ResumableJobMixin task whose external job already succeeded, and there’s no way to opt out from the Clear Run dialog.

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

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions