Skip to content

Conversation

@amoghrajesh
Copy link
Contributor

@amoghrajesh amoghrajesh commented Dec 29, 2025

closes: #54701

Why?

Simply stating, for client server separation.

The airflow.listeners module was used between airflow-core and task-sdk. By extracting the shared components to a shared library, I am intending to solve the problem of cross dependency between airflow-core and task-sdk.

What's done?

  1. Created shared/listeners/ library containing:

    • ListenerManager class (manages plugin registration and hook dispatching)
    • hookimpl marker for implementing listeners
  2. Hook specs are now houses by where they're called from:

    Spec Location Called from SDK? Called from Core?
    lifecycle Shared Yes Yes
    taskinstance Shared Yes Yes
    dagrun Core No Yes
    asset Core No Yes
    importerrors Core No Yes
  3. Both airflow-core and task-sdk now:

    • Import shared listener infrastructure via symlinks (_shared/listeners/)
    • Register only the hookspecs they actually need/use
  4. SDK now only registers specs it actually uses:

    • lifecycle (on_starting, before_stopping)
    • taskinstance (on_task_instance_*)

Open Questions and Direction to proceed

  1. Type hints in hook specs

    The specs use TYPE_CHECKING imports to avoid runtime dependencies:

    • taskinstance spec uses union type RuntimeTaskInstance | TaskInstance since it's called from both SDK workers and Core API server

TODO

  • Update providers using listeners manager to consume from task sdk
  • Split specs: shared (lifecycle, taskinstance) vs core-only (dagrun, asset, importerrors)
  • Move unit tests for listeners / write new ones
  • Update documentation

^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in airflow-core/newsfragments.

@amoghrajesh amoghrajesh added this to the Airflow 3.2.0 milestone Dec 29, 2025
@amoghrajesh amoghrajesh self-assigned this Dec 29, 2025
@amoghrajesh amoghrajesh marked this pull request as draft December 29, 2025 12:40
@amoghrajesh amoghrajesh marked this pull request as ready for review December 30, 2025 10:55
@amoghrajesh amoghrajesh force-pushed the move-listeners-to-shared branch 2 times, most recently from 93d3cf8 to 11403fb Compare January 7, 2026 06:11
@amoghrajesh amoghrajesh force-pushed the move-listeners-to-shared branch from 1d8a0b8 to c463664 Compare January 7, 2026 06:25
@amoghrajesh amoghrajesh changed the title Extract airflow listeners as a shared library Move listeners module to shared library for client server separation Jan 7, 2026
@amoghrajesh amoghrajesh requested review from kaxil and potiuk January 7, 2026 06:40
Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good - I tnink dagnode leaked from another branch - but other than that - it's exactly how I imagined it :)

@potiuk
Copy link
Member

potiuk commented Jan 7, 2026

Also - there are two remaining questions about tests -> I am not sure why we have task.sdk in airflow-core unit tests ?

@amoghrajesh
Copy link
Contributor Author

@kaxil there's a request changes from you over here, could you take a look again? Or remove the request change if your veto was handled?

Copy link
Member

@uranusjr uranusjr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaning up changeset

@amoghrajesh amoghrajesh force-pushed the move-listeners-to-shared branch from 8a02228 to 4a63f94 Compare January 8, 2026 08:06
@amoghrajesh amoghrajesh merged commit 0b341e6 into apache:main Jan 8, 2026
222 checks passed
@amoghrajesh amoghrajesh deleted the move-listeners-to-shared branch January 8, 2026 14:16
dabla pushed a commit to dabla/airflow that referenced this pull request Jan 8, 2026
…pache#59883)

Extract the listeners infrastructure to `shared/listeners/` library to eliminate cross dependencies between airflow-core and task-sdk.

- ListenerManager and hookimpl marker now in shared library
- Hook specs split by callers:
  - shared: lifecycle, taskinstance (called from both sdk and core)
  - core: dagrun, asset, importerrors (called only from core)
- sdk registers only specs it actually uses (lifecycle, taskinstance)
- core registers all specs for full listener support
chirodip98 pushed a commit to chirodip98/airflow-contrib that referenced this pull request Jan 9, 2026
…pache#59883)

Extract the listeners infrastructure to `shared/listeners/` library to eliminate cross dependencies between airflow-core and task-sdk.

- ListenerManager and hookimpl marker now in shared library
- Hook specs split by callers:
  - shared: lifecycle, taskinstance (called from both sdk and core)
  - core: dagrun, asset, importerrors (called only from core)
- sdk registers only specs it actually uses (lifecycle, taskinstance)
- core registers all specs for full listener support
stegololz pushed a commit to stegololz/airflow that referenced this pull request Jan 9, 2026
…pache#59883)

Extract the listeners infrastructure to `shared/listeners/` library to eliminate cross dependencies between airflow-core and task-sdk.

- ListenerManager and hookimpl marker now in shared library
- Hook specs split by callers:
  - shared: lifecycle, taskinstance (called from both sdk and core)
  - core: dagrun, asset, importerrors (called only from core)
- sdk registers only specs it actually uses (lifecycle, taskinstance)
- core registers all specs for full listener support
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move Listeners into airflow_shared module

4 participants