Skip to content

Keep mapped tasks when clearing with run on latest version - #76420

Merged
vatsrahul1001 merged 3 commits into
apache:mainfrom
astronomer:keep-mapped-tis-when-clearing-on-latest-version
Nov 4, 2026
Merged

vatsrahul1001 merged 3 commits into
apache:mainfrom
astronomer:keep-mapped-tis-when-clearing-on-latest-version

Conversation

@ephraimbuddy

@ephraimbuddy ephraimbuddy commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Clearing a Dag run with "run on latest version" marked every instance of a mapped task removed when the producer of its input was cleared in the same request. They stayed removed after the producer ran again, so the mapped task never re-ran and its downstream tasks ran as if it had finished.

Clearing on the latest version calls verify_integrity, which re-checks the mapped task's length. Since #74222 that length is read from the producer's current attempt, and a cleared producer's new attempt has no XCom yet. The check then took the branch that removes every expanded instance when the mapping can't be resolved. Nothing expands a removed index again: _revise_map_indexes_if_mapped only revises schedulable instances and doesn't recreate removed indexes, and no map_index=-1 placeholder is left to expand. #71425 later made the same check run for running and queued runs as well.

The expanded instances are now kept while the mapping can't be resolved. The scheduler already trims or extends them once the upstreams finish, as it did before #74222, when the length could still be read from the producer's previous run.

Changed existing test: test_mapped_literal_to_xcom_arg_verify_integrity asserted that switching a task from literal to XCom mapping, before the producer has run, removes all of its instances. Those instances were never expanded again either, so the task never ran under its new mapping. The test now checks that they are kept, then revised to the producer's length once it runs.

Follow-ups: #76445 (a re-run that maps to zero ends removed, not skipped) and #76446 (restoring an index removed by a shorter list reports a Dag re-add and adds an empty try).

closes: #76377


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 5.5)

@vatsrahul1001 vatsrahul1001 added this to the Airflow 3.4.0 milestone Nov 4, 2026
@vatsrahul1001 vatsrahul1001 added the backport-to-v3-4-test Backport to v3-4-test label Nov 4, 2026
@ephraimbuddy
ephraimbuddy force-pushed the keep-mapped-tis-when-clearing-on-latest-version branch 2 times, most recently from 448bc29 to 07b3561 Compare November 4, 2026 12:45
@uranusjr

uranusjr commented Nov 4, 2026

Copy link
Copy Markdown
Member

The last comment and the one on regression above can be done in a follow-up.

Clearing on the latest Dag version re-checks the run's task instances against
that version. When the producer of a mapped task's input is cleared in the same
request, its new attempt has no XCom yet, so the mapped length cannot be
resolved and every expanded instance was marked removed. Nothing expands a
removed index again, so the mapped task never re-ran and its downstream tasks
ran as if it had finished. The same happened when a new version switched a
task from literal to XCom mapping before the producer had run.

The scheduler already trims or extends a mapped task once its upstreams have
finished, so keeping the instances lets it settle the count from the
producer's new value.
The removal is not limited to clearing with "run on latest version". For a
run without a bundle version, the scheduler checks the run's integrity
whenever the Dag's structure changes, and before the fix that check removed
the mapped instances of a cleared producer that had not run again yet.
…rsion

A mapped index removed earlier, by a shrink or because the task left the
Dag, stayed removed after a clear on the latest version re-ran its
producer: the unresolved-count branch skipped the restore block, and
_revise_map_indexes_if_mapped never brings a removed index back.
@vatsrahul1001
vatsrahul1001 force-pushed the keep-mapped-tis-when-clearing-on-latest-version branch from 07b3561 to d10f7bc Compare November 4, 2026 14:45
@vatsrahul1001
vatsrahul1001 merged commit cd3ae40 into apache:main Nov 4, 2026
70 checks passed
@vatsrahul1001
vatsrahul1001 deleted the keep-mapped-tis-when-clearing-on-latest-version branch November 4, 2026 16:27
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Backport successfully created: v3-4-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
✅ v3-4-test PR Link

vatsrahul1001 pushed a commit that referenced this pull request Nov 4, 2026
#76420) (#76468)

* Keep mapped tasks when clearing with run on latest version

Clearing on the latest Dag version re-checks the run's task instances against
that version. When the producer of a mapped task's input is cleared in the same
request, its new attempt has no XCom yet, so the mapped length cannot be
resolved and every expanded instance was marked removed. Nothing expands a
removed index again, so the mapped task never re-ran and its downstream tasks
ran as if it had finished. The same happened when a new version switched a
task from literal to XCom mapping before the producer had run.

The scheduler already trims or extends a mapped task once its upstreams have
finished, so keeping the instances lets it settle the count from the
producer's new value.

* Test that the scheduler keeps cleared mapped tasks on Dag change

The removal is not limited to clearing with "run on latest version". For a
run without a bundle version, the scheduler checks the run's integrity
whenever the Dag's structure changes, and before the fix that check removed
the mapped instances of a cleared producer that had not run again yet.

* Restore removed mapped tasks when their producer re-runs on latest version

A mapped index removed earlier, by a shrink or because the task left the
Dag, stayed removed after a clear on the latest version re-ran its
producer: the unresolved-count branch skipped the restore block, and
_revise_map_indexes_if_mapped never brings a removed index back.
(cherry picked from commit cd3ae40)

Co-authored-by: Ephraim Anierobi <splendidzigy24@gmail.com>
github-actions Bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Nov 4, 2026
apache#76420)

* Keep mapped tasks when clearing with run on latest version

Clearing on the latest Dag version re-checks the run's task instances against
that version. When the producer of a mapped task's input is cleared in the same
request, its new attempt has no XCom yet, so the mapped length cannot be
resolved and every expanded instance was marked removed. Nothing expands a
removed index again, so the mapped task never re-ran and its downstream tasks
ran as if it had finished. The same happened when a new version switched a
task from literal to XCom mapping before the producer had run.

The scheduler already trims or extends a mapped task once its upstreams have
finished, so keeping the instances lets it settle the count from the
producer's new value.

* Test that the scheduler keeps cleared mapped tasks on Dag change

The removal is not limited to clearing with "run on latest version". For a
run without a bundle version, the scheduler checks the run's integrity
whenever the Dag's structure changes, and before the fix that check removed
the mapped instances of a cleared producer that had not run again yet.

* Restore removed mapped tasks when their producer re-runs on latest version

A mapped index removed earlier, by a shrink or because the task left the
Dag, stayed removed after a clear on the latest version re-ran its
producer: the unresolved-count branch skipped the restore block, and
_revise_map_indexes_if_mapped never brings a removed index back.
(cherry picked from commit cd3ae40)

Co-authored-by: Ephraim Anierobi <splendidzigy24@gmail.com>
vatsrahul1001 pushed a commit that referenced this pull request Nov 4, 2026
#76420) (#76468)

* Keep mapped tasks when clearing with run on latest version

Clearing on the latest Dag version re-checks the run's task instances against
that version. When the producer of a mapped task's input is cleared in the same
request, its new attempt has no XCom yet, so the mapped length cannot be
resolved and every expanded instance was marked removed. Nothing expands a
removed index again, so the mapped task never re-ran and its downstream tasks
ran as if it had finished. The same happened when a new version switched a
task from literal to XCom mapping before the producer had run.

The scheduler already trims or extends a mapped task once its upstreams have
finished, so keeping the instances lets it settle the count from the
producer's new value.

* Test that the scheduler keeps cleared mapped tasks on Dag change

The removal is not limited to clearing with "run on latest version". For a
run without a bundle version, the scheduler checks the run's integrity
whenever the Dag's structure changes, and before the fix that check removed
the mapped instances of a cleared producer that had not run again yet.

* Restore removed mapped tasks when their producer re-runs on latest version

A mapped index removed earlier, by a shrink or because the task left the
Dag, stayed removed after a clear on the latest version re-ran its
producer: the unresolved-count branch skipped the restore block, and
_revise_map_indexes_if_mapped never brings a removed index back.
(cherry picked from commit cd3ae40)

Co-authored-by: Ephraim Anierobi <splendidzigy24@gmail.com>
vatsrahul1001 pushed a commit that referenced this pull request Nov 4, 2026
#76420) (#76468)

* Keep mapped tasks when clearing with run on latest version

Clearing on the latest Dag version re-checks the run's task instances against
that version. When the producer of a mapped task's input is cleared in the same
request, its new attempt has no XCom yet, so the mapped length cannot be
resolved and every expanded instance was marked removed. Nothing expands a
removed index again, so the mapped task never re-ran and its downstream tasks
ran as if it had finished. The same happened when a new version switched a
task from literal to XCom mapping before the producer had run.

The scheduler already trims or extends a mapped task once its upstreams have
finished, so keeping the instances lets it settle the count from the
producer's new value.

* Test that the scheduler keeps cleared mapped tasks on Dag change

The removal is not limited to clearing with "run on latest version". For a
run without a bundle version, the scheduler checks the run's integrity
whenever the Dag's structure changes, and before the fix that check removed
the mapped instances of a cleared producer that had not run again yet.

* Restore removed mapped tasks when their producer re-runs on latest version

A mapped index removed earlier, by a shrink or because the task left the
Dag, stayed removed after a clear on the latest version re-ran its
producer: the unresolved-count branch skipped the restore block, and
_revise_map_indexes_if_mapped never brings a removed index back.
(cherry picked from commit cd3ae40)

Co-authored-by: Ephraim Anierobi <splendidzigy24@gmail.com>
vatsrahul1001 pushed a commit that referenced this pull request Nov 4, 2026
#76420) (#76468)

* Keep mapped tasks when clearing with run on latest version

Clearing on the latest Dag version re-checks the run's task instances against
that version. When the producer of a mapped task's input is cleared in the same
request, its new attempt has no XCom yet, so the mapped length cannot be
resolved and every expanded instance was marked removed. Nothing expands a
removed index again, so the mapped task never re-ran and its downstream tasks
ran as if it had finished. The same happened when a new version switched a
task from literal to XCom mapping before the producer had run.

The scheduler already trims or extends a mapped task once its upstreams have
finished, so keeping the instances lets it settle the count from the
producer's new value.

* Test that the scheduler keeps cleared mapped tasks on Dag change

The removal is not limited to clearing with "run on latest version". For a
run without a bundle version, the scheduler checks the run's integrity
whenever the Dag's structure changes, and before the fix that check removed
the mapped instances of a cleared producer that had not run again yet.

* Restore removed mapped tasks when their producer re-runs on latest version

A mapped index removed earlier, by a shrink or because the task left the
Dag, stayed removed after a clear on the latest version re-ran its
producer: the unresolved-count branch skipped the restore block, and
_revise_map_indexes_if_mapped never brings a removed index back.
(cherry picked from commit cd3ae40)

Co-authored-by: Ephraim Anierobi <splendidzigy24@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-to-v3-4-test Backport to v3-4-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clearing with "run on latest version" permanently removes a mapped task's instances when its input's producer is cleared too

3 participants