fix(workers): cancel jobs when interrupted during context exit - #5721
Open
skulitom wants to merge 2 commits into
Open
fix(workers): cancel jobs when interrupted during context exit#5721skulitom wants to merge 2 commits into
skulitom wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cancelling a caller while
job()orjob_group()waits for responses in__aexit__leaves its child jobs running and the group registered. The existing cleanup only handles exceptions raised inside theasync withbody, so a commonasync with parent.job("worker"): passcall misses cleanup when interrupted during the response wait.Handle
CancelledErrorduring that wait using the existing shielded group cancellation, then re-raise it. This sends cancellation to the children and clears the group while preserving cancellation of the requester. The context-manager docstrings and changelog describe the behavior.The regression tests exercise the actual
AsyncQueueBus, a requester, and blocking worker handlers. They synchronize with events, cancel after the context body has finished, and verify cancellation messages, group cleanup, and termination of every child handler. Both tests fail on current main: no cancellation messages are sent.Validation on Windows, Python 3.13:
tests/test_job_group.py,tests/test_base_worker.py, andtests/test_ui_job_lifecycle.py.Found during code inspection; no matching open issue or PR identified.
AI disclosure: OpenAI Codex wrote and tested the code, regression tests, and this description.