Repository navigation
MAINT: Simplify scenario resume around stored planned seed groups (seed 3) - #4366
Richard Lundeen (richlundeen) wants to merge 11 commits into
Conversation
Resuming a scenario after its dataset was deleted reported "no seeds found in memory. Call prepare_async() ...", which resume never does. After an edit or refresh it reported only "missing N planned seed group(s)". Resume now names the deleted datasets, or the resolved datasets whose content changed, and ends with the two recoveries: re-import the content the run used, or drop scenario_result_id to start a new run. Only a dataset that is actually absent is reported as deleted; other resolution errors propagate unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A new run now stores the population it was built from, in the same transaction as its ScenarioResult, in ScenarioPlanSeedGroupEntries. Resume rebuilds from those groups and never prepares, resolves, or resamples the population datasets, so editing, refreshing, or deleting a dataset no longer breaks resume. Scenarios that override seed resolution still run it on resume for the state it sets up, and discard its groups. This also keeps exactly the copies of duplicate groups the first run sampled (microsoft#4157), and removes the legacy replay: objective_hashes, _apply_persisted_objectives, and rebuilding plans for results without one. Runs created before this change can no longer be resumed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… seeds Resume now receives exactly the planned population, in order and with its duplicate copies, so AdaptiveScenario builds and names its atomics the same way a new run does and only reads its saved technique choices from the plan. This removes _restore_planned_populations and the separate resume branches for the baseline and per-dataset atomics. AtomicAttack.keep_seed_groups_with_hashes only served the removed objective_hashes replay, so it is deprecated for removal in 1.4.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resume rebuilds a run from its stored planned seed groups, but dataset media cleanup didn't count those groups as references, so deleting a dataset could remove a file a paused run still needed. stored_media_keys now also reads media paths from planned seed groups of runs that haven't completed, using the has_media index. Planned seed group writes go through the same dataset reference guard as seeds and messages, so a new run can't plan media that is already queued for deletion. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resume no longer re-runs a scenario's seed resolution for its side effects. Scenarios that keep state from resolution restore it in a new _restore_resume_state_async hook: LatentInjection rebuilds its scorer from the stored groups, PromptInject and ApiKey restore templates and excluded values saved in run metadata, and PackageHallucination and AssertPolicy still read their datasets. Scenarios that only reshape groups no longer read datasets on resume, so they resume after a dataset delete too. Resume now requires the rebuilt plan to equal the stored plan and names the atomic groups that differ, replacing the reorder-and-filter replay. Execute no longer records or checks a hash of its source conversation, since the stored group holds the history it planned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
Resume validation rejects unchanged, partially cached AdversarialBenchmark runs because the rebuilt atomic ordering differs from the saved plan; restore the saved ordering and add a regression test.
1 open issue
What changed in this PR
Building on stored populations and media retention in #4350 and #4365, this PR simplifies PyRIT scenario resume so most scenarios no longer reread their datasets.
Changes:
- Unifies resume around stored seed groups, explicit state restoration, and exact plan validation.
- Restores scorer and template state from saved data where possible, retaining necessary dataset reads for AssertPolicy and PackageHallucination.
- Removes Execute’s source-history hash check and updates regression tests and scenario guidance.
| File | Description |
|---|---|
tests/unit/scenario/scenarios/technique/test_execute.py |
Verifies resume preserves planned history after source edits. |
tests/unit/scenario/scenarios/adaptive/test_text_adaptive.py |
Updates stored-population and saved-choice expectations. |
tests/unit/scenario/garak/test_prompt_inject.py |
Tests template restoration after dataset deletion. |
tests/unit/scenario/garak/test_latent_injection.py |
Tests saved cases and scorer reconstruction. |
tests/unit/scenario/garak/test_exploitation.py |
Updates the plan-mismatch error expectation. |
tests/unit/scenario/garak/test_api_key.py |
Tests scorer restoration without corpus reads. |
tests/unit/scenario/core/test_scenario.py |
Covers stored populations, restoration hooks, and resume failures. |
tests/unit/scenario/core/test_scenario_retry.py |
Removes obsolete objective-filter replay tests. |
tests/unit/scenario/core/test_scenario_dataset_overrides.py |
Updates resume comments and configuration-mismatch expectations. |
tests/unit/scenario/core/test_atomic_attack.py |
Checks deprecated filtering emits warnings. |
tests/unit/memory/test_scenario_plan_seed_groups_migration.py |
Covers migration round trips and SQL Server compilation. |
tests/unit/memory/test_planned_seed_groups.py |
Tests ordered storage, duplicates, and media references. |
tests/unit/memory/test_dataset_lifecycle.py |
Tests planned-media retention and deletion guards. |
tests/unit/memory/test_dataset_lifecycle_migration.py |
Includes planned seed storage in schema expectations. |
tests/unit/backend/test_scenario_resume.py |
Updates persistence interception for planned-result writes. |
pyrit/scenario/scenarios/technique/execute.py |
Removes source-conversation hash storage and validation. |
pyrit/scenario/scenarios/garak/prompt_inject.py |
Saves templates and restores goal-scoring state. |
pyrit/scenario/scenarios/garak/package_hallucination.py |
Restores scorer state from package registries. |
pyrit/scenario/scenarios/garak/latent_injection.py |
Rebuilds scorer coverage from stored groups. |
pyrit/scenario/scenarios/garak/api_key.py |
Saves and restores default scorer exclusions. |
pyrit/scenario/scenarios/foundry/assert_policy.py |
Restores judges and repeated IDs from datasets. |
pyrit/scenario/scenarios/adaptive/adaptive_scenario.py |
Rebuilds attacks from stored populations and choices. |
pyrit/scenario/core/scenario.py |
Adds stored-population loading, restoration hooks, and exact validation. |
pyrit/scenario/core/atomic_attack.py |
Deprecates the former resume filtering helper. |
pyrit/memory/memory_session.py |
Guards planned-group writes against deleted media. |
pyrit/memory/memory_models.py |
Defines stored planned groups and media extraction. |
pyrit/memory/memory_interface.py |
Persists results with populations and reads them back. |
pyrit/memory/dataset_lifecycle.py |
Retains media referenced by incomplete runs. |
pyrit/memory/alembic/versions/c7d1e9a3b5f2_add_scenario_plan_seed_groups.py |
Creates indexed storage for planned seed groups. |
.github/instructions/scenarios.instructions.md |
Documents state restoration and exact resume validation. |
Review effort: Balanced
Resolves the AssertPolicy conflict with microsoft#4130, which removed its population-derived judges. AssertPolicy now saves the logical IDs repeated in its unsampled population with the run and restores them on resume, so it no longer reads its datasets. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
hannahwestra25 thanks for the review! We prob need to do #4482 first :) |
Main already contains the squash-merged lower layers (microsoft#4350, microsoft#4482) and the resume design this branch carried, so every file this branch touched takes main's version. The remaining Execute change follows separately. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Execute stored a hash of its source conversation and, on resume, re-ran seed resolution only to recompute it and refuse a changed source. The planned objective seed group already stores that history, so resume now replays it: a run whose source conversation was edited or deleted resumes on the history it planned. Runs that stored the old hash key still resume; the key is ignored. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resume never calls _resolve_seed_groups_by_dataset_async; it loads the stored planned seed groups. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
review:5944031830, review:6033252157 Rebuilt on Verified on published commit |
Richard Lundeen (richlundeen)
left a comment
There was a problem hiding this comment.
Automated review completed. No blocking concerns remain. This review records source coverage; merging is handled separately.
Resume no longer overwrites each atomic attack's private seed groups. It checks that every planned group rebuilds exactly its planned seed groups and refuses with its own message otherwise, since re-importing data cannot restore a stored population. LatentInjection builds its trigger scorer in the builder, which runs on new and resumed runs, and drops its resume hook. Docstrings no longer say resume calls the seed resolver. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Builds on #4350 (seed 1) and #4482 (seed 2), both merged.
Description
A resumed scenario run rebuilds from the seed groups stored when it was planned. This PR removes the resume paths that still re-read or rewrite that data: Execute's source-conversation hash, the base class's private seed-group rewrite, and LatentInjection's resume hook.
Execute.PREPENDED_CONVERSATION_HASH_KEY, the hash written to run metadata, its check in_validate_stored_scenario, and the_prepare_resume_state_asyncoverride that re-ran seed resolution only to recompute it. The objective seed group already holds the copied history, so a run whose source conversation was edited or deleted resumes on the planned history instead of being refused. Runs that stored the old key still resume; the key is ignored._apply_persisted_run_planno longer overwrites each atomic attack's private_seed_groups. It checks that each planned atomic group rebuilds exactly its planned seed groups and refuses the resume otherwise, so an unplanned seed group in a planned atomic group fails loudly instead of being dropped. A partially cached AdversarialBenchmark run, whose plan lists its cached objectives last, still resumes; a new test covers it._build_atomic_attacks_asyncfrom the planned groups, which runs on new and resumed runs, and drops its_prepare_resume_state_asyncoverride.scenarios.instructions.mdnow points scenarios to the builder for state the planned groups carry and keeps the hook for state that needs a helper dataset.dataset_configuration.py,web_injection.py, garakexploitation.pyandsystem_prompt_extraction.py), updates the resume note in the technique doc, and replaces the Execute test that expected a refusal with one that appends to, edits, or deletes the source conversation and resumes on the planned history.Possible follow-ups:
scenario_registry_name, after AdversarialBenchmark lists cached groups in population order.