Skip to content

FIX: Adaptive Scenario bugs#2152

Merged
rlundeen2 merged 3 commits into
microsoft:mainfrom
rlundeen2:rlundeen2-glowing-robot
Jul 9, 2026
Merged

FIX: Adaptive Scenario bugs#2152
rlundeen2 merged 3 commits into
microsoft:mainfrom
rlundeen2:rlundeen2-glowing-robot

Conversation

@rlundeen2

Copy link
Copy Markdown
Contributor

Summary

Fixes two pre-existing bugs in the adaptive-scenario resume/attack machinery (surfaced during Phase F, not caused by it).

Bug 1 — Non-deterministic resume under max_dataset_size

On resume, DatasetAttackConfiguration re-drew an unseeded random.sample before restricting to the persisted objective_hashes. Whenever max_dataset_size < len(dataset), the fresh draw diverged from the persisted subset, the intersection dropped them, and resume aborted with "persisted objective hash(es) are no longer present in the dataset."

Fix: thread an apply_sampling keyword through the seed-resolution path so resume resolves the full deterministic dataset and lets the persisted hashes reconstruct the exact original subset. Fresh runs still sample as before.

Bug 2 — Flaky "All message pieces must be from the same conversation"

_generate_next_message_async (simulated conversation) built its request via Message.from_prompt, which leaves conversation_id unset (None), then passed that None to set_system_prompt. get_message_pieces skips its conversation filter when the id is falsy, so it returned every piece in memory and the grouper raised as soon as memory held >1 conversation. Intermittent because it needed both multiple conversations in memory and the epsilon-greedy selector to pick the simulated single_turn (context_compliance) path.

Fix: scope the system prompt and generated request message to a fresh unique conversation_id so the filter is always applied.

Testing

  • New regression tests for both bugs (each verified to fail pre-fix, pass post-fix).
  • Bug 2 confirmed via live adaptive single_turn run: failed on first attempt before the fix, 5/5 clean after.
  • tests/unit/scenario/ (795) + tests/unit/executor/attack/{multi_turn,component}/ (468) pass; pre-commit green.

rlundeen2 and others added 2 commits July 9, 2026 09:49
Resume re-drew an unseeded random.sample before restricting to persisted
objective hashes, so whenever max_dataset_size < len(dataset) the fresh draw
diverged from the persisted subset and resume aborted with 'persisted objective
hash(es) are no longer present in the dataset'.

Thread an apply_sampling keyword through the seed-resolution path so resume
resolves the full deterministic dataset and lets the persisted hashes
reconstruct the exact original subset. Fresh runs still sample as before.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
_generate_next_message_async built the request message with Message.from_prompt,
which leaves conversation_id unset (None), then passed that None to
set_system_prompt. set_system_prompt calls get_conversation_messages, whose
conversation_id filter is skipped when the id is falsy, so it returned every
message piece in memory and group_conversation_message_pieces_by_sequence raised
'All message pieces must be from the same conversation' as soon as memory held
more than one conversation. This surfaced intermittently in adaptive single_turn
runs (context_compliance) once the epsilon-greedy selector picked the simulated
path and multiple conversations existed.

Scope the system prompt and the generated request message to a fresh unique
conversation id so the filter is always applied.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Comment thread pyrit/executor/attack/multi_turn/simulated_conversation.py
@jsong468 jsong468 self-assigned this Jul 9, 2026
A falsy conversation_id caused get_message_pieces to skip its filter and silently return pieces from every conversation, which surfaced as the flaky 'same conversation' error. Raise ValueError instead. Two TAP tests were passing only via this footgun (querying an empty conversation_id); retarget them to resolve the real node conversation from memory.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@rlundeen2 rlundeen2 enabled auto-merge July 9, 2026 23:22
@rlundeen2 rlundeen2 added this pull request to the merge queue Jul 9, 2026
Merged via the queue into microsoft:main with commit d7b9576 Jul 9, 2026
53 checks passed
@rlundeen2 rlundeen2 deleted the rlundeen2-glowing-robot branch July 9, 2026 23:46
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