Skip to content

fix(workers): cancel jobs when interrupted during context exit - #5721

Open
skulitom wants to merge 2 commits into
pipecat-ai:mainfrom
skulitom:fix/job-context-exit-cancellation
Open

fix(workers): cancel jobs when interrupted during context exit#5721
skulitom wants to merge 2 commits into
pipecat-ai:mainfrom
skulitom:fix/job-context-exit-cancellation

Conversation

@skulitom

Copy link
Copy Markdown

Cancelling a caller while job() or job_group() waits for responses in __aexit__ leaves its child jobs running and the group registered. The existing cleanup only handles exceptions raised inside the async with body, so a common async with parent.job("worker"): pass call misses cleanup when interrupted during the response wait.

Handle CancelledError during 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:

  • 139 tests pass across tests/test_job_group.py, tests/test_base_worker.py, and tests/test_ui_job_lifecycle.py.
  • Repository-wide Ruff lint and formatting pass (1,396 files checked for formatting).
  • Pyright 1.1.411 reports no errors or warnings for both changed Python files.
  • No provider calls are involved; this reproduces through local worker execution.

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant