FIX Persist direct scenario cancellation - #2342
Open
Roman Lutz (romanlutz) wants to merge 2 commits into
Open
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 058569a0-6218-4cf4-947e-67fa51001d85
varunj-msft
approved these changes
Aug 7, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 058569a0-6218-4cf4-947e-67fa51001d85
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.
Description
Direct cancellation of an
asynciotask runningScenario.run_async()bypassed the existingExceptionhandlers, leaving the persisted scenario state asIN_PROGRESSeven after workers had stopped.This change handles
asyncio.CancelledErrorat the scenario boundary, persistsCANCELLED, and re-raises the original cancellation without consuming retries or changing normal failure behavior. Event-gated coverage verifies worker cleanup, no queued or post-cancel work, exactly-once persistence of completed objectives, and duplicate-free resume of only unfinished objectives.Tests and Documentation
pytest tests/unit/scenario/core/test_scenario_partial_results.py tests/unit/scenario/core/test_scenario.py::TestScenarioParallelExecution tests/unit/backend/test_scenario_run_service.py::TestScenarioRunServiceCancelRun tests/unit/memory/memory_interface/test_interface_scenario_results.py::test_update_scenario_run_state_updates_state_and_error_fields -q(18 passed)ruff check pyrit/scenario/core/scenario.py tests/unit/scenario/core/test_scenario_partial_results.pyruff format --check pyrit/scenario/core/scenario.py tests/unit/scenario/core/test_scenario_partial_results.pyty check pyrit/scenario/core/scenario.py tests/unit/scenario/core/test_scenario_partial_results.pyUpdated the
Scenario.run_async()contract documentation for cancellation and resumability. JupyText was not applicable.