Skip to content

Fix one bad callback request crashing the Dag processor and dropping the rest - #70990

Merged
ephraimbuddy merged 4 commits into
apache:mainfrom
astronomer:fix-dag-processor-callback-request-isolation
Aug 14, 2026
Merged

ephraimbuddy merged 4 commits into
apache:mainfrom
astronomer:fix-dag-processor-callback-request-isolation

Conversation

@ephraimbuddy

Copy link
Copy Markdown
Contributor

A callback request that hits the documented race condition (the Dag or task was removed between scheduling the callback and parsing the file) raises out of _execute_callbacks, killing the parse subprocess. The remaining requests in the batch were already popped from the manager's queue, so on_failure_callback, on_retry_callback, and failure-email requests behind the bad one are lost permanently. Isolate each request so a failure is logged and the rest still execute, and route the last_ti task lookup through _get_dag_with_task so a removed task surfaces as the race-condition error instead of a raw TaskNotFound.


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)
    claude fable 5

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR prevents a single invalid callback request (e.g., due to the documented “Dag/task removed between scheduling and parsing” race) from crashing the Dag processor subprocess and causing the remainder of the callback batch to be dropped. It also ensures missing last_ti tasks surface as the intended race-condition ValueError rather than a raw TaskNotFound.

Changes:

  • Wrap per-request callback execution so one failing request is logged and the rest of the batch continues.
  • Route last_ti task lookup through _get_dag_with_task to normalize missing-task behavior to the race-condition ValueError.
  • Add unit tests covering “continue after failed request” and “missing last_ti task raises ValueError”.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
airflow-core/src/airflow/dag_processing/processor.py Isolates callback request execution failures and normalizes missing-task lookup behavior via _get_dag_with_task.
airflow-core/tests/unit/dag_processing/test_processor.py Adds regression tests for batch-continuation and missing last_ti task error behavior.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@ephraimbuddy
ephraimbuddy requested a review from kaxil August 4, 2026 10:59
@ephraimbuddy
ephraimbuddy force-pushed the fix-dag-processor-callback-request-isolation branch from 794d893 to 0f78bfe Compare August 5, 2026 08:05

@kaxil kaxil left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Both points are addressed well. The ValueError fallback keeps the dag-level callback alive with minimal context and cites the produce_dag_callback precedent, and exclude={"context_from_server"} keeps run conf out of the payload on both the debug and the error path, with log_extra binding the identifying fields so the error line is filterable. Reverting the fix locally makes both new tests fail with the original signatures, so they cover the real paths rather than the wiring. One optional test hardening below, not a blocker.

@ephraimbuddy ephraimbuddy self-assigned this Aug 10, 2026
…the rest

A callback request that hits the documented race condition (the Dag or
task was removed between scheduling the callback and parsing the file)
raises out of _execute_callbacks, killing the parse subprocess. The
remaining requests in the batch were already popped from the manager's
queue, so on_failure_callback, on_retry_callback, and failure-email
requests behind the bad one are lost permanently. Isolate each request
so a failure is logged and the rest still execute, and route the
last_ti task lookup through _get_dag_with_task so a removed task
surfaces as the race-condition error instead of a raw TaskNotFound.
Avoids a second to_json() in the exception handler, where a
serialization failure would mask the original error and abort the
batch the handler exists to protect.
…hen only the task is gone

The last_ti task lookup only enriches the callback context, so a task
removed since the run should downgrade to the minimal context (as
produce_dag_callback already does for an unrepresentable last_ti)
instead of costing the user the callback. The failure log leaked
user-supplied dag_run.conf at ERROR via the serialized request and
carried no structured identifiers; it now excludes context_from_server
and binds dag_id/run_id/ti_id so log filters can match the line.
@ephraimbuddy
ephraimbuddy force-pushed the fix-dag-processor-callback-request-isolation branch from 0f78bfe to 21d936d Compare August 11, 2026 11:57
@ephraimbuddy
ephraimbuddy merged commit 13b2969 into apache:main Aug 14, 2026
77 checks passed
@ephraimbuddy
ephraimbuddy deleted the fix-dag-processor-callback-request-isolation branch August 14, 2026 08:51
@github-actions

Copy link
Copy Markdown
Contributor

Backport successfully created: v3-3-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
✅ v3-3-test PR Link

aws-airflow-bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Aug 14, 2026
…nd dropping the rest (apache#70990)

* Fix one bad callback request crashing the Dag processor and dropping the rest

A callback request that hits the documented race condition (the Dag or
task was removed between scheduling the callback and parsing the file)
raises out of _execute_callbacks, killing the parse subprocess. The
remaining requests in the batch were already popped from the manager's
queue, so on_failure_callback, on_retry_callback, and failure-email
requests behind the bad one are lost permanently. Isolate each request
so a failure is logged and the rest still execute, and route the
last_ti task lookup through _get_dag_with_task so a removed task
surfaces as the race-condition error instead of a raw TaskNotFound.

* Serialize callback request once per loop iteration

Avoids a second to_json() in the exception handler, where a
serialization failure would mask the original error and abort the
batch the handler exists to protect.

* Address review: keep run conf out of logs and deliver Dag callbacks when only the task is gone

The last_ti task lookup only enriches the callback context, so a task
removed since the run should downgrade to the minimal context (as
produce_dag_callback already does for an unrepresentable last_ti)
instead of costing the user the callback. The failure log leaked
user-supplied dag_run.conf at ERROR via the serialized request and
carried no structured identifiers; it now excludes context_from_server
and binds dag_id/run_id/ti_id so log filters can match the line.

* fixup! Address review: keep run conf out of logs and deliver Dag callbacks when only the task is gone
(cherry picked from commit 13b2969)

Co-authored-by: Ephraim Anierobi <[email protected]>
potiuk pushed a commit that referenced this pull request Aug 17, 2026
…nd dropping the rest (#70990)

* Fix one bad callback request crashing the Dag processor and dropping the rest

A callback request that hits the documented race condition (the Dag or
task was removed between scheduling the callback and parsing the file)
raises out of _execute_callbacks, killing the parse subprocess. The
remaining requests in the batch were already popped from the manager's
queue, so on_failure_callback, on_retry_callback, and failure-email
requests behind the bad one are lost permanently. Isolate each request
so a failure is logged and the rest still execute, and route the
last_ti task lookup through _get_dag_with_task so a removed task
surfaces as the race-condition error instead of a raw TaskNotFound.

* Serialize callback request once per loop iteration

Avoids a second to_json() in the exception handler, where a
serialization failure would mask the original error and abort the
batch the handler exists to protect.

* Address review: keep run conf out of logs and deliver Dag callbacks when only the task is gone

The last_ti task lookup only enriches the callback context, so a task
removed since the run should downgrade to the minimal context (as
produce_dag_callback already does for an unrepresentable last_ti)
instead of costing the user the callback. The failure log leaked
user-supplied dag_run.conf at ERROR via the serialized request and
carried no structured identifiers; it now excludes context_from_server
and binds dag_id/run_id/ti_id so log filters can match the line.

* fixup! Address review: keep run conf out of logs and deliver Dag callbacks when only the task is gone
(cherry picked from commit 13b2969)

Co-authored-by: Ephraim Anierobi <[email protected]>
potiuk pushed a commit that referenced this pull request Aug 17, 2026
…nd dropping the rest (#70990) (#71608)

* Fix one bad callback request crashing the Dag processor and dropping the rest

A callback request that hits the documented race condition (the Dag or
task was removed between scheduling the callback and parsing the file)
raises out of _execute_callbacks, killing the parse subprocess. The
remaining requests in the batch were already popped from the manager's
queue, so on_failure_callback, on_retry_callback, and failure-email
requests behind the bad one are lost permanently. Isolate each request
so a failure is logged and the rest still execute, and route the
last_ti task lookup through _get_dag_with_task so a removed task
surfaces as the race-condition error instead of a raw TaskNotFound.

* Serialize callback request once per loop iteration

Avoids a second to_json() in the exception handler, where a
serialization failure would mask the original error and abort the
batch the handler exists to protect.

* Address review: keep run conf out of logs and deliver Dag callbacks when only the task is gone

The last_ti task lookup only enriches the callback context, so a task
removed since the run should downgrade to the minimal context (as
produce_dag_callback already does for an unrepresentable last_ti)
instead of costing the user the callback. The failure log leaked
user-supplied dag_run.conf at ERROR via the serialized request and
carried no structured identifiers; it now excludes context_from_server
and binds dag_id/run_id/ti_id so log filters can match the line.

* fixup! Address review: keep run conf out of logs and deliver Dag callbacks when only the task is gone
(cherry picked from commit 13b2969)

Co-authored-by: Ephraim Anierobi <[email protected]>
vatsrahul1001 pushed a commit that referenced this pull request Sep 7, 2026
…nd dropping the rest (#70990) (#71608)

* Fix one bad callback request crashing the Dag processor and dropping the rest

A callback request that hits the documented race condition (the Dag or
task was removed between scheduling the callback and parsing the file)
raises out of _execute_callbacks, killing the parse subprocess. The
remaining requests in the batch were already popped from the manager's
queue, so on_failure_callback, on_retry_callback, and failure-email
requests behind the bad one are lost permanently. Isolate each request
so a failure is logged and the rest still execute, and route the
last_ti task lookup through _get_dag_with_task so a removed task
surfaces as the race-condition error instead of a raw TaskNotFound.

* Serialize callback request once per loop iteration

Avoids a second to_json() in the exception handler, where a
serialization failure would mask the original error and abort the
batch the handler exists to protect.

* Address review: keep run conf out of logs and deliver Dag callbacks when only the task is gone

The last_ti task lookup only enriches the callback context, so a task
removed since the run should downgrade to the minimal context (as
produce_dag_callback already does for an unrepresentable last_ti)
instead of costing the user the callback. The failure log leaked
user-supplied dag_run.conf at ERROR via the serialized request and
carried no structured identifiers; it now excludes context_from_server
and binds dag_id/run_id/ti_id so log filters can match the line.

* fixup! Address review: keep run conf out of logs and deliver Dag callbacks when only the task is gone
(cherry picked from commit 13b2969)

Co-authored-by: Ephraim Anierobi <[email protected]>
kravii pushed a commit to acceldata-io/airflow that referenced this pull request Nov 19, 2026
…nd dropping the rest (apache#70990) (apache#71608)

* Fix one bad callback request crashing the Dag processor and dropping the rest

A callback request that hits the documented race condition (the Dag or
task was removed between scheduling the callback and parsing the file)
raises out of _execute_callbacks, killing the parse subprocess. The
remaining requests in the batch were already popped from the manager's
queue, so on_failure_callback, on_retry_callback, and failure-email
requests behind the bad one are lost permanently. Isolate each request
so a failure is logged and the rest still execute, and route the
last_ti task lookup through _get_dag_with_task so a removed task
surfaces as the race-condition error instead of a raw TaskNotFound.

* Serialize callback request once per loop iteration

Avoids a second to_json() in the exception handler, where a
serialization failure would mask the original error and abort the
batch the handler exists to protect.

* Address review: keep run conf out of logs and deliver Dag callbacks when only the task is gone

The last_ti task lookup only enriches the callback context, so a task
removed since the run should downgrade to the minimal context (as
produce_dag_callback already does for an unrepresentable last_ti)
instead of costing the user the callback. The failure log leaked
user-supplied dag_run.conf at ERROR via the serialized request and
carried no structured identifiers; it now excludes context_from_server
and binds dag_id/run_id/ti_id so log filters can match the line.

* fixup! Address review: keep run conf out of logs and deliver Dag callbacks when only the task is gone
(cherry picked from commit 13b2969)

Co-authored-by: Ephraim Anierobi <[email protected]>
(cherry picked from commit b9154e5)
senthh pushed a commit to acceldata-io/airflow that referenced this pull request Nov 23, 2026
…nd dropping the rest (apache#70990) (apache#71608)

* Fix one bad callback request crashing the Dag processor and dropping the rest

A callback request that hits the documented race condition (the Dag or
task was removed between scheduling the callback and parsing the file)
raises out of _execute_callbacks, killing the parse subprocess. The
remaining requests in the batch were already popped from the manager's
queue, so on_failure_callback, on_retry_callback, and failure-email
requests behind the bad one are lost permanently. Isolate each request
so a failure is logged and the rest still execute, and route the
last_ti task lookup through _get_dag_with_task so a removed task
surfaces as the race-condition error instead of a raw TaskNotFound.

* Serialize callback request once per loop iteration

Avoids a second to_json() in the exception handler, where a
serialization failure would mask the original error and abort the
batch the handler exists to protect.

* Address review: keep run conf out of logs and deliver Dag callbacks when only the task is gone

The last_ti task lookup only enriches the callback context, so a task
removed since the run should downgrade to the minimal context (as
produce_dag_callback already does for an unrepresentable last_ti)
instead of costing the user the callback. The failure log leaked
user-supplied dag_run.conf at ERROR via the serialized request and
carried no structured identifiers; it now excludes context_from_server
and binds dag_id/run_id/ti_id so log filters can match the line.

* fixup! Address review: keep run conf out of logs and deliver Dag callbacks when only the task is gone
(cherry picked from commit 13b2969)

Co-authored-by: Ephraim Anierobi <[email protected]>
(cherry picked from commit b9154e5)
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.

3 participants