Skip to content

Scheduler exits when handle_failure raises for a single task instance #76529

Open

Description

@ChickenBenny

Under which category would you file this issue?

Airflow Core

Apache Airflow version

main; the same code path is present in 3.3.2

What happened and how to reproduce it?

Follow-up from #76191 (fixing #76190).

The scheduler calls ti.handle_failure() for each task instance inside a loop, with nothing that isolates an exception raised for one task instance:

  • SchedulerJobRunner.process_executor_events, when the executor reports a failure the TI did not record itself
  • the heartbeat-timeout purge (_purge_task_instances_without_heartbeats)

If handle_failure() raises for any reason, the exception leaves _run_scheduler_loop and the scheduler process exits. After a restart the same task instance is still in the same state, so it is picked up again, raises again, and the scheduler keeps crashing. In #76190 this was a KeyError from fail_fast handling. A task with retries=0 reached try 13 in about 30 minutes, because each restart reset the TI as orphaned and ran it again.

#76191 removes that specific KeyError, but any other exception raised from handle_failure() (a failure callback lookup, fail_fast handling, a data problem in one Dag run) has the same effect. One bad task instance can stop scheduling for every Dag.

To reproduce, make handle_failure() raise for one task instance. For example, on a build without #76191, follow the steps in #76190.

What you think should happen instead?

An exception from handle_failure() for one task instance should not stop the scheduler. It should log the error with the task instance key, and leave the TI in a state that does not cause it to be picked up again in the same way, for example FAILED without the extra handling. It should then continue with the remaining task instances.

Open points:

  • If the exception comes from the database, the transaction may no longer be usable. Handling each TI inside a savepoint (session.begin_nested()) may be needed so that one TI's failure does not roll back the others.
  • Which fallback state to use when handle_failure() itself cannot complete.

Operating System

No response

Deployment

None

Apache Airflow Provider(s)

No response

Versions of Apache Airflow Providers

No response

Official Helm Chart version

Not Applicable

Kubernetes Version

No response

Helm Chart configuration

No response

Docker Image customizations

No response

Anything else?

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    kind:bugThis is a clearly a bug
    needs-triagelabel for new issues that we didn't triage yet
    on Nov 5, 2026
  2. its-amann commented on Nov 5, 2026

    @its-amann

    Hi! I'd like to work on this. Could you assign it to me? I'll follow up with a PR that includes a fix and tests.

  3. ChickenBenny commented on Nov 5, 2026

    @ChickenBenny
    ContributorAuthor

    @its-amann Sure, go ahead! Note that Airflow doesn't assign issues to contributors. See How to contribute. Just open a PR with the fix when it's ready.

    One heads-up: this touches the same code as #76191, so it will probably need to wait until that one is merged (or be rebased on top of it).

  4. its-amann commented on Nov 5, 2026

    @its-amann

    Opened a fix for this in #76544, would appreciate a look when you get a chance.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind:bugThis is a clearly a bugneeds-triagelabel for new issues that we didn't triage yet

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions