Skip to content

FIX: run unstarted attacks before failed ones on resume - #4298

Open
Chen Yufeiyang (feiiiiii5) wants to merge 8 commits into
microsoft:mainfrom
feiiiiii5:fix/scenario-resume-order-unstarted
Open

Chen Yufeiyang (feiiiiii5) wants to merge 8 commits into
microsoft:mainfrom
feiiiiii5:fix/scenario-resume-order-unstarted

Conversation

@feiiiiii5

@feiiiiii5 Chen Yufeiyang (feiiiiii5) commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Description

On retry/resume, _get_remaining_atomic_attacks_async keeps the original planned order. If the first remaining attack has one objective that always raises, it reaches stop_event every run before admission moves on, so the attacks behind it never start. With 6 attacks × 4 objectives, the run keeps sending the same 3 healthy objectives and 15 of 18 healthy objectives are never tried.

  • Read completed objectives and failure timestamps from the same result snapshot that already supplies persisted results. _get_attack_progress_async now returns completed hashes plus the latest still-pending failure timestamp for each (parent_collection, parent_eval_hash). Only ERROR and preparation-failure rows whose objective is still pending count as failures; merely started or interrupted attacks do not get demoted.
  • Stable-sort attacks with no pending failure before attacks that already failed. Failed attacks are ordered by their oldest latest pending failure, so repeated failures rotate instead of starving each other; original order is preserved within each group.
  • Keep stop-on-failure within a single run unchanged; completed objectives are still filtered as before.
  • Remove the test-only _get_completed_objective_hashes_by_attack_async wrapper and let tests unpack _get_attack_progress_async() directly.

This makes retries progress: after t1 fails, t2–t6 run first; if t2 also fails, the next retry starts at t3. A fresh failure still stops admission for the rest of that run. Parameter-construction failures that persist no result row remain a separate follow-up, as agreed in review.

Validation: the retry-ordering tests cover unstarted-before-failed ordering, interrupted and compound-child rows, duplicate names, legacy name-only rows, preparation failures and failure rotation: 32 passed. Ruff check and format pass.

Fixes #4158.

Copilot AI balanced review requested due to automatic review settings November 15, 2026 00:57

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 were identified for the change prioritizing unstarted attacks on retry and resume.

No open issues 🎉

What changed in this PR

This PR addresses #4158 by prioritizing unstarted atomic attacks on retry and resume, preventing a repeatedly failing attack from blocking untouched work.

Changes:

  • Track completed objectives and started attacks from the same persisted result snapshot.
  • Queue unstarted attacks first while preserving order within each group and leaving stop-on-failure behavior unchanged.
  • Add a regression test for retry ordering.
File Description
tests/​unit/​scenario/​core/​test_scenario_retry.py Tests that unstarted attacks are queued before a previously failed attack.
pyrit/​scenario/​core/​scenario.py Tracks started attacks and reorders remaining work without changing completed-objective filtering.

Review effort: Balanced

@feiiiiii5

Copy link
Copy Markdown
Contributor Author

The only failing check is tests/unit/prompt_target/target/test_websocket_copilot_target.py::TestConnectAndSend::test_connect_and_send_overall_timeout_during_stream (AssertionError: Regex pattern did not match) in the Ubuntu 3.14 dev_all job. That file is untouched by this PR; the same job reports 38,833 passed, 22 skipped, 4 xfailed. The failure looks timing-sensitive. Could CI re-run that job?

Comment thread pyrit/scenario/core/scenario.py Resolved
@feiiiiii5
Chen Yufeiyang (feiiiiii5) force-pushed the fix/scenario-resume-order-unstarted branch from de03e72 to 609fff4 Compare November 16, 2026 00:29
@feiiiiii5

Copy link
Copy Markdown
Contributor Author

Good catch — a healthy half-finished attack was being demoted with the failed one. I cherry-picked your commit (daa3d6cd, now 609fff4), so the ordering set is restricted to ERROR and preparation-failure rows. The retry test suite passes (29 passed) and Ruff is clean on both files.

Thanks for including the test with the fix.

@hannahwestra25 hannahwestra25 self-assigned this Nov 20, 2026

@hannahwestra25 hannahwestra25 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Three inline findings from the external-contribution review.

Comment thread pyrit/scenario/core/scenario.py Resolved
Comment thread pyrit/scenario/core/scenario.py Resolved
Comment thread pyrit/scenario/core/scenario.py Resolved

@hannahwestra25 hannahwestra25 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-checked at 3269678. The compound-child and duplicate-name fixes hold, with tests. Four new notes are inline; the ordering one still lets failed attacks starve each other.

Comment thread pyrit/scenario/core/scenario.py Resolved
Comment thread pyrit/scenario/core/scenario.py Resolved
Comment thread pyrit/scenario/core/scenario.py Resolved
@feiiiiii5

Copy link
Copy Markdown
Contributor Author

Thanks hannahwestra25 — the last gap you confirmed is fixed in da1ab236.

attack_name_counts now counts over self._atomic_attacks instead of remaining_attacks, so a completed namesake no longer makes the legacy (name, None) failure unambiguous for the surviving duplicate. Added test_completed_namesake_does_not_demote_surviving_duplicate, which keeps the surviving duplicate ahead of the untouched attack.

Verification: pytest tests/unit/scenario/core/test_scenario_retry.py -q → 32 passed; ruff check and format clean on both changed files.

For the earlier items: the parameter-construction marker and the compound-child exclusion were explicitly scoped out per your "keep this PR scoped" note, and the set was already renamed to failed_attack_keys in the prior commit.

@hannahwestra25 hannahwestra25 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-checked at da1ab23. The namesake count fix holds, and the new test fails without it. Failed attacks still starve each other on retry, and the rename, wrapper, and test notes remain open. One small note inline.

Comment thread pyrit/scenario/core/scenario.py Resolved
@feiiiiii5

Copy link
Copy Markdown
Contributor Author

Thanks for the follow-ups. At the new head I removed the stale TestApplyPersistedObjectives cases (they called a method this branch does not have), switched the remaining callers to unpack _get_attack_progress_async(), renamed the failure set and the ordering test, added unique-name legacy, preparation-failure and failure-rotation cases, and updated the PR description. Focused retry suite: 32 passed; Ruff check and format clean. Parameter-construction failures with no persisted row stay in the agreed follow-up.

Chen Yufeiyang (feiiiiii5) added a commit to feiiiiii5/PyRIT that referenced this pull request Dec 1, 2026
…R-then-SUCCESS skip

Per maintainer review on microsoft#4298:
- test_failed_attacks_rotate_by_latest_pending_failure now appends a second
  ERROR row for the retried attack instead of editing the first row's
  timestamp, so max-vs-min in failure-rank is distinguished.
- add test_error_then_success_objective_is_not_a_pending_failure covering the
  skip at line 2603: a later non-error row for the same objective means the
  objective is no longer pending, so a stale ERROR must not demote the attack
  while it still has pending work.
@feiiiiii5

Copy link
Copy Markdown
Contributor Author

Addressed the test gap in test_failed_attacks_rotate_by_latest_pending_failure: the second phase now appends a new ERROR row for first at 12:00 rather than editing the first row's timestamp, so max vs min in the failure-rank computation is distinguished (with min, first would stay ahead and the test would fail).

Also added test_error_then_success_objective_is_not_a_pending_failure: an ERROR for objective r1 followed by a later non-error row for the same r1 means r1 is no longer pending, so the stale ERROR must not demote an attack that still has pending work (r2) — covering the skip at scenario.py:2603.

Pushed a934042a. Verified locally in a clean worktree: pytest tests/unit/scenario/core/test_scenario_retry.py -q → 33 passed; ruff check + ruff format --check clean.

@hannahwestra25 hannahwestra25 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for contributing!

A legacy name-only failure stays ambiguous when one same-name attack has completed. Count names over all atomic attacks so the surviving namesake is not demoted for a failure that belonged to the finished one.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…R-then-SUCCESS skip

Per maintainer review on microsoft#4298:
- test_failed_attacks_rotate_by_latest_pending_failure now appends a second
  ERROR row for the retried attack instead of editing the first row's
  timestamp, so max-vs-min in failure-rank is distinguished.
- add test_error_then_success_objective_is_not_a_pending_failure covering the
  skip at line 2603: a later non-error row for the same objective means the
  objective is no longer pending, so a stale ERROR must not demote the attack
  while it still has pending work.
@feiiiiii5
Chen Yufeiyang (feiiiiii5) force-pushed the fix/scenario-resume-order-unstarted branch from a934042 to 0e11571 Compare December 1, 2026 22:35

This branch has not been deployed

No deployments
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: Scenario: one objective that always errors stops the rest of the run from ever being sent, across every retry and resume

4 participants