Skip to content

MAINT: Ordering AttackResults by timestamp for perf - #2295

Merged
rlundeen2 merged 2 commits into
microsoft:mainfrom
rlundeen2:rlundeen2-optimize-attack-history-query
Jul 31, 2026
Merged

MAINT: Ordering AttackResults by timestamp for perf#2295
rlundeen2 merged 2 commits into
microsoft:mainfrom
rlundeen2:rlundeen2-optimize-attack-history-query

Conversation

@rlundeen2

@rlundeen2 rlundeen2 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

What & why

Loading Attack History in the GUI got slow at scale because the paginated query ordered and keyset-seeked on a JSON recency expression (COALESCE(json_extract(attack_metadata,'$.updated_at'), ...)) that no index can serve; this makes the real, indexable AttackResultEntry.timestamp column the single source of truth for "last updated" recency so the ordering/seek is index-served.

Changes

  • Memory layer: recency ORDER BY / keyset seek / cursor now use the timestamp column (timestamp DESC, id DESC). Removed the JSON recency expression and its SQLite/Azure overrides and the Python recency key. AttackResultsKeysetCursor simplified to (timestamp, attack_result_id).
  • Edit paths (attack_service.py): GUI edits (add message, branch, promote main) now bump the timestamp column instead of writing metadata.updated_at. metadata.created_at stays as a display-only field.
  • Indexes + migration (d7e9f1a3b5c6): adds ix_AttackResultEntries_conversation_id (dedup window) and ix_AttackResultEntries_timestamp_id (ORDER BY + seek). Backfills timestamp from the legacy updated_at/created_at JSON keys so manually-edited conversations keep their History order, and strips the redundant updated_at key. Downgrade restores it.

@jsong468 jsong468 self-assigned this Jul 30, 2026
Comment thread pyrit/memory/alembic/versions/d7e9f1a3b5c6_index_attack_result_recency.py Outdated
Comment thread pyrit/backend/mappers/attack_mappers.py
Make the indexable AttackResultEntry.timestamp column the single source of
truth for History recency, replacing the non-indexable JSON-extract sort
expression. Adds serving indexes + an Alembic migration that backfills
timestamp from the legacy attack_metadata.updated_at/created_at keys.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 5ae8d0da-5198-4ac0-acd9-65e6f7b5d283
@rlundeen2
rlundeen2 force-pushed the rlundeen2-optimize-attack-history-query branch from 01790cf to 058d1a3 Compare July 31, 2026 19:41
@rlundeen2
rlundeen2 added this pull request to the merge queue Jul 31, 2026
Merged via the queue into microsoft:main with commit 60d8abc Jul 31, 2026
54 checks passed
@rlundeen2
rlundeen2 deleted the rlundeen2-optimize-attack-history-query branch July 31, 2026 21: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.

2 participants