Skip to content

Lang-SDK coordinator tasks do not run their task callbacks #74063

Open

Description

@jason810496

A @task.stub task that a coordinator runs in a Lang-SDK runtime (Go, Java, TypeScript) never runs the task callbacks declared on it in the Python Dag, such as on_failure_callback and on_success_callback. Callbacks run only inside the Python task runner (_run_task_state_change_callbacks in task-sdk/src/airflow/sdk/execution_time/task_runner.py). The Lang-SDK runtime cannot run them, and neither the supervisor nor the Execution API sends a callback request when such a task finishes. The only exception is the scheduler's state-mismatch path ("killed externally?"), which does send a callback request to the Dag processor.

Proposal: when a coordinator task reaches a final state, request its task callbacks so the Dag processor runs them from the Python Dag file, as it already does for a task that was killed externally.


Drafted with Claude Code (Opus 5.5).

Activity

  1. sudeep876 commented on Oct 2, 2026

    @sudeep876

    Hi @jason810496,
    I’d like to work on this issue. Could you please assign it to me?
    My understanding is that coordinator runtimes should not execute the Python callbacks themselves. Instead, when a coordinator-run @task.stub task reaches a final state, Airflow should request that the DAG Processor run the task’s callbacks, using a mechanism similar to the existing “killed externally” callback path.
    Does that sound like the right direction? If so, I’ll trace the existing callback request flow and open a draft PR for early feedback.

  2. luc-pimentel commented on Oct 31, 2026

    @luc-pimentel
    Contributor

    I reproduced this on 3.4.0rc2 with the TypeScript runtime and want to send a PR. Before I open it, I want to confirm the approach, because you asked on #74578 to fix this in the supervisor or the SDK runtime rather than in the Execution API, and to handle language-SDK Dags and Python Dags with stub tasks separately.

    For a Python Dag with @task.stub tasks, I see two options in the supervisor:

    1. When the runtime finishes, the supervisor tells the server to run the callbacks for this task. The server queues the same callback request it queues today for a task killed externally, and the Dag processor runs it. Same path Task-level failure callbacks are not triggered when tasks are SIGKILLed #60858 picked for a killed task process. The Dag processor also needs to run on_success_callback, which it skips today.
    2. The supervisor starts a Python process on the worker, loads the Dag file from the bundle and runs the callbacks there. No server change, but the worker has to load the Dag file, and the Dag processor's callback code gets copied.

    I built option 1 locally to test it. The stub tasks' success, failure and retry callbacks ran in the Dag processor, same lines as the Python tasks. The flag goes in the URL of the state update, not in the body, because the success and retry bodies are also what a runtime sends to the supervisor, and a new field there would mean a new supervisor schema version. Dags written in a language SDK stay out, since they have no task callbacks. Is this what you had in mind? Happy to send the PR.

    Tested with one Dag that has a Python task and a stub task for each outcome, all with the same success, failure and retry callbacks. Before: the Python tasks wrote their callback lines, the stub tasks wrote none, the callback table stayed empty. With option 1: every task wrote its lines, retry included.

  3. seanmuth commented on Nov 3, 2026

    @seanmuth
    Contributor

    @jason810496 following up on @luc-pimentel's question above, since the same design question applies to #60858 (task process SIGKILLed while the supervisor survives, so neither on_failure_callback nor the OL FAIL event runs).

    We'd like to push for luc's option 1: the supervisor decides that a callback is needed and flags it on the state update, and the API server only queues the callback request for the Dag processor. That is the same queue the scheduler already uses on the "killed externally" mismatch path.

    This looks compatible with fixing at the supervisor level. The supervisor can't run the callback itself, because it doesn't parse the Dag file and doesn't write to the callback table, so the queuing has to happen server-side. The difference from #74578 is that the server doesn't infer on its own that a callback is needed. The supervisor makes that call and the server just enqueues it.

    We don't like option 2 either (the supervisor starts a Python process and runs the callbacks itself). It would make the worker load the Dag file and would duplicate the Dag processor's callback code. It also looks race-prone: the supervisor would be running a new process while it is reporting the final state and exiting, so the callback could be cut off if the pod is terminated. When the original kill was an OOM, the new process would run in the same memory-starved pod.

    With option 1, #74063 and #60858 could share one mechanism, with a single flag on the state update and different triggers. Does that direction work for you? If so, I'm happy to help with the implementation.

  4. ashb commented on Nov 3, 2026

    @ashb
    Member

    So I think the first question to answer: Does it make sense to have python callbacks on a task defined in another language? Is this really something we want to support?

    I have to admit, that my first thought is "no", and if you want callbacks, those should be defined on the other language side too when you define the task handler.

  5. luc-pimentel commented on Nov 5, 2026

    @luc-pimentel
    Contributor

    So I think the first question to answer: Does it make sense to have python callbacks on a task defined in another language? Is this really something we want to support?
    I have to admit, that my first thought is "no", and if you want callbacks, those should be defined on the other language side too when you define the task handler.

    For a Python Dag with stub tasks, I think it would make sense. The task is still declared in the Python Dag, and its callbacks are set there like its retries, often once in default_args for every task. Only the body runs in the other language.

    If the answer is no, maybe the stub tasks should at least say so? Because today they accept the callbacks and just never run them nor raise any way to observe this behavior (no logs, nor warnings or anything).

    For comparison, retry_policy is already rejected on @task.stub. The Dag fails to parse with a ValueError, even when the policy comes from default_args, because the policy is Python code and nothing would run it. Callbacks are also Python code, but they are accepted. Unlike a retry policy, they have somewhere else to run, because the Dag processor already runs failure callbacks when a task is killed.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions