Repository navigation
MAINT: Use TaskGroup for Anthropic model-written evals file fetches (P311-11) - #3959
Merged
Roman Lutz (romanlutz) merged 4 commits intoNov 5, 2026
Conversation
…P311-11) Replace the bare asyncio.gather over the 172 JSONL fetches with an asyncio.TaskGroup so a failed fetch cancels sibling fetches still queued for a worker thread instead of leaving them running unowned. The first fetch error is re-raised unwrapped, so callers still see the original exception type, and seeds keep manifest order. Part of microsoft#3166.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the change to cancel sibling dataset fetches when one fails.
No open issues 🎉
What changed in this PR
This PR addresses P311-11 in #3166 by giving Anthropic model-written eval file fetches a shared task lifetime, so a failed fetch cancels pending siblings.
Changes:
- Replaces
asyncio.gatherwithasyncio.TaskGroupin the dataset loader. - Re-raises the original fetch exception and preserves manifest ordering.
- Adds tests for sibling cancellation, exception identity and cause, and result ordering.
| File | Description |
|---|---|
tests/unit/datasets/test_anthropic_model_written_evals_dataset.py |
Adds cancellation, exception-preservation, and ordering tests. |
pyrit/datasets/seed_datasets/remote/anthropic_model_written_evals_dataset.py |
Uses a task group for file fetches while preserving errors and seed order. |
Review effort: Balanced
Roman Lutz (romanlutz)
self-requested a review
November 4, 2026 14:53
19 of 25 tasks
Roman Lutz (romanlutz)
approved these changes
Nov 4, 2026
Run file-fetch task groups in an owned task to preserve caller cancellation counts on Python 3.11 and 3.12. Cover repeated failures and external cancellation cleanup. 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-11): the parent-scoped JSONL fetches in
_AnthropicModelWrittenEvalsDataset._fetch_dataset_async.The loader fetched all 172 JSONL files with a bare
asyncio.gather. When one fetch failed, the error propagated but the sibling fetches kept running unowned, and most of them were still queued for a worker thread (asyncio.to_thread, default executor ofcpu_count + 4threads). This PR:asyncio.TaskGroup, so the first failure cancels the remaining fetches. Fetches still queued for a thread are dropped; fetches already running in a thread finish, since threads cannot be interruptedexceptblock, so callers see the original exception (type, traceback, cause) rather than anExceptionGroup.SeedDatasetProvider.fetch_datasets_asyncerror handling and notes are unaffectedScope is limited to this one site;
pyrit/common/task_utils.pyand othergathercall sites are unchanged.Tests and Documentation
test_fetch_failure_cancels_pending_sibling_fetches: a failing fetch cancels every sibling fetch, and the exact original exception (with its__cause__) reaches the caller. Fails against the previousgatherimplementation.test_fetch_results_keep_manifest_order: fetches finish in reverse order and seeds still follow manifest order.to_threadwork (2-worker executor: 3 of 20 jobs ran after the first failure).tests/unit/datasets(anthropic + seed dataset provider): 260 passedruff check/ruff format --check: passedty checkon both changed files: no new diagnosticsHappy to adjust anything in this PR