Uh oh!
There was an error while loading. Please reload this page.
AIP-103: Adding periodic task state garbage collection and retention support - #66463
Conversation
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
jason810496
left a comment
There was a problem hiding this comment.
Would it be better to introduce batching / pagination for the task state garbage collection?
Uh oh!
There was an error while loading. Please reload this page.
082d92d to
7dc826dCompare7dc826d to
b644ce6CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
28ea4fd to
f52ce27CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Wei Lee <weilee.rx@gmail.com>
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Lee-W
left a comment
There was a problem hiding this comment.
besides the typo and description, looks good to me. thanks!
Uh oh!
There was an error while loading. Please reload this page.
amoghrajesh
commented
May 14, 2026
Thanks for review folks, merging this one, we can always revise it as need comes. |
Uh oh!
There was an error while loading. Please reload this page.
closes: #66459
What?
Task state rows live as long as their parent DAG run. In deployments that don't run airflow db cleanup — or where task state should expire sooner than the DAG run — rows accumulate indefinitely. This PR adds an explicit retention mechanism independent of DAG run cleanup. To perform effective cleanup, following is needed:
task_staterows older than N daysasset_activeentry is deleted, butasset_staterows stay behind silentlyProposed change
expires_atcolumn ontask_state-updated_atalone can't distinguish a 7 day key from a 30 day key. NULL means fall back to the globaldefault_retention_days; set means delete after this timestamp regardless ofupdated_at. Settingdefault_retention_days = 0disables time-based cleanup entirely (expires_atcleanup still runs).BaseStateBackend.cleanup()no-op default — custom backends override this to implement their own retention policy. The backend reads[state_store] default_retention_daysfrom config itself since the AIP says "the backend is responsible for enforcing the retention policy."[state_store]:default_retention_days = 30(task_state only — does not affect asset_state) andclear_on_success = False.MetastoreStateBackend.cleanup()runs two passes for task_state: rows pastupdated_at + default_retention_dayscutoff, and rows withexpires_at < now().airflow state-store cleanupCLI command — callsget_state_backend().cleanup(). Operators schedule this via cron or a maintenance DAG. Supports--dry-run._update_asset_orphanage()— runs in the same pass as asset deregistration, which is when the orphans are created. This is the right home since it is an internal consistency operation, not a user-facing data lifecycle decision.Why a CLI command instead of the scheduler?
Running cleanup as a scheduler periodic task was considered but there will be concerns regarding performance to the scheduler because cleanup doesn't come without a time cost.
A dedicated CLI keeps the separation clean, schedule it where it makes sense for a deployment.
User implications / backcompat
New config options under
[state_store]with safe defaults — no action needed to maintain existing behaviour. Theexpires_atcolumn is nullable; existing rows getNULL(global default retention applies).Testing
Test setup
Ran a dag with single task instance and pushed 3 task states for it
Global Retention test
Run this query:
Run the state store cleanup:
What's next
clear_on_successhook: Clear task state on TI success #66460task_state.set(retention_days=N)API to populateexpires_atat write time: Add ability for Per task state key retention at operator level #66461Was generative AI tooling used to co-author this PR?
{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.