Repository navigation
Conversation
Expose known worker and executor causes to infrastructure listeners and telemetry while preserving ordinary retry and clear behavior. Signed-off-by: 1fanwang <1fannnw@gmail.com>
When a Celery worker child disappears, the result backend records WorkerLostError but Airflow drops it. Keep `WorkerLost` in the scheduler failure report and listener event as a reason with no category, because a lost worker alone does not establish an infrastructure cause. Ordinary retry behavior is unchanged. The providers/celery tree matches the tested source fbd551c. Signed-off-by: 1fanwang <1fannnw@gmail.com>
Preserve Task.stopCode from the ECS task response and report SpotInterruption as `infra`. Other stop codes stay diagnostic reasons without a category and missing codes stay unclassified. Callback workloads and older failure signatures keep their behavior, and no retries are granted. The providers/amazon tree matches the tested source 5819598. Signed-off-by: 1fanwang <1fannnw@gmail.com>
Resolves conflicts with the task attempt UUID and try number alignment (apache#73554): notify_failure() now also carries failure_kind and reason to the listener, _finalize_task_failure() keeps the new log parameter alongside failure_kind, and the scheduler event loop keeps the imports from both sides. The tested classification hunks are unchanged. Signed-off-by: 1fanwang <1fannnw@gmail.com>
The listener now receives failure_kind and reason, so the recorder used by test_failure_listener_receives_failed_try_before_rotation must accept them; both are None on this path and the test asserts that. Signed-off-by: 1fanwang <1fannnw@gmail.com>
Since the attempt UUID and try number alignment, a retry-eligible failure allocates the next attempt at once, so the ECS classification test expects try_number 2 when a retry remains. The heartbeat-timeout recorder also accepts the two cause keywords the listener now passes. Signed-off-by: 1fanwang <1fannnw@gmail.com>
Signed-off-by: 1fanwang <1fannnw@gmail.com> # Conflicts: # task-sdk/src/airflow/sdk/execution_time/task_runner.py # task-sdk/tests/task_sdk/execution_time/test_task_runner.py
Signed-off-by: 1fanwang <1fannnw@gmail.com>
Signed-off-by: 1fanwang <1fannnw@gmail.com> # Conflicts: # airflow-core/src/airflow/models/taskinstance.py # airflow-core/tests/unit/jobs/test_scheduler_job.py # providers/amazon/tests/unit/amazon/aws/executors/ecs/test_ecs_executor.py # providers/celery/tests/unit/celery/executors/test_celery_executor.py
Signed-off-by: 1fanwang <1fannnw@gmail.com>
Merge current main and retain the metadata contract with its SDK and scheduler consumers. Leave provider adapters in the existing ancestor commits. Preserve retry behavior and unknown causes. Signed-off-by: 1fanwang <1fannnw@gmail.com>
Pass the stop code of the last ECS attempt as the failure reason, with SpotInterruption reported as infra, for attempt-UUID and legacy task keys. Detect the contract from apache#73816 instead of gating on Airflow 3.4, which lacks it, and document it. Signed-off-by: 1fanwang <1fannnw@gmail.com>
Signed-off-by: 1fanwang <1fannnw@gmail.com> # Conflicts: # shared/listeners/src/airflow_shared/listeners/spec/taskinstance.py
o-nikolas
left a comment
There was a problem hiding this comment.
Thanks for this, the end-to-end repro is really thorough. The AIP-97 page still shows it as under discussion with the vote TBD. So this should not be merged until that VOTE happens. Maybe flip this back to DRAFT
| Airflow reports a failure category when the worker or executor can establish the cause: | ||
| ``infra``, ``application``, ``timeout``, or ``manual``. Otherwise the category remains unset. | ||
| Failure listeners and scheduler logs can also receive a short producer-owned reason, | ||
| such as Kubernetes ``PreemptionByScheduler``. |
There was a problem hiding this comment.
Since the provider adapters were dropped from this PR, no built-in executor reports a cause yet, but these paragraphs read as if Airflow already does this for Kubernetes (PreemptionByScheduler, Evicted, disruption conditions). Could we scope the docs to what ships here (application/timeout from the SDK, manual from the API, and causes a custom executor passes to fail()), and add the Kubernetes guidance with the K8s adapter PR?
Drafted-by: Kiro (claude-opus-5.5); reviewed by @o-nikolas before posting
| error: None | str | BaseException, | ||
| ): | ||
| """Execute when task state changes to FAIL. previous_state can be None.""" | ||
| failure_kind: TaskFailureKind | None, |
There was a problem hiding this comment.
How do you see listeners that support several Airflow versions (OpenLineage, say) adopting this? pluggy rejects a hookimpl argument that isn't in the hookspec, so declaring failure_kind/reason fails registration on current Airflow, and declaring them with defaults means they're never passed. The repro works around it with inspect.signature on the spec. A separate hook just for the cause would avoid that, since older versions would simply never call it. If we keep it on on_task_instance_failed, the listeners docs need a versionadded and a note about this.
Drafted-by: Kiro (claude-opus-5.5); reviewed by @o-nikolas before posting
| def _get_task_failure_kind(error: BaseException | None) -> TaskFailureKind | None: | ||
| if error is None or isinstance(error, AirflowTaskTerminated): | ||
| return None | ||
| return TaskFailureKind.TIMEOUT if isinstance(error, AirflowTaskTimeout) else TaskFailureKind.APPLICATION |
There was a problem hiding this comment.
Everything that isn't a timeout or AirflowTaskTerminated becomes application here. That includes AirflowRuntimeError, which also wraps API_SERVER_ERROR responses from the Execution API. The PR is careful not to call worker loss infra without proof. Should we be just as careful here and leave errors raised by the Airflow runtime itself (at least API_SERVER_ERROR) unset, rather than counting them as application?
Drafted-by: Kiro (claude-opus-5.5); reviewed by @o-nikolas before posting
| Failure cause | ||
| """"""""""""" | ||
|
|
||
| ``on_task_instance_failed`` can receive a :class:`~airflow.executors.base_executor.TaskFailureKind`: |
There was a problem hiding this comment.
This points listener authors to airflow.executors.base_executor.TaskFailureKind, but worker-side listeners run under the Task SDK and shouldn't import from airflow-core, and the SDK copy is in the private airflow.sdk._shared.state. Could we export it from a public SDK path and reference that? Or, since it's a str enum, just say that comparing against the string values is the supported way.
Drafted-by: Kiro (claude-opus-5.5); reviewed by @o-nikolas before posting
| - name: "operator_failures" | ||
| description: "Operator ``{operator_name}`` failures." | ||
| description: "Operator ``{operator_name}`` failures. Tagged backends include ``failure_kind``: | ||
| ``infra``, ``application``, ``timeout``, ``manual``, or ``unclassified``." |
There was a problem hiding this comment.
manual never reaches these metrics: the API's mark-failed path only calls the listener, not handle_failure(). I'd drop it from this list or say it's listener-only.
Drafted-by: Kiro (claude-opus-5.5); reviewed by @o-nikolas before posting
| ("manual", (TaskFailureKind.MANUAL, None)), | ||
| *[ | ||
| (f"reason_{reason}", (None, reason)) | ||
| for reason in ("SIGTERM", "SIGKILL", "OOMKilled", "WorkerLostError", "Evicted") |
There was a problem hiding this comment.
This file tests SchedulerJobRunner.process_executor_events, so I'd move it into tests/unit/jobs/test_scheduler_job.py. The matrix is also 40 DB tests, and the five reason-only cases all take the same path, so one would do. Small thing: the model_fields assertions at the end pass without this change too, and so does test_failure_cause_is_not_added_to_template_context in the Task SDK's test_task_runner.py.
Drafted-by: Kiro (claude-opus-5.5); reviewed by @o-nikolas before posting
Done. Checked the cwiki page too, still under discussion with the vote thread TBD, so draft is the right state until that vote happens. |
Why
A missing heartbeat tells the scheduler that a worker stopped reporting, not why. Even a SIGKILL notice identifies the signal but not who sent it. Failure listeners need a way to report a known cause without treating either observation as proof of preemption.
What
This draft implements the core part of AIP-97, Task Failure Classification. The proposal is still under discussion:
https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=399279312
The Task SDK reports application exceptions and execution timeouts to worker-side listeners. A custom executor can pass a failure category and a short reason to the scheduler. If it supplies only a reason, the listener receives that reason with no category, and the task and operator failure counters use unclassified. When a user marks a task failed through the public API, the listener receives manual.
This PR does not include a Kubernetes provider classifier or change how Airflow counts attempts. AIP-122 separately proposes when a confirmed infrastructure failure should get an extra retry:
https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=451974654
Risk
Existing listeners can keep their signatures, and existing executors can keep sending their usual info. Only the category becomes a metric tag. The SDK keeps its failure metadata on the worker; it adds no Execution API or database fields.
Testing Done
The two-file scheduler replay is the shortest check. On a fresh database at the PR head, the listener received SIGKILL without a category and the task never started. In the full run on the same head, both failure counters recorded unclassified for that notice and infra for an explicit category from the test executor. An ordinary retry succeeded on attempt 2 with max_tries still 1. The macOS and Breeze comparisons below use their own pinned base commits.
Failure before a worker starts
At 287983c the SDK reported application and timeout failures, and the retry succeeded on attempt 2 with its original retry budget:
A separate replay on that head rejected a queued task before dispatch. The executor used the legacy task key and supplied SIGKILL as its reason. The scheduler listener received the reason without inferring a category. No process received that signal.
With this checkout's Airflow environment on PATH, save the two files below in an empty directory and run:
env -i PATH="$PATH" /bin/sh check.shReproducer source: queue_notice.py
Reproducer source: check.sh
Demo on current main
Ran natively on macOS 26.7.3 (arm64) with Python 3.12.16, uv 0.13.8 and Airflow 3.5.0, against current main at 8f88f8d. The reproducer below starts the real API server, Dag processor and scheduler on a SQLite metadata database. It runs failing tasks through the Task SDK and records what a listener plugin, the failure callbacks and a DogStatsD receiver see.
Callbacks and legacy listeners kept their failed-attempt identities. ControlledBackendNotice comes from the reproducer's executor, so this run shows the custom-executor transport and the consumers rather than a production infrastructure classifier. SDK causes do not travel to the scheduler through the Execution API.
Setup in a checkout of this branch, with the four reproducer files below copied to dev/:
The core install does not include the DogStatsD client, so datadog is added at the version pinned in uv.lock.
Run:
Raw output (exit 0, 43.7 seconds):
The retry kept its ordinary attempt accounting:
Current main without this change
The same command on current main:
Raw output (exit 0, 31.5 seconds):
Linux Breeze run
The same reproducer also passed in Linux amd64 Breeze with Python 3.12.16 and Airflow 3.5.0. The control was 0bc9e82:
DogStatsD packets on the control:
DogStatsD packets and listener records with this change:
Reproducer source: aip97_core_repro.py
Reproducer source: aip97_repro_dag.py
Reproducer source: aip97_repro_executor.py
Reproducer source: aip97_repro_listener.py
Was generative AI tooling used to co-author this PR?
Generated-by: GitHub Copilot CLI (gpt-6.1-sol, claude-opus-5.5) following the guidelines