Commit b54c47f
Victor Valbuena
FEAT: Add skip_cached cross-run caching to AdversarialBenchmark
Adds a skip_cached: bool = False constructor parameter and a thin
_get_atomic_attacks_async override on AdversarialBenchmark that, when
enabled, filters out atomic-attack candidates whose
(atomic_attack_name, technique_eval_hash) tuple appears in any prior
COMPLETED ScenarioResult for the same scenario name + VERSION with
outcome SUCCESS or FAILURE. ERROR and UNDETERMINED outcomes always
retry. Caching is off by default to preserve existing behavior.
Built on the AttackResultAttribution primitives introduced in microsoft#1758:
- AtomicAttack.technique_eval_hash provides the candidate side of the
cache key (content-derived via AtomicAttackEvaluationIdentifier).
- AttackResultEntry.attribution_data['parent_collection' +
'parent_eval_hash'] provides the persisted side; the executor stamps
these per AttackResult, so two atomic attacks sharing a name but
using different technique configurations don't cross-pollinate.
Defensive behavior:
- Missing attribution_data or missing parent_collection -> skip the row
silently (treat as not-cached).
- Memory exceptions from get_scenario_results / get_attack_results ->
log a warning and fall back to no filtering. Caching becomes a no-op
rather than blocking the run.
- Scenarios in IN_PROGRESS / FAILED / CANCELLED state contribute
nothing (no get_attack_results query made for them at all).
- Scenario name is matched on type(self).__name__ (PascalCase
"AdversarialBenchmark"), aligned with how ScenarioIdentifier stores
it; VERSION filter ensures the VERSION bump in the previous commit
invalidates old VERSION=1 results for cache purposes (they remain
queryable; they just don't suppress fresh runs).
Tests: 11 new unit tests (TestAdversarialBenchmarkSkipCachedFilter +
TestAdversarialBenchmarkSkipCachedInit) covering filtering semantics,
outcome filters, eval-hash disambiguation, scenario-state filter,
query-arg shape, missing-attribution defense, memory-error defense,
and constructor defaults. Integration test with full persistence
round-trip is a separate follow-up commit (F6.3 per plan).
Wider regression: 1649/1649 pass across scenario+setup+registry+
backend.
Failure mode flagged for the PR description batch:
- The override + helper are scenario-agnostic in shape and should
probably live on base Scenario behind a duck-typed identity hook
(e.g. cls.cache_scope_name() classmethod) so other scenarios
(RapidResponse, Scam, etc.) can opt into skip_cached without
copy-pasting the wrapper. Enhancement, not a bug; tracked as
lift-skip-cached-to-base-scenario.1 parent d652a56 commit b54c47f
2 files changed
Lines changed: 385 additions & 2 deletions
File tree
- pyrit/scenario/scenarios/benchmark
- tests/unit/scenario/benchmark
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| |||
218 | 220 | | |
219 | 221 | | |
220 | 222 | | |
| 223 | + | |
221 | 224 | | |
222 | 225 | | |
223 | 226 | | |
| |||
227 | 230 | | |
228 | 231 | | |
229 | 232 | | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
230 | 243 | | |
231 | 244 | | |
232 | 245 | | |
233 | 246 | | |
234 | 247 | | |
235 | 248 | | |
| 249 | + | |
236 | 250 | | |
237 | 251 | | |
238 | 252 | | |
| |||
241 | 255 | | |
242 | 256 | | |
243 | 257 | | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
244 | 354 | | |
245 | 355 | | |
246 | 356 | | |
| |||
0 commit comments