Skip to content

Conversation

@Nusnus
Copy link
Member

@Nusnus Nusnus commented Aug 25, 2025

Fixes #9844

When a task is revoked via app.control.revoke(), the task status in the result backend was not being updated to REVOKED. The status would remain PENDING until a worker actually picked up the task and discovered it was revoked.

This was particularly problematic for tasks with ETA/countdown - if the worker was shut down before the ETA arrived, the task status would stay PENDING forever.

Changes

  • Added a call to backend.mark_as_revoked() in the _revoke() function to immediately update the backend status when a task is revoked
  • Backend failures are caught and logged as warnings without breaking the revocation process
  • Added unit tests to verify the new behavior

Behavior Change

The result backend is now immediately updated when a task is revoked. Previously, the backend was only updated when a worker attempted to process the revoked task.

This is the expected/correct behavior - users calling AsyncResult(task_id).status after revocation will now correctly see REVOKED instead of PENDING.

@Nusnus Nusnus self-assigned this Aug 25, 2025
@Nusnus Nusnus added this to the 5.6.0 milestone Aug 25, 2025
@codecov
Copy link

codecov bot commented Aug 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.43%. Comparing base (9d6ab11) to head (9f9a39a).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #9869   +/-   ##
=======================================
  Coverage   88.42%   88.43%           
=======================================
  Files         153      153           
  Lines       19368    19373    +5     
  Branches     2227     2228    +1     
=======================================
+ Hits        17127    17133    +6     
  Misses       1941     1941           
+ Partials      300      299    -1     
Flag Coverage Δ
unittests 88.40% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Nusnus Nusnus force-pushed the issue_9844 branch 2 times, most recently from 6008d8a to 557cda3 Compare August 26, 2025 10:37
@auvipy auvipy self-requested a review August 26, 2025 13:38
@Nusnus Nusnus requested a review from Copilot August 26, 2025 18:19
Copy link
Contributor

Copilot AI left a comment

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 adds backend status updates for task revocation operations in Celery. The purpose is to ensure that when tasks are revoked, the backend is properly notified to mark these tasks as revoked, which helps maintain consistency between worker state and backend state.

Key changes:

  • Added backend status update calls in the _revoke function to mark tasks as revoked in the backend
  • Added defensive error handling to prevent backend failures from breaking the revocation process
  • Added comprehensive test coverage for the new backend integration functionality

Reviewed Changes

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

File Description
celery/worker/control.py Added backend.mark_as_revoked calls with error handling in the _revoke function
t/unit/worker/test_control.py Added test coverage for backend status updates during revocation, including error handling scenarios

@Nusnus
Copy link
Member Author

Nusnus commented Aug 26, 2025

Testing the new GitHub Copilot instructions on this PR @auvipy FYI

@auvipy
Copy link
Member

auvipy commented Sep 1, 2025

I think we can start with celery 5.6b1 release process

@Nusnus
Copy link
Member Author

Nusnus commented Sep 15, 2025

@auvipy

I think we can start with celery 5.6b1 release process

Done:

@auvipy
Copy link
Member

auvipy commented Sep 15, 2025

thanks!

@auvipy
Copy link
Member

auvipy commented Oct 27, 2025

the tests are passing

Copy link
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

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

as per a comment from discussion, the solution seems working for the reporter

@auvipy auvipy marked this pull request as ready for review October 27, 2025 05:24
@auvipy auvipy requested a review from Copilot October 27, 2025 05:30
Copy link
Contributor

Copilot AI left a comment

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 1 comment.

@Nusnus Nusnus force-pushed the issue_9844 branch 2 times, most recently from cf44795 to c2c8137 Compare November 1, 2025 16:19
@Nusnus Nusnus modified the milestones: 5.6.0, 5.6.x Nov 1, 2025
@Nusnus Nusnus force-pushed the issue_9844 branch 3 times, most recently from 84a4c63 to e360e3f Compare November 22, 2025 18:01
Nusnus and others added 3 commits January 4, 2026 13:29
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Nusnus Nusnus changed the title Potential fix for Issue #9844 Bugfix: Revoked tasks now immediately update backend status to REVOKED Jan 4, 2026
@Nusnus Nusnus merged commit 333a82f into celery:main Jan 4, 2026
371 checks passed
@Nusnus Nusnus deleted the issue_9844 branch January 4, 2026 12:11
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.

2 participants