You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add support for rescheduling tasks to RetryPolicy #74660
The RetryDecision interface for task policies does not support Rescheduling as an option. In our KubernetesPodOperator tasks we Reschedule the task if a capacity constraint is encountered ( NamespaceQuota is full, Nodes are unavailable for scheduling ). We do this because at the start of the day our kubernetes cluster remains full of airflow pods for an extended period of time. If we want to convert our tasks to use the RetryPolicy API then we will need to be able to select a RetryAction.RESCHEDULE option, as our tasks are rescheduled ~ every 10 minutes when capacity is unavailable, and it may be several hours before capacity becomes available. To use the retry policy with this mechanism would require setting an unreasonable number of retries on our tasks.
Use case/motivation
Add a RetryAction.RESCHEDULE option to the RetryDecision and RetryPolicy interfaces, update the execution interface to reschedule task instances when a RetryAction.RESCHEDULE is received.
Hi @stephen-bracken and maintainers! I would love to work on this feature.
I'm currently inspecting the codebase, checking out the RetryDecision / RetryPolicy interfaces, and looking into the related issue (#67118) to understand the context.
Could you please assign this issue to me? Thanks! or should i start working and push pr?
The wait happens in the triggerer so no worker slot is held, and the pod starts when a node frees up rather than on your next 10 minute poll. Downside is the Pending pods sit in the cluster and Kubernetes picks the order, not Airflow priority weights, so if that's a problem for you let me know.
A full ResourceQuota is different: create returns a 403, KPO doesn't retry it, and there's no pod to wait on. Today you'd have to subclass the operator to raise AirflowRescheduleException, or set a lot of retries.
That's where I think RetryAction.RESCHEDULE belongs, and it's useful beyond KPO for anything waiting on capacity. It shouldn't need an Execution API change since any task can already go to UP_FOR_RESCHEDULE; the task runner would send the same reschedule message sensors use. Try number and retries stay untouched and on_retry_callback won't fire.
I'll make the reschedule bounded (by count or elapsed time) and fall back to the normal retry/fail logic past that, since a rule matching a broad exception would otherwise keep rescheduling real failures forever.
If you can paste the error from one of the failed attempts, that'd help.
Thanks, that helps. The quota 403 fits what I described: the pod never ran, so a reschedule that doesn't spend a retry is the right outcome.
Evicted and OOMKilled are different, because the pod did run. Eviction under node memory pressure is capacity, I agree. But an OOMKill from going over the container's own memory limit happens again on every attempt, so a reschedule just loops until the bound kicks in. Does your setup tell those apart, e.g. burstable pods getting killed by node pressure vs a real limit breach?
There's also a gap on the KPO side. A failed pod currently comes back as a plain AirflowException with the termination message in the text, so a policy can only find Evicted or OOMKilled by string matching. I'd rather fix that in KPO with a typed exception that carries the pod's termination reason, so a RetryRule can match on it. That's a separate provider change from RESCHEDULE in the SDK.
On the code pointer: no need for that one. I wrote the retry policy plumbing, so I know where this change goes. What I can't see from here is how it fails in your cluster, so details like the ones above are what help most.
We catch the ApiException from the kubernetes client library before the AirflowException gets raised, and use that to determine what kind of failure mode it is. OOMKilled and Evicted are different states in k8s so its easy to tell them apart from the pod status.
I should clarify, we have a mechanism for rescaling pods automatically which kicks in on OOMKilled statuses, the pod is rescaled when it gets rescheduled.
to be clear, I'm mostly interested in the RetryAction.RESCHEDULE being added here, the KubernetesPodOperator changes are already implemented for us internally, and I could upstream these in a future PR. My current goal is to convert this mechanism to use the new RetryPolicy API, but we need the reschedule action to do this.
Makes sense, thanks. I'll put up the PR for RetryAction.RESCHEDULE, and a follow-up upstreaming the typed KPO exceptions would be welcome.
One scoping note so this doesn't get mixed up with AIP-97 / AIP-122. RESCHEDULE is for when the task's own code decides that the external system it drives isn't ready, here the cluster KPO launches pods into. The Airflow worker itself ran fine, and the Dag author's policy makes the call.
Disruption of the Airflow worker (executor pod preempted, Spot capacity reclaimed) is what AIP-97 classifies as infra and what AIP-122 grants admin-capped retries for. A retry policy never sees those, since the worker is gone. So RESCHEDULE won't touch failure_kind, and the docs won't describe it as an infrastructure failure.
Thanks for the explanation, @kaxil That makes total sense regarding the difference between Quota/Eviction and OOMKilled, as well as the need for typed exceptions in KPO. Looking forward to seeing this feature land!
Activity
kadubhumika commentedon Oct 13, 2026
Hi @stephen-bracken and maintainers! I would love to work on this feature.
I'm currently inspecting the codebase, checking out the
RetryDecision/RetryPolicyinterfaces, and looking into the related issue (#67118) to understand the context.Could you please assign this issue to me? Thanks! or should i start working and push pr?
kaxil commentedon Oct 13, 2026
@kadubhumika Thanks, but I am going to take this on since these interfaces are very new and want to ensure design remain consistent with future paths.
kaxil commentedon Oct 13, 2026
Thanks @stephen-bracken. Are you seeing pods stuck in
Pending, or pod creation rejected by the namespace quota? The answer changes what you need here.For Pending pods KPO can already wait without burning retries:
The wait happens in the triggerer so no worker slot is held, and the pod starts when a node frees up rather than on your next 10 minute poll. Downside is the Pending pods sit in the cluster and Kubernetes picks the order, not Airflow priority weights, so if that's a problem for you let me know.
A full
ResourceQuotais different: create returns a 403, KPO doesn't retry it, and there's no pod to wait on. Today you'd have to subclass the operator to raiseAirflowRescheduleException, or set a lot of retries.That's where I think
RetryAction.RESCHEDULEbelongs, and it's useful beyond KPO for anything waiting on capacity. It shouldn't need an Execution API change since any task can already go toUP_FOR_RESCHEDULE; the task runner would send the same reschedule message sensors use. Try number andretriesstay untouched andon_retry_callbackwon't fire.I'll make the reschedule bounded (by count or elapsed time) and fall back to the normal retry/fail logic past that, since a rule matching a broad exception would otherwise keep rescheduling real failures forever.
If you can paste the error from one of the failed attempts, that'd help.
stephen-bracken commentedon Oct 14, 2026
@kaxil in our RetryPolicy we would reschedule the task on the following conditions:
stephen-bracken commentedon Oct 14, 2026
This is where a change is necessary, we need to implement support for a
RetryAction.RESCHEDULEhere:https://github.com/apache/airflow/blob/main/task-sdk/src/airflow/sdk/execution_time/task_runner.py#L1943
kaxil commentedon Oct 14, 2026
Thanks, that helps. The quota 403 fits what I described: the pod never ran, so a reschedule that doesn't spend a retry is the right outcome.
Evicted and OOMKilled are different, because the pod did run. Eviction under node memory pressure is capacity, I agree. But an OOMKill from going over the container's own memory limit happens again on every attempt, so a reschedule just loops until the bound kicks in. Does your setup tell those apart, e.g. burstable pods getting killed by node pressure vs a real limit breach?
There's also a gap on the KPO side. A failed pod currently comes back as a plain
AirflowExceptionwith the termination message in the text, so a policy can only findEvictedorOOMKilledby string matching. I'd rather fix that in KPO with a typed exception that carries the pod's termination reason, so aRetryRulecan match on it. That's a separate provider change fromRESCHEDULEin the SDK.On the code pointer: no need for that one. I wrote the retry policy plumbing, so I know where this change goes. What I can't see from here is how it fails in your cluster, so details like the ones above are what help most.
stephen-bracken commentedon Oct 14, 2026
We catch the ApiException from the kubernetes client library before the AirflowException gets raised, and use that to determine what kind of failure mode it is. OOMKilled and Evicted are different states in k8s so its easy to tell them apart from the pod status.
I should clarify, we have a mechanism for rescaling pods automatically which kicks in on OOMKilled statuses, the pod is rescaled when it gets rescheduled.
stephen-bracken commentedon Oct 14, 2026
to be clear, I'm mostly interested in the
RetryAction.RESCHEDULEbeing added here, the KubernetesPodOperator changes are already implemented for us internally, and I could upstream these in a future PR. My current goal is to convert this mechanism to use the new RetryPolicy API, but we need the reschedule action to do this.kaxil commentedon Oct 14, 2026
Makes sense, thanks. I'll put up the PR for
RetryAction.RESCHEDULE, and a follow-up upstreaming the typed KPO exceptions would be welcome.One scoping note so this doesn't get mixed up with AIP-97 / AIP-122.
RESCHEDULEis for when the task's own code decides that the external system it drives isn't ready, here the cluster KPO launches pods into. The Airflow worker itself ran fine, and the Dag author's policy makes the call.Disruption of the Airflow worker (executor pod preempted, Spot capacity reclaimed) is what AIP-97 classifies as
infraand what AIP-122 grants admin-capped retries for. A retry policy never sees those, since the worker is gone. SoRESCHEDULEwon't touchfailure_kind, and the docs won't describe it as an infrastructure failure.kadubhumika commentedon Oct 14, 2026
Thanks for the explanation, @kaxil That makes total sense regarding the difference between Quota/Eviction and OOMKilled, as well as the need for typed exceptions in KPO. Looking forward to seeing this feature land!
kaxil commentedon Oct 14, 2026
PR: #74719
Let retry policies reschedule a task without using a retry (#74719) (#…
Let retry policies reschedule a task without using a retry (#74719) (#…