Skip to content

MAINT: Simplify scenario resume around stored planned seed groups (seed 3) - #4366

Open
Richard Lundeen (richlundeen) wants to merge 11 commits into
microsoft:mainfrom
richlundeen:simplify-resume
Open

Richard Lundeen (richlundeen) wants to merge 11 commits into
microsoft:mainfrom
richlundeen:simplify-resume

Conversation

@richlundeen

@richlundeen Richard Lundeen (richlundeen) commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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.

flowchart LR
  L["Load the stored<br/>planned seed groups"] --> B["Build the atomic attacks<br/>(same path as a new run)"]
  B --> C["Check each group rebuilds<br/>exactly its planned seeds"]
  C --> R["Continue the run"]
Loading
  • Execute: removes Execute.PREPENDED_CONVERSATION_HASH_KEY, the hash written to run metadata, its check in _validate_stored_scenario, and the _prepare_resume_state_async override 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.
  • Base resume: _apply_persisted_run_plan no 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.
  • Resume errors: a planned group that no longer builds its seed groups gets its own message, which says to start a new run. The "re-import the dataset content" advice stays only where re-importing helps: a deleted or edited helper dataset.
  • LatentInjection: builds its trigger scorer in _build_atomic_attacks_async from the planned groups, which runs on new and resumed runs, and drops its _prepare_resume_state_async override. scenarios.instructions.md now points scenarios to the builder for state the planned groups carry and keeps the hook for state that needs a helper dataset.
  • Removes the remaining docstrings that said resume calls the seed resolver (dataset_configuration.py, web_injection.py, garak exploitation.py and system_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:

  • A stricter plan-identity check, using a replay key that ignores description, tags, and scenario_registry_name, after AdversarialBenchmark lists cached groups in population order.
  • Resume state for ApiKey and PromptInject that doesn't depend on their helper datasets, saving every template and testing older runs.

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>
Copilot AI balanced review requested due to automatic review settings November 17, 2026 18:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread pyrit/scenario/core/scenario.py Resolved
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 hannahwestra25 self-assigned this Nov 24, 2026

@hannahwestra25 hannahwestra25 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed this PR's own layer (408b4b8 and the merge resolution). The branch still carries the #4350 pre-squash commits and the old seed-2 commit, and it conflicts with main in 19 files. Please rebuild it on main and #4482.

Comment thread pyrit/scenario/core/scenario.py Resolved
@richlundeen

Copy link
Copy Markdown
Contributor Author

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>
@richlundeen

Copy link
Copy Markdown
Contributor Author

review:5944031830, review:6033252157

Rebuilt on main in 30e0d95 and narrowed to the Execute change. main already has #4350 and #4482, so the branch takes main's resume code. That drops the exact plan check (and its AdversarialBenchmark ordering and registry-name refusals), the ApiKey, PromptInject, and AssertPolicy run-metadata payloads, and their older-run branches. What's left removes Execute's source-conversation hash, so a run resumes on its planned history after the source is edited or deleted. The description lists the dropped parts as possible follow-ups.

Verified on published commit 27a608b6414dfda83adb0ef88cc6c6f30fd875bf.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

This branch has not been deployed

No deployments
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.

3 participants