airflow icon indicating copy to clipboard operation
airflow copied to clipboard

on_task_instance_up_for_retry

Open avanish-garg opened this issue 3 months ago • 4 comments

Description

on_task_instance_failed fires identically whether a task instance is about to be automatically retried (state set to UP_FOR_RETRY) or has permanently failed (state set to FAILED). The hook call in models/taskinstance.py sits after the retry-eligibility branch and fires unconditionally either way, using the same hook name.

Use case/motivation

This makes the listener API noisy for a common use case: an alerting/paging integration built on on_task_instance_failed gets triggered on every transient retry of a flaky task, not just the final terminal failure, which undermines the signal-to-noise of building alerting on this hook.

Airflow's listener spec already carves out sub-outcomes this way elsewhere — on_task_instance_skipped exists specifically to distinguish "skipped" from the generic success/failure buckets. Same pattern fits here: a new on_task_instance_up_for_retry hookspec, fired when a task instance is set to UP_FOR_RETRY, additive alongside the existing on_task_instance_failed (left unchanged, to avoid a breaking change for existing listeners).

Related issues

Was previously opened as #72379 (closed to re-open via this form so template labels apply correctly).

Are you willing to submit a PR?

  • [x] Yes I am willing to submit a PR!

Code of Conduct

avanish-garg avatar Sep 02 '26 08:09 avanish-garg

Draft PR with an implementation: https://github.com/apache/airflow/pull/72424 (re-targeted from the previous #72379, closed to re-open via the web form so the template labels applied correctly). Went with an additive-only approach (new hook, on_task_instance_failed left unchanged) to avoid a breaking change — see the PR description for the reasoning. Happy to rework based on feedback.

cc @henry3260 @guan404ming @dheerajturaga — I see each of you has prior commits in taskinstance.py's failure-handling path, so flagging in case this area is useful for you to weigh in on. cc @potiuk as well, given the listener-registration surface this also touches (same as #36516).

avanish-garg avatar Sep 02 '26 08:09 avanish-garg

Hi @avanish-garg , Can I work on this issue ?

Hi @avanish-garg , Can I work on this issue ?

Thanks for offering. There is already a draft PR for this (#72424); I'm updating it, so I'd suggest picking a different issue to avoid duplicate work.

avanish-garg avatar Nov 20 '26 09:11 avanish-garg

#72424 is merged: it documents that on_task_instance_failed also fires for an attempt that will be retried, and that listeners can tell the two apart with task_instance.state (UP_FOR_RETRY vs FAILED). As discussed there, a separate hook is not needed, so I am closing this.


Drafted-by: Claude Code (Opus 5.5) (no human review before posting)

avanish-garg avatar Nov 26 '26 08:11 avanish-garg