Skip to content

FIX: Start queued scenario run when handoff retry finds it already IN_PROGRESS - #4038

Merged
Roman Lutz (romanlutz) merged 8 commits into
microsoft:mainfrom
WaqarAnwar:fix/scenario-handoff-stuck-in-progress
Nov 9, 2026
Merged

Roman Lutz (romanlutz) merged 8 commits into
microsoft:mainfrom
WaqarAnwar:fix/scenario-handoff-stuck-in-progress

Conversation

@WaqarAnwar

Copy link
Copy Markdown
Contributor

Description

Closes #4036.

If the IN_PROGRESS update for a queued scenario run commits but the call still raises, the handoff retry sees a non-QUEUED row and drops the run. The row stays IN_PROGRESS with nothing executing it, and startup reconciliation only covers SQLiteMemory. This PR makes the retry start the run instead.

  • Handoff retry: _handoff_scheduler_async now recognizes an IN_PROGRESS row 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 step: task creation moved into _launch_scheduled_run_locked so the retry can start a run without repeating the state update.
  • Cancel during the retry window: cancelling a queued run now also matches IN_PROGRESS. Before, the update did nothing, the cancel raised ValueError, 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.

…_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]>
Copilot AI balanced review requested due to automatic review settings November 7, 2026 08:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

@romanlutz Roman Lutz (romanlutz) self-assigned this Nov 8, 2026
@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Nov 9, 2026
Merged via the queue into microsoft:main with commit 94329f1 Nov 9, 2026
59 checks passed
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.

BUG: Queued scenario run gets stuck IN_PROGRESS after a handoff retry

4 participants