Skip to content

Add example Dag for checkpointing progress from an async task - #71870

Merged
amoghrajesh merged 2 commits into
apache:mainfrom
astronomer:example-dag-for-async-task-state
Sep 9, 2026
Merged

amoghrajesh merged 2 commits into
apache:mainfrom
astronomer:example-dag-for-async-task-state

Conversation

@amoghrajesh

Copy link
Copy Markdown
Contributor

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Adds example_task_state_store_async.py, showing an async def task that fetches pages concurrently and checkpoints its progress with aget/aset so a retry resumes instead of starting over.

aget/aset landed in 3.3 but have no example coverage in the repo, and this is the first async def task in example_dags/. Two deliberate choices worth calling out for review:

The checkpoint is a completed-set, not a high-water cursor. Both async examples in
task-state-store.rst track a last_page cursor, which assumes ordered sequential
completion. Under asyncio.gather, items finish out of order, so a cursor either skips
unfinished work or repeats finished work. A set is correct at any concurrency.

Only the parent coroutine writes the checkpoint. If each worker coroutine did its own
await aset, the writes would interleave at their await points, each overwriting a stale
copy of the set, and completed items would silently vanish. So the task gathers a bounded
batch and the parent checkpoints once per batch. That is the one thing in the file that
gets a comment, because the bug it avoids leaves no trace.

Progress and the running row total live under a single key so one write keeps them
consistent, which also means a resumed attempt does not lose the previous attempt's total.

The staged failure fires only on the first try, so with retries=2 the Dag run demonstrates the resume and still ends successfully on a single trigger.

closes: #66842 properly.

Testing

Try 1
image

Try 2
image

State store

image
  • 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.

@ColtenOuO ColtenOuO left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@amoghrajesh
amoghrajesh merged commit 4b1e9d2 into apache:main Sep 9, 2026
78 checks passed
@amoghrajesh
amoghrajesh deleted the example-dag-for-async-task-state branch September 9, 2026 10:27
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Backport failed to create: v3-3-test. View the failure log Run details

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-3-test Commit Link

You can attempt to backport this manually by running:

cherry_picker 4b1e9d2 v3-3-test

This should apply the commit to the v3-3-test branch and leave the commit in conflict state marking
the files that need manual conflict resolution.

After you have resolved the conflicts, you can continue the backport process by running:

cherry_picker --continue

If you don't have cherry-picker installed, see the installation guide.

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

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

Wire async task state access for AIP-98 async tasks

3 participants