Skip to content

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

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

Richard Lundeen (richlundeen) wants to merge 9 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. This PR now carries only the one resume change main doesn't have yet.

Description

Execute no longer records or checks a hash of its source conversation. A run whose source conversation was edited or deleted resumes on the history it planned instead of being refused.

#4350 stores each run's planned seed groups, and Execute's objective seed group already holds the copied history. Execute still stored a hash of the source conversation and, on resume, re-ran seed resolution only to recompute that hash and refuse a changed source. A deleted source failed even earlier, because the re-run could not read it.

flowchart LR
  L["Load the stored<br/>planned seed groups"] --> H["Objective group already<br/>holds the copied history"]
  H --> R["Continue the run on<br/>the planned history"]
Loading
  • Removes Execute.PREPENDED_CONVERSATION_HASH_KEY, the hash written to run metadata, its check in _validate_stored_scenario, and Execute's _prepare_resume_state_async override. No built-in scenario calls the seed resolver on resume now, as the scenario instructions already say. Runs that stored the old key still resume; the key is ignored.
  • Replaces the test that expected a refusal with one that appends to, edits, or deletes the source conversation and resumes on the planned history, updates the GUI resume test, and updates the resume note in the technique doc. Also removes two resolver docstring sentences (garak exploitation.py and system_prompt_extraction.py) that still said resume calls the resolver.

An earlier version of this PR also reworked resume around a _restore_resume_state_async hook, an exact plan check, and resume state saved in run metadata for ApiKey, PromptInject, and AssertPolicy. main already resumes from stored seed groups with per-scenario restores (#4350), so those parts are dropped. 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.
  • Dropping the private _seed_groups overwrite in _apply_persisted_run_plan.

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.

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