Skip to content

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

Closed

Description

Describe the bug

If the IN_PROGRESS update for a queued scenario run commits but the call still raises (for example, the connection drops during the commit acknowledgement), the run never starts.

The handoff retry sees that the row is no longer QUEUED and removes the run from the queue. The row stays IN_PROGRESS, but nothing is executing it. Startup reconciliation only covers SQLiteMemory, so on shared memory such as Azure SQL the row is never corrected.

I found this through code review and reproduced it with a mock. I haven't seen it in production.

Steps/Code to Reproduce

Add this test to tests/unit/backend/test_scenario_run_service.py and run it:

async def test_retry_starts_run_when_in_progress_ack_is_lost(mock_all_registries) -> None:
    service = ScenarioRunService()
    row = MagicMock(scenario_run_state=ScenarioRunState.QUEUED)

    async def commit_then_raise(**_: object) -> None:
        row.scenario_run_state = ScenarioRunState.IN_PROGRESS  # the write commits...
        raise ConnectionError("connection lost after commit")  # ...but the caller sees a failure

    memory = mock_all_registries["memory"]
    memory.get_scenario_result_header_async = AsyncMock(return_value=row)
    memory.update_scenario_run_state_and_metadata_fields_async = AsyncMock(side_effect=commit_then_raise)

    service._active_scenario_result_id = "run-0"
    service._queued_runs.append(MagicMock(scenario_result_id="run-1"))

    with pytest.raises(ConnectionError):
        await service._handoff_scheduler_async(scenario_result_id="run-0")  # first attempt
    await service._handoff_scheduler_async(scenario_result_id="run-0")  # retry

    assert "run-1" in service._active_tasks  # fails: the run was dropped and never started

Expected Results

The retry recognizes that the scheduler already claimed the run and starts it, or marks the run as failed.

Actual Results

AssertionError: assert 'run-1' in {}

The run is removed from the queue without being started, and its row stays IN_PROGRESS.

Screenshots

N/A

Versions

  • OS: Linux (WSL2)
  • Browser: N/A
  • Python version: 3.12.3
  • PyRIT version: 1.2.0.dev0, installed from source at 110a58ef0. scenario_run_service.py is unchanged on main at 020bff429.
  • Output of pyrit.show_versions():
System:
    python: 3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]
   machine: Linux-5.15.167.4-microsoft-standard-WSL2-x86_64-with-glibc2.39

Python dependencies:
        pyrit: 1.2.0.dev0
       Cython: None
        numpy: 2.4.6
       openai: 2.54.0
    packaging: 26.3
          pip: 26.2.2
        scipy: 1.17.1
   setuptools: 84.2.1
      sqlite3: None
        torch: None
 transformers: 5.20.2

Activity

  1. WaqarAnwar commented on Nov 8, 2026

    @WaqarAnwar
    ContributorAuthor

    Hello Roman Lutz (@romanlutz) ,

    Kindly have a look at this issue and linked PR

    Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions