FIX Drain nested scoring and batch tasks on failure - #2856
Open
biefan (biefan) wants to merge 4 commits into
Open
biefan (biefan) wants to merge 4 commits into
biefan (biefan) wants to merge 4 commits into
Conversation
This was referenced Sep 25, 2026
Roman Lutz (romanlutz)
approved these changes
Oct 3, 2026
Roman Lutz (romanlutz)
enabled auto-merge
October 3, 2026 14:01
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> # Conflicts: # pyrit/score/message_scorer.py # pyrit/score/true_false/true_false_composite_scorer.py
This branch has not been deployed
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
A failed scoring call can return while nested scorers or other items in its batch still run, allowing old work to overlap retries or write scores after the caller has reported failure.
The response-level protection from #2695 does not cover every concurrency boundary. This change applies a shared cleanup helper to:
Scorer.score_with_scorers_async()TrueFalseCompositeScorerMessageScorerscore_batch_async()/batch_task_async()The helper shields the initial gather and explicitly owns cancellation. It cancels unfinished tasks only when they are not already processing a cancellation request, then shields and awaits the drain. This matters when one child exits immediately and another is still awaiting asynchronous cleanup: caller cancellation must not reach that slow child twice. Further caller cancellation is propagated after cleanup, and cleanup errors do not replace the primary failure. The original gather's exception is retrieved after draining so a detached shield does not leave an unobserved future error.
Successful result ordering, completed score persistence, batch sizes and rate-limit validation are preserved. Later batches do not start after a failure. Completed requests or scores are not rolled back.
Tests and Documentation
get_scores(score_type="true_false"), which actually queries storage. A separate real-score check confirmed that an unfiltered lookup returns[]while the filtered lookup returns the saved row.make unit-test(Python 3.11, default dependencies): 20,425 passed, 146 skipped, 1 failed. The sole failure is the pre-existingtest_get_seed_dataset_summaries_follows_a_trailing_blank_insensitive_collationintests/unit/memory/memory_interface/test_interface_seed_prompts.py, previously reproduced on unmodified upstream in the same environment.ty check pyrit.The common helper and root/batch docstrings document the cleanup contract. No notebooks changed and no live model endpoints were used.