Skip to content

Fetch deadline callback context via Execution API at runtime#66608

Open
seanghaeli wants to merge 7 commits into
apache:mainfrom
aws-mwaa:ghaeli/callback-context-execution-api
Open

Fetch deadline callback context via Execution API at runtime#66608
seanghaeli wants to merge 7 commits into
apache:mainfrom
aws-mwaa:ghaeli/callback-context-execution-api

Conversation

@seanghaeli
Copy link
Copy Markdown
Contributor

@seanghaeli seanghaeli commented May 8, 2026

Summary

Replace the simple context workaround from #55241 that stored serialized context in trigger kwargs (DB). Now that #55068 gives the triggerer API access, fetch the DagRun at execution time via the Execution API and build context fresh.

This avoids DB bloat from serialized context, provides fresh (not stale) context, and builds a richer context dict including logical_date, ds, ts, conf, data_interval_start/end, and the deadline info.

Changes

  • deadline.py: Remove get_simple_context(). Store only identifiers (dag_id, run_id, deadline_id, deadline_time) in callback kwargs.
  • callback.py: Add _build_context() that fetches DagRun via SUPERVISOR_COMMS.asend(GetDagRun(...)). Backward compat: old callbacks with "context" key still work.
  • triggerer_job_runner.py: Add GetDagRun to ToTriggerSupervisor union, DagRunResult to ToTriggerRunner union, handler in _handle_request.
  • callback_supervisor.py: Add GetDagRun to CallbackToSupervisor union + handler for executor callback path.
  • Tests: Updated deadline model tests, added context-fetching test, backward-compat test, GetDagRun handler test.

Testing

Ran in Breeze to verify the comms plumbing works e2e:

  • Confirmed GetDagRun round-trips through the triggerer's ToTriggerSupervisor_handle_requestDagRunResult response path without breaking existing trigger handling
  • Verified SUPERVISOR_COMMS.asend() is the correct async calling pattern — uses TriggerCommsDecoder from init_comms() with async lock for coroutine safety in the trigger event loop
  • Verified the DagRun generated model has all fields accessed in _build_context: logical_date, data_interval_start, data_interval_end, conf
  • Backward compat confirmed: old callbacks with stored "context" key (queued before this change) still work

Motivation

Per @ramitkataria's feedback on #64984: context should not be stored in the DB. The triggerer now has API access (#55068), so fetch it at runtime like tasks do.

Related

…in DB

Replace the simple context workaround from apache#55241 that stored serialized
context in trigger kwargs. Now that apache#55068 gives the triggerer API access,
fetch the DagRun and build context at execution time.

This avoids DB bloat from serialized context, provides fresh (not stale)
context, and enables richer context information. The CallbackTrigger now
uses SUPERVISOR_COMMS.asend(GetDagRun(...)) to fetch the DagRun details
from the Execution API when it runs, rather than receiving a pre-built
context dict from the scheduler.

Changes:
- deadline.py: Store only identifiers (dag_id, run_id, deadline_id,
  deadline_time) in callback kwargs instead of serialized context
- callback.py: Add _build_context() that fetches DagRun via Execution API;
  maintain backward compat for old callbacks with "context" key
- triggerer_job_runner.py: Add GetDagRun/DagRunResult to triggerer comms
- callback_supervisor.py: Add GetDagRun to executor callback comms

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@seanghaeli
Copy link
Copy Markdown
Contributor Author

@ramitkataria incorporated your feedback from #64984
@ferruzzi

your reviews would be much appreciated!

Sean Ghaeli added 5 commits May 8, 2026 22:54
The CallbackTrigger legitimately imports from airflow.sdk to communicate
with the supervisor via the Execution API at runtime, similar to
triggers/base.py and jobs/triggerer_job_runner.py which are already
excluded.
@seanghaeli seanghaeli marked this pull request as ready for review May 9, 2026 03:24
@potiuk potiuk added the ready for maintainer review Set after triaging when all criteria pass. label May 11, 2026
Copy link
Copy Markdown
Contributor

@ferruzzi ferruzzi left a comment

Choose a reason for hiding this comment

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

Just a quick question, otherwise LGTM.

Comment thread airflow-core/src/airflow/triggers/callback.py
Address review feedback: only include deadline keys that have non-None
values, preventing the callback from receiving unexpected None entries.
Copy link
Copy Markdown
Contributor

@ferruzzi ferruzzi left a comment

Choose a reason for hiding this comment

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

Approved pending CI passing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:deadline-alerts AIP-86 (former AIP-57) area:task-sdk area:Triggerer ready for maintainer review Set after triaging when all criteria pass.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants