Repository navigation
FIX Handle Ctrl+C cancellation in CLI scenario polling (#3747) - #3813
Merged
Roman Lutz (romanlutz) merged 2 commits intoNov 4, 2026
Merged
Roman Lutz (romanlutz) merged 2 commits into
Roman Lutz (romanlutz) merged 2 commits into
Conversation
Contributor
Author
|
@microsoft-github-policy-service agree |
Roman Lutz (romanlutz)
approved these changes
Nov 4, 2026
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the CLI polling cancellation change.
No open issues 🎉
What changed in this PR
Fixes #3747 by handling Ctrl+C cancellation during CLI scenario polling so the CLI requests server-side cancellation instead of leaving the accepted run executing.
Changes:
- Catches both
KeyboardInterruptandasyncio.CancelledErrorduring polling. - Sends cancellation in a shielded task and reports success only after the request returns successfully.
- Adds a regression test verifying that polling cancellation sends the server request and returns exit code 1.
| File | Description |
|---|---|
tests/unit/cli/test_pyrit_scan.py |
Adds regression coverage for cancellation during polling. |
pyrit/cli/pyrit_scan.py |
Handles polling cancellation and shields the server cancellation request. |
Review effort: Balanced
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
Fixes #3747.
When Ctrl+C arrives during scenario polling,
asyncio.run()cancels the main task and raisesasyncio.CancelledErrorat the polling await. The polling handler only caughtKeyboardInterrupt, so the server cancellation endpoint was skipped and the accepted run continued.Handle both cancellation forms, run the server cancellation request in its own task, and shield that request from the cancellation already delivered to the polling task. Report that the request was sent only after it returns successfully; report a warning if it fails.
Tests and Documentation
.venv/bin/pytest -q tests/unit/cli/test_pyrit_scan.py— 157 passed.ty checkonpyrit/cli/pyrit_scan.pyandtests/unit/cli/test_pyrit_scan.py— passed.tests/unit/build_scripts/test_codeql_merge_group.py::test_codeql_merge_group_scenarioswith Node.js v22.22.0 — 1 passed..venv/bin/pytest -q -n 4 tests/unit) — 32,159 passed, 478 skipped, 139 subtests passed; 2 failures. The CodeQL test initially could not find Node and passed when rerun with Node installed. The other failure is in the unrelatedtest_assert_generator.py::TestAssertGenerator::test_separate_research_target_receives_research_stages_async, which raisesUnboundLocalErrorfor localcall; it also fails in isolation.