Skip to content

FIX: Keep a scenario running after an objective-specific error - #4829

Open
Behnam (behnam-o) wants to merge 1 commit into
microsoft:mainfrom
behnam-o:agents/fix-scenario-objective-error-handling
Open

Behnam (behnam-o) wants to merge 1 commit into
microsoft:mainfrom
behnam-o:agents/fix-scenario-objective-error-handling

Conversation

@behnam-o

Copy link
Copy Markdown
Collaborator

Description

A scenario stopped starting new atomic attacks as soon as any objective errored, whatever the error. A single objective-specific failure, such as a garbled adversarial reply that later fails prompt hashing with UnicodeEncodeError, left every unstarted atomic attack without results, and a resume could stop again at the next such error. This keeps the run going and stops early only for errors that every remaining objective would hit.

  • Add ObjectiveFailureTracker. It follows each failed objective's error chain past the attack's wrapper, because neither the component label nor PyritException.status_code is reliable. New atomic attacks stop for:
    • rejected credentials (401/403, Azure credential failures)
    • a missing model or deployment (404)
    • connection failures and timeouts
    • rate-limit or server errors (429/5xx) that outlast the target's own retries
  • As a safety net for system-wide failures the list doesn't anticipate, new atomic attacks also stop when the same root error (type plus message, ignoring numbers and IDs) fails 3 distinct objectives.
  • Any other error stays on its objective. The run still ends FAILED with ScenarioPartialFailureException, and resume re-runs only the objectives that errored. An atomic attack that raises outright still stops new attacks, as before.
  • Update the scenario resiliency docs and flowchart.

Related: #4158, and #4298, which runs unstarted attacks before failed ones on resume. This PR changes the stop rule within a single run.

Before / After. The reproduction uses two atomic attacks (first: objectives A and B; second: objective C), with max_concurrency=1 and max_retries=0. The target's reply to B contains a lone surrogate, so storing it raises UnicodeEncodeError, labeled objective_target. The script then resumes the same scenario against a healthy target.

Before
  run:    results={'first': ['success', 'error']}                         sent A, B     -> ScenarioPartialFailureException, FAILED
  resume: sent C, B                                                                     -> COMPLETED
After
  run:    results={'first': ['success', 'error'], 'second': ['success']}  sent A, B, C  -> ScenarioPartialFailureException, FAILED
  resume: sent B                                                                        -> COMPLETED

If the target returns a 401 for B instead, both versions stop before second. The new version logs why: Scenario '...' won't start further atomic attacks: an objective failed with a system-wide error (AuthenticationError: ...).

🤖 Generated with Claude Code

A scenario stopped starting atomic attacks as soon as any objective
errored, so one bad objective, such as a garbled adversarial reply,
left every unstarted atomic attack without results.

Classify each failed objective's error chain instead. New atomic
attacks stop only for errors every remaining objective would hit:
rejected credentials, a missing model or deployment, connection
failures and timeouts, and rate-limit or server errors that outlast
the target's retries. As a safety net, the same root error failing
three distinct objectives also stops them. Other errors stay on
their objective; the run still ends failed and resume re-runs only
those objectives.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings December 4, 2026 00:28

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.

🟡 Changes recommended

The failure tracker can stop valid queued attacks when a single prompt introduces an invalid HTTP header, because it treats LocalProtocolError as a system-wide failure. Separately, when attack execution and error-result persistence both fail, authentication or connection errors wrapped in an ExceptionGroup are missed, allowing the scenario to keep starting atomic attacks despite a system-wide failure.

2 open issues
What changed in this PR

Changes PyRIT scenario scheduling to continue after objective-specific errors, complementing #4298’s retry/resume ordering fix.

Changes:

  • Adds failure classification and a three-objective repeated-error stopping threshold.
  • Adds regression coverage for continuation, stopping, and selective resume.
  • Updates resiliency documentation and flowcharts.
File Description
tests/​unit/​scenario/​core/​test_scenario.py Tests scenario continuation and stopping conditions.
tests/​unit/​scenario/​core/​test_scenario_retry.py Tests resuming only errored objectives.
tests/​unit/​scenario/​core/​test_objective_failure_tracker.py Tests error classification and repeated-failure tracking.
pyrit/​scenario/​core/​scenario.py Uses the tracker to decide whether to start more attacks.
pyrit/​scenario/​core/​_objective_failure_tracker.py Implements failure classification and tracking.
doc/​code/​scenarios/​0_scenarios.py Updates resiliency explanations and flowchart comments.
doc/​code/​scenarios/​0_scenarios.ipynb Mirrors the documentation updates in the notebook.

Review effort: Balanced

system_wide_types = (
ClientAuthenticationError,
APIConnectionError,
httpx.TransportError,
Comment on lines +84 to +85
if isinstance(error, system_wide_types):
return True
@behnam-o
Behnam (behnam-o) marked this pull request as ready for review December 4, 2026 00:45
@richlundeen

Copy link
Copy Markdown
Contributor

I think a better policy may be, once an atomic attack reports an execution error, stop starting new attacks, let in-flight work finish, and let max_retries decide whether to resume. That gives operators one place to decide whether to spend more calls after an attack errors, without asking the scheduler to also decide.

https://microsoft.github.io/PyRIT/latest/code/setup/resiliency/

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.

3 participants