Repository navigation
FIX: Start queued scenario run when handoff retry finds it already IN_PROGRESS - #4038
Merged
Roman Lutz (romanlutz) merged 8 commits intoNov 9, 2026
Conversation
…_PROGRESS If the IN_PROGRESS update for a queued run committed but the call still raised, the handoff retry saw a non-QUEUED row and dropped the run, leaving it IN_PROGRESS with nothing executing it. The retry now starts a run whose row carries the start time this scheduler saved for it. Cancelling a queued run in that window now also cancels the IN_PROGRESS row. Closes microsoft#4036 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the scheduler retry-recovery and cancellation changes.
No open issues 🎉
What changed in this PR
Fixes #4036 by allowing the scenario scheduler to start a queued run when its earlier IN_PROGRESS update committed but reported a failure.
Changes:
- Recognizes a persisted start timestamp belonging to the current scheduler and launches the run without repeating the database update.
- Extracts task launch logic and allows cancellation during the handoff retry window.
- Adds mocked regression tests for retry recovery, mismatched start timestamps, and cancellation.
| File | Description |
|---|---|
tests/unit/backend/test_scenario_run_service.py |
Adds regression coverage for handoff retry recovery and cancellation. |
pyrit/backend/services/scenario_run_service.py |
Recovers committed starts on retry and handles cancellation before task launch. |
Review effort: Balanced
…handoff-stuck-in-progress
Use _load_started_at so a saved start time written with a Z suffix or returned as a datetime still matches the run's start on handoff retry.
…aqarAnwar/PyRIT into fix/scenario-handoff-stuck-in-progress
Roman Lutz (romanlutz)
approved these changes
Nov 9, 2026
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
Closes #4036.
If the
IN_PROGRESSupdate for a queued scenario run commits but the call still raises, the handoff retry sees a non-QUEUEDrow and drops the run. The row staysIN_PROGRESSwith nothing executing it, and startup reconciliation only coversSQLiteMemory. This PR makes the retry start the run instead._handoff_scheduler_asyncnow recognizes anIN_PROGRESSrow whose saved start time matches the one this scheduler wrote for the run, and starts the run without writing to the database again. Other unexpected states are still dropped from the queue._launch_scheduled_run_lockedso the retry can start a run without repeating the state update.IN_PROGRESS. Before, the update did nothing, the cancel raisedValueError, and the run had already left the queue, so it stayed stuck. A queued run has no task yet, so there is nothing else to stop.The failure is simulated with a mocked database. It hasn't been observed in production or tried against a real Azure SQL connection failure.