Set task_callback_type when scheduler purges tasks without heartbeats#65404
Open
kimhaggie wants to merge 1 commit intoapache:mainfrom
Open
Set task_callback_type when scheduler purges tasks without heartbeats#65404kimhaggie wants to merge 1 commit intoapache:mainfrom
kimhaggie wants to merge 1 commit intoapache:mainfrom
Conversation
When a task instance stops heartbeating (e.g. worker OOMKilled, node eviction), ``_purge_task_instances_without_heartbeats`` sends a ``TaskCallbackRequest`` to the DAG processor. The request was created without a ``task_callback_type``, so it defaulted to ``None``; the DAG processor's ``_execute_task_callbacks`` then dispatched the request to ``on_failure_callback`` even when the task still had retries remaining, producing spurious failure alerts. Use a direct ``ti.max_tries > 0 and ti.try_number <= ti.max_tries`` check rather than ``ti.is_eligible_to_retry()``: the scheduler does not eagerly load ``ti.task`` here, and the latter's "task not loaded" fallback ignores ``task.retries`` and can incorrectly report retry-eligibility for tasks declared with ``retries=0``. Fixes apache#65400 Signed-off-by: kimhaggie <kimhaggie@gmail.com>
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #65400.
_purge_task_instances_without_heartbeatswas building aTaskCallbackRequestwithouttask_callback_type. The field defaults toNone, andis_failure_callbacktreatsNoneas a failure, so the DAG processor ranon_failure_callbackeven when the task still had retries left. This caused spurious failure alerts for tasks that ultimately succeeded on retry.Changes
airflow-core/src/airflow/jobs/scheduler_job_runner.py: settask_callback_typewhen constructing the callback request in_purge_task_instances_without_heartbeats, based onti.max_tries > 0 and ti.try_number <= ti.max_tries.airflow-core/tests/unit/jobs/test_scheduler_job.py: add parametrized regression test (retries=1→UP_FOR_RETRY,retries=0→FAILED).airflow-core/newsfragments/65400.bugfix.rst: changelog entry.Why a direct check instead of
ti.is_eligible_to_retry()?Adopting the existing pattern elsewhere in this file (
task_callback_type=(UP_FOR_RETRY if ti.is_eligible_to_retry() else FAILED)near L1372 onmain) was the obvious first instinct, but the unit test uncovered thatis_eligible_to_retry()has a fallback branch:_purge_task_instances_without_heartbeats()doesn't eagerly loadti.task, so it takes that branch — which returnsTrueforretries=0tasks (try_number=0 <= max_tries=0). A directti.max_tries > 0 and ti.try_number <= ti.max_triescheck matches the "task loaded" branch ofis_eligible_to_retry()(bool(self.task.retries and self.try_number <= self.max_tries)) and avoids the false positive.Happy to discuss whether the preferred fix is this direct check, or to eagerly load
ti.taskfirst and keepis_eligible_to_retry()— whichever is more in line with project style.Test plan
breeze testing core-testslocally — the new test passes; no regressions in neighboring tests (test_scheduler_passes_context_from_server_on_heartbeat_timeout,test_external_kill_sets_callback_type_param).Out of scope
scheduler_job_runner.pyL1372 may have the sameis_eligible_to_retry()fallback issue depending on whether its caller loadsti.task. Left as a follow-up since it's a separate code path.