Skip to content

FIX Persist direct scenario cancellation - #2342

Open
Roman Lutz (romanlutz) wants to merge 2 commits into
microsoft:mainfrom
romanlutz:romanlutz-scenario-cancellation-contract
Open

FIX Persist direct scenario cancellation#2342
Roman Lutz (romanlutz) wants to merge 2 commits into
microsoft:mainfrom
romanlutz:romanlutz-scenario-cancellation-contract

Conversation

@romanlutz

Copy link
Copy Markdown
Contributor

Description

Direct cancellation of an asyncio task running Scenario.run_async() bypassed the existing Exception handlers, leaving the persisted scenario state as IN_PROGRESS even after workers had stopped.

This change handles asyncio.CancelledError at the scenario boundary, persists CANCELLED, 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.py
  • ruff format --check pyrit/scenario/core/scenario.py tests/unit/scenario/core/test_scenario_partial_results.py
  • ty check pyrit/scenario/core/scenario.py tests/unit/scenario/core/test_scenario_partial_results.py

Updated the Scenario.run_async() contract documentation for cancellation and resumability. JupyText was not applicable.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 058569a0-6218-4cf4-947e-67fa51001d85
Comment thread pyrit/scenario/core/scenario.py Outdated
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 058569a0-6218-4cf4-947e-67fa51001d85
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.

3 participants