Skip to content

Move dag-level callbacks to worker #44354

Open

Description

@kaxil

We will move callbacks to workers. TBD on “how”.

Options:

  1. Moving callbacks to workers as a separate activity.
  2. Running callbacks as teardown task.
  3. Deprecate (not remove) concept of callback and pushing users to use teardown. If we do this and deprecate/not remove this option will happen with one of the above two options.
  4. Leave them in dag-processor

I am leaning towards (2) — and (3) is my next preference. This is because imo callbacks and teardowns are sort of redundant concepts, and if we keep them as is, we will have an explosion of callbacks, we already have: on_{success,failure,skipped,retry,execute}_callback .

Activity

  1. converted this from a draft issue on Nov 25, 2024
  2. added
    area:task-execution-interface-aip72
    on Nov 25, 2024
  3. potiuk commented on Nov 26, 2024

    @potiuk
    Member

    The (2) sounds like a really good idea (not for all callbacks though). It would be great to see callbacks as implicit "tasks" in Airflow UI. Though not all callbacks can be done this way I am afraid. "on_retry" and "on execute" are particularly not fitting the "teardown" concept. The "on_execute" might be an implicit "setup" task, but "on_retry" is a bit problematic

  4. eladkal commented on Dec 1, 2024

    @eladkal
    Contributor

    we need to consider what happens when task succeeded but callback wasn't. We need retry for callbacks but if for example worker is terminated between task success to callback execution how would it retry?
    Also on_sla_callback() and on_execute_callback() can't be part of teardown. We need to verify with AIP-86 what is the plan for sla callback as part of the deadline interface and if it conflicts with the plan we choose to take here cc @ferruzzi @romsharon98

  5. ferruzzi commented on Dec 3, 2024

    @ferruzzi
    Contributor

    The plan for Deadlines is to add a simple check in the scheduler loop, essentially (obviously pseudocode): if (select min(deadline) from DeadlinesTable) < utcnow(): handle_deadline_misses() My intention was for the handler to spin up a new process to run the callbacks so it isn't holding anything else up, but let me know if that plan needs to change with this initiative.

  6. added this to the Airflow 3.0.0 milestone on Jan 17, 2025
  7. changed the title [-]Move callbacks to worker[/-] [+]Move dag-level callbacks to worker[/+] on Mar 17, 2025
  8. moved this from Todo to Next 2 Weeks in AIP-72 - Task Execution Interface and SDKon Mar 17, 2025
  9. moved this from Next 2 Weeks to Icebox in AIP-72 - Task Execution Interface and SDKon Mar 17, 2025
  10. VladaZakharova commented on May 6, 2025

    @VladaZakharova
    Contributor

    Should there be a timeout for task callbacks (like on_success_callback) in case they hang (e.g., due to API delays or infinite loops), so they don't block task completion?
    Something similar to execution_timeout, but specifically for callbacks.
    This could help avoid issues where long or broken callbacks prevent task success from being registered.
    WDYT?

  11. added a commit that references this issue on Jun 27, 2025
  12. baylisscg commented on Jul 2, 2025

    @baylisscg

    I managed to hit this for reasons I'm unclear about under 3.0.2.

    It was being raised by the DAG Processor after parsing a dag file that generates 27 DAGs from a config file (time python on the file reports sub-second runtime). I could see an error pointing me here from airflow-core/src/airflow/dag_processing/processor.py

    Unfortunately this was causing all the DAGs that file generated to be dropped which was, regrettably, all of them.

    After turning on debugging and much poking about I found this in the DAG processing log for the file:

    {
      "timestamp": "2025-07-01T00:00:10.108010",
      "level": "debug",
      "event": "Processing Callback Request",
      "request": "{\"filepath\":\"extract.py\",\"bundle_name\":\"dags-folder\",\"bundle_version\":null,\"msg\":\"{'DAG Id': '#####', 'Task Id': '#####', 'Run Id': 'backfill__2024-12-12T00:00:00+00:00', 'Map Index': 2, 'Hostname': 'f3d38ea38a99', 'External Executor Id': '15bbb640-d659-44be-a26b-7bc2030b4b4e'}\",\"ti\":{\"id\":\"0197aefa-80b8-73cd-a588-17b61f373a76\",\"task_id\":\"'#####',\",\"dag_id\":\"'#####',\",\"run_id\":\"backfill__2024-12-12T00:00:00+00:00\",\"try_number\":1,\"map_index\":2,\"hostname\":\"f3d38ea38a99\",\"context_carrier\":{}},\"task_callback_type\":null,\"type\":\"TaskCallbackRequest\"}",
      "logger": "task"
    }

    So the DAG processor was creating a TaskCallbackRequest for running backfill task? After shutting off all the backfills killing the task the processor worked again happily but I'm concerned I can't use backfill without triggering this as it's not clear why it happened.

  13. 19 remaining items

  14. ramitkataria commented on Oct 21, 2025

    @ramitkataria
    Contributor

    I believe option 1 should be relatively straightforward to implement once support for ExecuteCallback is added to workers, which is in progress

    class ExecuteCallback(BaseDagBundleWorkload):

  15. xkarkosx commented on Dec 10, 2025

    @xkarkosx

    --- Supervised process Last chance exception handler ---
    Traceback (most recent call last):
    File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/supervisor.py", line 376, in _fork_main
    target()
    File "/home/airflow/.local/lib/python3.12/site-packages/airflow/dag_processing/processor.py", line 126, in _parse_file_entrypoint
    result = _parse_file(msg, log)
    ^^^^^^^^^^^^^^^^^^^^^
    File "/home/airflow/.local/lib/python3.12/site-packages/airflow/dag_processing/processor.py", line 142, in _parse_file
    _execute_callbacks(bag, msg.callback_requests, log)
    File "/home/airflow/.local/lib/python3.12/site-packages/airflow/dag_processing/processor.py", line 182, in _execute_callbacks
    raise NotImplementedError(
    NotImplementedError: Haven't coded Task callback yet - #44354!

    I have the same problem. Will updating fix it? I'm currently using helm chart 1.18.0 with airflow 3.0.2. Will chart 1.19.0-dev with appVersion: 3.1.3 fix the problem?

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

    area:task-execution-interface-aip72

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions