Skip to content

Stop failing reschedule-mode sensors on a stale executor success - #71194

Closed
rjgoyln wants to merge 2 commits into
apache:mainfrom
rjgoyln:fix-sensor-reschedule-stale-executor-event
Closed

rjgoyln wants to merge 2 commits into
apache:mainfrom
rjgoyln:fix-sensor-reschedule-stale-executor-event

Conversation

@rjgoyln

@rjgoyln rjgoyln commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

A sensor running with mode="reschedule" is intermittently marked failed when the executor success for one poke reaches the scheduler after the task instance has already gone back to scheduled (or queued) for the next poke. The scheduler reads the late event as a task that finished without recording its own state, and fails it:

Executor CeleryExecutor(parallelism=512) reported that the task instance
<TaskInstance: <dag_id>.<sensor_task_id> ... [scheduled] ti_id=...>
finished with state success, but the task instance's state attribute is scheduled.

The existing guards for this race all assume the defer path. A reschedule exit leaves next_method unset and keeps the same try_number, so the executor key still matches and none of them apply. A reschedule row for the current try is the signal that separates the two cases: it says the worker exited up_for_reschedule rather than being killed. Anything with no such row still takes the externally-killed branch.

It is resolved once per event batch alongside the bulk task-instance fetch, so the per-event path gains no query.

closes: #71172


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 5)

Generated-by: Claude Code (Opus 5) following the guidelines

A sensor running with mode="reschedule" was intermittently marked failed
when the executor success for one poke reached the scheduler after the
task instance had already been put back for the next poke. The existing
guards for this race only cover the defer path: a reschedule exit leaves
next_method unset and does not bump try_number, so none of them applied
and the event was treated as an external kill.
@rjgoyln
rjgoyln marked this pull request as ready for review August 8, 2026 14:00
@rjgoyln
rjgoyln requested review from XD-DENG and ashb as code owners August 8, 2026 14:00

@steveahnahn steveahnahn 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.

Verified on Postgres with the source reverted to main and the new test kept, both params reproduce the bug (sensor marked failed) and with the fix both pass.

idx_task_reschedule_ti_id_id_desc covers the batched ti_id lookup, so it stays index-only as reschedule volume grows LGTM.

@rjgoyln

rjgoyln commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

Verified on Postgres with the source reverted to main and the new test kept, both params reproduce the bug (sensor marked failed) and with the fix both pass.

idx_task_reschedule_ti_id_id_desc covers the batched ti_id lookup, so it stays index-only as reschedule volume grows LGTM.

Thanks for review! Really appreciate it.

@potiuk

potiuk commented Sep 25, 2026

Copy link
Copy Markdown
Member

Hello @rjgoyln - thank you for your contributions to Apache Airflow!

The Airflow community has introduced a limit of 5 open pull requests at a time for contributors without write access to the repository. You currently have 24 open pull requests, so - as a one-time step of introducing the limit - we closed the ones where maintainers have not engaged yet:

These pull requests stay open because maintainers are already engaged in them - they count towards your limit:

This is not a judgement of you or of your changes. We never told contributors before that opening many pull requests at once was a problem, so there is nothing to feel bad about - and nothing is lost: your branches, commits and the review history stay where they are.

What we ask you to do is to make your first prioritization decision: choose which of the pull requests above matter most to you, and reopen them (up to 5 open at a time, including the ones still open) with the "Reopen pull request" button or gh pr reopen <PR_NUMBER> --repo apache/airflow. Reopen the ones you are ready to follow through - keep them rebased, respond to review comments and fix failing checks.

While your pull requests are waiting for review, the most valuable thing you can do is help in other ways - reviewing other contributors' pull requests, helping with issues, and taking part in the discussions on the devlist and Slack.

Why we introduced the limit, what it means for you and how to reopen or restore a pull request is explained in https://github.com/apache/airflow/blob/main/contributing-docs/32_open_pull_request_limit.rst.


Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting

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

Labels

area:scheduler closed because of open PR limit Closed as a one-time step of introducing the open pull request limit ready for maintainer review Set after triaging when all criteria pass.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Race condition between scheduler processing events and sensor reschedule

4 participants