Skip to content

Celery: Ignore redelivered message for already-running task#64052

Merged
eladkal merged 1 commit intoapache:mainfrom
anishgirianish:fix/58441-celery-redelivery-ignore
Mar 26, 2026
Merged

Celery: Ignore redelivered message for already-running task#64052
eladkal merged 1 commit intoapache:mainfrom
anishgirianish:fix/58441-celery-redelivery-ignore

Conversation

@anishgirianish
Copy link
Copy Markdown
Contributor

Catch TaskAlreadyRunningError from the supervisor and raise Celery Ignore() to prevent the broker redelivery from being recorded as a task failure.

related: #58441


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

Summary

Catch TaskAlreadyRunningError from the supervisor and raise Celery Ignore() to prevent a broker redelivery from being recorded as a task failure.

In Airflow 3.x, the scheduler processes executor events for RUNNING tasks (not just QUEUED as in 2.x). When Celery redelivers a message for a task that's already running, the worker hits a 409 from the API server. Without this fix, Celery records it as FAILURE, and the scheduler marks the still-running task as failed.

related: #58441
depends on: #60855


  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

Copy link
Copy Markdown
Contributor

@jscheffl jscheffl left a comment

Choose a reason for hiding this comment

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

Assume will fail unless #60855 is merged... which is fair. Can be re-based once the other PR is merged.

@potiuk potiuk marked this pull request as draft March 22, 2026 11:32
@potiuk
Copy link
Copy Markdown
Member

potiuk commented Mar 22, 2026

@anishgirianish This PR has been converted to draft because it does not yet meet our Pull Request quality criteria.

Issues found:

  • mypy (type checking): Failing: CI image checks / MyPy checks (mypy-providers). Run prek --stage manual mypy-providers --all-files locally to reproduce. You need breeze ci-image build --python 3.10 for Docker-based mypy. See mypy (type checking) docs.
  • Provider tests: Failing: Postgres tests: providers / DB-prov:Postgres:14:3.10:-amazon,celer...standard, MySQL tests: providers / DB-prov:MySQL:8.0:3.10:-amazon,celer...standard, Sqlite tests: providers / DB-prov:Sqlite:3.10:-amazon,celer...standard, Special tests / Min SQLAlchemy test: providers / DB-prov:MinSQLAlchemy-Postgres:14:3.10:-amazon,celer...standard, Special tests / Latest SQLAlchemy test: providers / DB-prov:LatestSQLAlchemy-Postgres:14:3.10:-amazon,celer...standard (+2 more). Run provider tests with breeze run pytest <provider-test-path> -xvs. See Provider tests docs.

Note: Your branch is 258 commits behind main. Some check failures may be caused by changes in the base branch rather than by your PR. Please rebase your branch and push again to get up-to-date CI results.

What to do next:

  • The comment informs you what you need to do.
  • Fix each issue, then mark the PR as "Ready for review" in the GitHub UI - but only after making sure that all the issues are fixed.
  • There is no rush — take your time and work at your own pace. We appreciate your contribution and are happy to wait for updates.
  • Maintainers will then proceed with a normal review.

Converting a PR to draft is not a rejection — it is an invitation to bring the PR up to the project's standards so that maintainer review time is spent productively. There is no rush — take your time and work at your own pace. We appreciate your contribution and are happy to wait for updates. If you have questions, feel free to ask on the Airflow Slack.

@jscheffl jscheffl marked this pull request as ready for review March 22, 2026 12:24
@jscheffl
Copy link
Copy Markdown
Contributor

@potiuk This is an exception where your AI tooling is not right - all the errors are caused by the explicit split PR #60855 not being merged (yet). Once this is done a rebase most probably will fix all errors. Re-converted to "Ready for review".

@eladkal
Copy link
Copy Markdown
Contributor

eladkal commented Mar 24, 2026

@anishgirianish can you resolve conflicts and rebase?
@jscheffl the code in this PR should work regardless of the change in #60855 as the change will be in airflow 3.1.x and the celery provider must work with airflow 2.11 as well

@anishgirianish anishgirianish force-pushed the fix/58441-celery-redelivery-ignore branch from 8c5147e to aebe804 Compare March 25, 2026 03:46
@anishgirianish
Copy link
Copy Markdown
Contributor Author

@anishgirianish can you resolve conflicts and rebase? @jscheffl the code in this PR should work regardless of the change in #60855 as the change will be in airflow 3.1.x and the celery provider must work with airflow 2.11 as well

@eladkal rebased and updated thanks

@anishgirianish anishgirianish force-pushed the fix/58441-celery-redelivery-ignore branch from aebe804 to 8753cab Compare March 25, 2026 21:27
Catch TaskAlreadyRunningError from the supervisor and raise Celery
Ignore() to prevent the broker redelivery from being recorded as a
task failure.

related: apache#58441
@anishgirianish anishgirianish force-pushed the fix/58441-celery-redelivery-ignore branch from 8753cab to e1c2006 Compare March 25, 2026 22:39
@eladkal eladkal merged commit 95fc11e into apache:main Mar 26, 2026
146 checks passed
nailo2c pushed a commit to nailo2c/airflow that referenced this pull request Mar 30, 2026
Catch TaskAlreadyRunningError from the supervisor and raise Celery
Ignore() to prevent the broker redelivery from being recorded as a
task failure.

related: apache#58441
Suraj-kumar00 pushed a commit to Suraj-kumar00/airflow that referenced this pull request Apr 7, 2026
Catch TaskAlreadyRunningError from the supervisor and raise Celery
Ignore() to prevent the broker redelivery from being recorded as a
task failure.

related: apache#58441
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.

4 participants