Repository navigation
FIX: Preserve failures in exception group handling (P311-12) - #3983
Merged
Roman Lutz (romanlutz) merged 4 commits intoNov 6, 2026
Merged
Roman Lutz (romanlutz) merged 4 commits into
Roman Lutz (romanlutz) merged 4 commits into
Conversation
- Catch mixed BaseExceptionGroups from close_services_async in runtime shutdown and live apply, so memory is still disposed, earlier errors are kept, and apply records restart-required. - Add other concurrent Anthropic fetch failures as notes on the raised error instead of discarding them. - Include child failures in persisted scenario error messages.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the changes preserving exception-group failure details.
No open issues 🎉
What changed in this PR
This PR addresses P311-12 in #3166 by preserving exception-group failure details across PyRIT’s runtime lifecycle, dataset fetching, and scenario error reporting, while retaining existing exception types and single-failure behavior.
Changes:
- Handle mixed exception groups during shutdown and live apply so cleanup and failure-state updates still occur.
- Attach concurrent dataset-fetch failures as notes to the original raised exception.
- Summarize nested exception groups in scenario errors and add regression coverage.
| File | Description |
|---|---|
tests/unit/scenario/core/test_scenario_partial_results.py |
Verify persisted errors include every partial failure. |
tests/unit/exceptions/test_exceptions_helpers.py |
Cover plain, empty-message, and nested exception summaries. |
tests/unit/datasets/test_anthropic_model_written_evals_dataset.py |
Verify concurrent fetch failures retain secondary error notes. |
tests/unit/backend/test_scenario_run_service.py |
Verify grouped failures reach run state and persistence. |
tests/unit/backend/test_runtime_lifecycle.py |
Cover cleanup and live-apply behavior for exception groups. |
pyrit/scenario/core/scenario.py |
Persist detailed exception-group summaries. |
pyrit/exceptions/exceptions_helpers.py |
Add recursive exception summarization. |
pyrit/datasets/seed_datasets/remote/anthropic_model_written_evals_dataset.py |
Preserve secondary fetch failures as exception notes. |
pyrit/backend/services/scenario_run_service.py |
Use detailed summaries in run failure reporting. |
pyrit/backend/services/runtime_lifecycle.py |
Catch mixed groups while preserving cancellation propagation. |
Review effort: Balanced
Contributor
Author
|
The failure looks unrelated to this PR, and the most likely cause is a stalled macOS runner, though I couldn't reproduce it:
Roman Lutz (@romanlutz) can you kindly re-run the failed job? If this keeps happening, the 10s limit may be worth revisiting in a separate change, since it is much tighter than the 300s |
Roman Lutz (romanlutz)
self-requested a review
November 5, 2026 18:38
19 of 25 tasks
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Roman Lutz (romanlutz)
approved these changes
Nov 6, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
hannahwestra25
pushed a commit
to Kaap10/PyRIT
that referenced
this pull request
Nov 6, 2026
Resolve the import conflict in pyrit/scenario/core/scenario.py by keeping both ScenarioRunInProgressException (this PR) and summarize_exception (microsoft#3983). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Part of #3166 (P311-12): three sites where exception-group failures were being lost. Exception types and single-failure behavior are unchanged.
Runtime shutdown and live apply
close_services_asyncraises a pureBaseExceptionGroupwhen two closures fail and at least one is aCancelledError.except (Exception, asyncio.CancelledError)does not catch that group, so inRuntimeLifecycle:_shutdown_runtime_async, which skipped memory disposal and dropped errors already collected.restart-required.Both handlers now also catch
BaseExceptionGroup, asgithub_copilot_target.pyandllm_scoring.pyalready do. Apply re-raises any error that is not anException, which coversCancelledErrorand groups that can carry it. A plainExceptionGroupis still absorbed into the state, as before.Anthropic evals fetches
TaskGroupcan collect several failures, but onlygroup.exceptions[0]was raised. That same exception is still raised, so callers see no type change, and the other failures are added withadd_note.Persisted scenario errors
str(group)only gives a child count, so stored errors readMultiple failed (2 sub-exceptions). A newsummarize_exceptionhelper keeps child failures in the message, which is used byScenario._mark_scenario_failed_asyncandScenarioRunService:error_typestaysExceptionGroup, and messages for non-group errors are unchanged. This text is the only user-visible change.Out of scope
This PR adds no
except*and no newTaskGroupusage, because a broad migration would change behavior:TaskGroupwraps even a single failure, which breaksexcept ValueErrorhandlers and hides the message behindunhandled errors in a TaskGroup (1 sub-exception).TaskGroupcancels siblings on the first failure, while the attack executor (partial results) and runtime shutdown (draining) let them finish.gather_with_cleanup_asyncand the scenario supervisor deliberately defer caller cancellation until cleanup finishes.raiseinsideexcept*wraps a plain exception in a group, and a task re-raising a cancellation this way reportstask.cancelled() == False.A live apply cancelled through a mixed group still ends as a failed task rather than a cancelled one. That is unchanged, because converting it to a plain
CancelledErrorwould drop the other errors in the group.Tests and Documentation
New regression tests:
test_shutdown_mixed_close_group_still_disposes_memory_and_reports_errors_async: with and without an earlier scenario shutdown failure.test_apply_mixed_close_group_requires_restart_and_propagates_cancellation_asynctest_apply_close_group_without_cancellation_requires_restart_without_raising_async: pins existing behavior, and passes before and after this change.test_concurrent_fetch_failures_keep_first_error_and_note_the_otherstest_execute_run_reports_every_failure_in_an_exception_grouptest_summarize_exception: plain, empty, group and nested group cases.test_concurrent_partial_failures_resume_without_duplicate_resultsandtest_fetch_failure_cancels_pending_sibling_fetches: extended with new assertions.The shutdown, apply (mixed group), fetch, run service and partial failure tests were confirmed failing before the fix.
Results:
tests/unitwith-n 4: 33760 passed, 460 skipped, 4 xfailed, 2 failed. I ran this without--dist=loadfile, whichmake unit-testuses.mainand are unrelated:test_codeql_merge_group_scenariosneedsnode, which is not installed locally, andtest_separate_research_target_receives_research_stages_asyncraisesUnboundLocalError.ruff checkandruff format: passed.ty checkon the changed source files: same diagnostics asmain.