Skip to content

Concurrent SDK run_async calls duplicate one persisted run and exceed its concurrency limit #3748

Closed

Description

@romanlutz

Describe the bug

Two concurrent run_async calls on the same initialized scenario create independent executors/semaphores over one persisted run, duplicate work and exceed the configured concurrency cap.

Steps/Code to Reproduce

Initialize one scenario with six objectives and max_concurrency=2, then await two concurrent calls to run_async on that same instance with a counting deterministic target.

Additional reproduction details

Prepare one offline scenario with six objectives and max_concurrency=2, backed by a deterministic target that blocks until both calls enter; invoke await asyncio.gather(scenario.run_async(), scenario.run_async()) on the same initialized instance. Captured values: peak target concurrency 4, target calls 12, persisted attack results 12, number_tries=1, both calls returned ScenarioResult under the same run ID. No live model or external target is needed.

Expected Results

Reject or serialize a second execution before target work; planned units should execute once, concurrency remain at most two, and attempt accounting be atomic.

Actual Results

Both calls return ScenarioResult under the same persisted ID. Six objectives run twice, 12 attack results persist, peak target concurrency is four despite limit two, and number_tries remains 1 due to overlapping read/increment/write. API detail folds duplicates into six completed units and six retry attempts.

Verified source reference: Scenario run lifecycle.

Proposed fix/regression: add same-run ownership/reentrancy guard released after worker cleanup; make attempt increments atomic; test concurrency, cancellation cleanup, and legitimate later resume with real SQLite.

Screenshots

Not applicable; counts/concurrency are inline.

Versions

Tested commit d3446e0, PyRIT 1.2.0.dev0, offline SDK/SQLite/deterministic-target scope. Evidence: files/evidence/round9/sdk-concurrent-same-run.json; local path is not an attachment.

Activity

  1. Kaap10 commented on Nov 1, 2026

    @Kaap10
    Contributor

    I have reproduced and tested this behavior locally against an offline SQLite fixture, confirming the concurrency cap bypass and duplicated persisted runs. I'd like to take this on by adding a scenario-level re-entrancy guard, making attempt accounting atomic, and adding regression tests.

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

Metadata

Metadata

Labels

help wantedExtra attention is needed

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions