Skip to content

Add support for rescheduling tasks to RetryPolicy #74660

Closed

Description

@stephen-bracken

Description

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.

Related issues

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    kind:feature
    needs-triage
    on Oct 13, 2026
  2. kadubhumika commented on Oct 13, 2026

    @kadubhumika
    Contributor

    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?

  3. self-assigned this
    on Oct 13, 2026
  4. kaxil commented on Oct 13, 2026

    @kaxil
    Member

    @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.

  5. removed
    needs-triage
    on Oct 13, 2026
  6. kaxil commented on Oct 13, 2026

    @kaxil
    Member

    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:

    KubernetesPodOperator(
        ...,
        deferrable=True,
        schedule_timeout_seconds=4 * 60 * 60,
    )

    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.

  7. stephen-bracken commented on Oct 14, 2026

    @stephen-bracken
    ContributorAuthor

    @kaxil in our RetryPolicy we would reschedule the task on the following conditions:

    • ResourceQuota exceeded - kubernetes returns 403 response on pod creation, immediately fails the task
    • Pods being Evicted from the node due to memory pressure (terminated reason == Evicted)
    • Pods being OOMKilled
  8. stephen-bracken commented on Oct 14, 2026

    @stephen-bracken
    ContributorAuthor
  9. kaxil commented on Oct 14, 2026

    @kaxil
    Member

    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.

  10. stephen-bracken commented on Oct 14, 2026

    @stephen-bracken
    ContributorAuthor

    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.

  11. stephen-bracken commented on Oct 14, 2026

    @stephen-bracken
    ContributorAuthor

    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.

  12. kaxil commented on Oct 14, 2026

    @kaxil
    Member

    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.

  13. kadubhumika commented on Oct 14, 2026

    @kadubhumika
    Contributor

    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!

  14. kaxil commented on Oct 14, 2026

    @kaxil
    Member

    PR: #74719

  15. added 2 commits that reference this issue on Oct 18, 2026
    af3fa8d
    b10513b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind:feature

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions