🐛 fix: fixed pair bugs - #513
Merged
Nicola Franco (franconicola) merged 2 commits intoJul 26, 2026
Merged
Conversation
Nicola Franco (franconicola)
temporarily deployed
to
460-fix-pair-off-rail-prompts - Docs PR #513
July 23, 2026 14:05 — with
Render
Destroyed
There was a problem hiding this comment.
Pull request overview
This PR updates the PAIR attack implementation to support true multi-stream execution with per-stream attacker histories, stricter attacker-output parsing, preserved decimal scoring, and a stream-aware dashboard view.
Changes:
- Added independent per-stream PAIR conversations with bounded history (
n_streams,keep_last_n) and stream-level concurrency (batch_size). - Enforced stricter attacker-output parsing (JSON-first) and preserved decimal judge scores end-to-end.
- Updated dashboard parsing/rendering and documentation to reflect per-stream traces and stream selection.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
hackagent/attacks/techniques/pair/attack.py |
Implements per-stream conversations, concurrency via worker pool, thread-local scorer explanations, and decimal score handling. |
hackagent/attacks/techniques/pair/config.py |
Adds PAIR config knobs (keep_last_n, target_str, translate_prompts) and updates attacker prompt template accordingly. |
hackagent/attacks/shared/prompt_parser.py |
Extends prompt parsing API with an optional plaintext fallback toggle. |
hackagent/server/dashboard/attack_cards/_pair.py |
Parses per-stream traces, preserves decimal scores, and renders a stream selector with per-stream “best” markers. |
docs/docs/attacks/pair.md |
Documents the new stream/concurrency behavior and additional configuration parameters. |
tests/unit/attacks/pair/test_attack.py |
Adds regression tests for per-stream history isolation, parallel stream execution, and decimal score preservation. |
tests/unit/attacks/pair/test_config.py |
Adds config round-trip coverage for the new PAIR settings and prompt formatting placeholders. |
tests/unit/server/dashboard/test_pair_card.py |
Adds dashboard parsing test for per-stream grouping, decimal scores, and best-attempt selection. |
Comments suppressed due to low confidence (1)
hackagent/attacks/techniques/pair/attack.py:796
_judge_responseuses a legacy judge fallback when_score_responsereturns1, but the fallback path returnsparsed_legacywithout updating the thread-local scorer explanation. As a result,_get_scorer_explanation()may return the previous AutoDAN assessment (or an empty string) even though the score came from the legacy judge, which makes the recorded/dashboard explanation inconsistent with the actual score source.
def _judge_response(self, goal: str, prompt: str, response: str) -> float:
"""Backward-compatible scorer hook expected by existing PAIR tests.
The ``prompt`` argument is currently unused by the AutoDAN-based
scorer path, but is preserved for API compatibility.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+917
to
+924
| try: | ||
| stream_worker_count = max(1, int(self.config.get("batch_size", 1))) | ||
| except (TypeError, ValueError): | ||
| stream_worker_count = 1 | ||
| stream_worker_count = min(n_streams, stream_worker_count) | ||
| # Best-result selection is shared across streams; model calls and | ||
| # histories are not. Only protect that tiny shared critical section. | ||
| best_result_lock = threading.Lock() |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Comment on lines
562
to
+567
| if content: | ||
| prompt = extract_prompt(content) | ||
| if prompt: | ||
| return prompt | ||
| parsed = extract_prompt_and_improvement(content, allow_plaintext=False) | ||
| # PAIR's attacker output is an assistant JSON turn. Reject | ||
| # non-JSON prose instead of accidentally sending its analysis | ||
| # to the target as a candidate jailbreak. | ||
| if parsed and parsed.get("prompt") and '"improvement"' in content: |
Comment on lines
+487
to
+492
| def _trim_stream_history(self, messages: List[Dict[str, str]]) -> None: | ||
| """Keep the system message plus the latest PAIR conversation turns.""" | ||
| keep_last_n = max(1, int(self.config.get("keep_last_n", 4))) | ||
| if len(messages) <= 1 + 2 * keep_last_n: | ||
| return | ||
| messages[:] = [messages[0], *messages[-2 * keep_last_n :]] |
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.
Fix PAIR stream isolation, iterative refinement, scoring, and dashboard details
Summary
This pull request aligns the PAIR implementation more closely with the original algorithm and fixes several issues affecting iterative refinement, multi-stream execution, score handling, and dashboard visualization.
Changes
keep_last_n.batch_sizecontrol the number of concurrent stream workers.n_streams,keep_last_n, andtarget_strsettings.7.5throughout the attack pipeline and dashboard.Testing
batch_size > 1.