Skip to content

FEAT: Propagating Scenario/Attack Errors#1720

Merged
rlundeen2 merged 9 commits into
microsoft:mainfrom
rlundeen2:users/rlundeen/scenario-errors
May 13, 2026
Merged

FEAT: Propagating Scenario/Attack Errors#1720
rlundeen2 merged 9 commits into
microsoft:mainfrom
rlundeen2:users/rlundeen/scenario-errors

Conversation

@rlundeen2
Copy link
Copy Markdown
Contributor

This PR adds the ability to structurally keep track of errors and retries in ScenarioResult and AttackResult. This will be important to surface these from the backend to front end, and useful for analytics (e.g. we can view retries to targets over time)

rlundeen2 and others added 5 commits May 11, 2026 15:29
- Add RetryEvent dataclass for capturing Tenacity retry attempts
- Add RetryCollector (contextvar-based) to accumulate retry events per-attack
- Hook log_exception() to record retries to active collector
- Add error_message, error_type, error_traceback, retry_events, total_retries
  fields to AttackResult and AttackResultEntry
- Add error_attack_result_ids pointer to ScenarioResult/ScenarioResultEntry
- Create ON_ERROR handler in attack strategy to persist failed AttackResults
  with error details, even when the attack crashes before returning
- Wire RetryCollector lifecycle in pre/post execute event handlers
- Link failed attack results to scenario result on incomplete objectives
- Add RetryEventResponse, error/retry fields to REST API models
  (AttackSummary, ScenarioRunSummary, AtomicAttackResults)
- Update service layer to populate error/retry info from persisted data
- Add Alembic migration for new database columns
- Add update_scenario_error_attacks() to MemoryInterface

All new fields are nullable/optional for backward compatibility.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- RetryEvent: serialization, round-trip, defaults, missing fields
- RetryCollector: contextvar lifecycle, record(), asyncio task isolation
- AttackResult: error field defaults, storage, DB round-trip, truncation
- ScenarioResult: error_attack_result_ids defaults and storage

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread pyrit/memory/memory_interface.py Outdated
Comment thread pyrit/executor/attack/core/attack_strategy.py
Comment thread pyrit/backend/services/scenario_run_service.py
rlundeen2 and others added 4 commits May 12, 2026 11:17
- Replace placeholder Alembic revision ID (a1b2c3d4e5f6) with proper generated hash (4f9db4b0a77f)
- Swap persist-before-set order in _on_error_async so context only gets error_attack_result_id after DB write succeeds; clear stale ID at handler entry
- Rewrite update_scenario_error_attacks to do read-modify-write in a single DB session
- Extract retry_events_to_response() shared helper in attack_mappers, replacing duplicate code in scenario_run_service
- Remove inline import from loop body in scenario_run_service
- Replace __import__("uuid") hack with proper top-level import
- Rename _on_error to _on_error_async per style guide

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rlundeen2 rlundeen2 enabled auto-merge May 13, 2026 00:02
@rlundeen2 rlundeen2 added this pull request to the merge queue May 13, 2026
Merged via the queue into microsoft:main with commit ed4b251 May 13, 2026
48 checks passed
@rlundeen2 rlundeen2 deleted the users/rlundeen/scenario-errors branch May 13, 2026 00:24
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.

2 participants