Repository navigation
FIX: Keep Azure SQL analytics heatmaps within the report budget - #4790
Behnam (behnam-o) wants to merge 3 commits into
Conversation
On SQL Server, heatmaps compiled one large matrix statement whose compile time alone (6-9 s) exceeded the 5 s report budget, and stored JSON null harm categories made OPENJSON fail with error 13609. - Let SQL Server use the compact-profile path for harm-category and attack-type charts; the SDK aggregates raw harm arrays. - Check attack/converter identifier completeness once per identifier on SQL Server too, not by parsing each result's embedded JSON. - Pass only arrays to OPENJSON when expanding harm/converter memberships. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The SQL Server profile path normalizes Unicode chart keys differently from SQL grouping and drilldown, causing missing drilldown results and unstable keys when falling back to SQL.
1 open issue
What changed in this PR
Reduces Azure SQL attack-result analytics query costs to help supported charts finish within the report budget.
Changes:
- Enables bounded compact profiles for SQL Server harm-category and attack-type charts.
- Checks attack/converter identifier completeness per identifier.
- Guards
OPENJSONagainst non-array values.
| File | Description |
|---|---|
| tests/unit/memory/test_attack_analytics.py | Adds SQL Server query-compilation and profile-eligibility checks. |
| pyrit/memory/attack_analytics.py | Updates compact-profile docstrings for broader backend support. |
| pyrit/memory/attack_analytics_query.py | Implements SQL Server profiles, identifier checks, and guarded array expansion. |
| pyrit/analytics/_profile_aggregation.py | Removes SQLite-only wording from docstrings. |
| doc/contributing/11_memory_models.md | Documents SQL Server compact-profile support. |
| doc/code/analytics/0_attack_results.md | Explains supported charts, profile limits, and SQL fallback behavior. |
Review effort: Balanced
| return self._bounded_profiles( | ||
| profiles=compiler._compact_profile_inputs(dimensions), |
There was a problem hiding this comment.
Good catch, fixed in 1519279.
SQL Server profiles now also return LOWER(source) as key0/key1, and the SDK uses those as chart keys instead of Python's str.lower. Keys therefore come from the same function as SQL grouping and drilldown. SQLite is unchanged: its UnicodeLower already is Python str.lower.
I checked this on Azure SQL. LOWER over the JSON text gives the same result as LOWER over each OPENJSON member (the SQL path) for ΟΣ, İ, DŽ, ẞ and U+1C90, while Python disagrees on 4 of those 5. The one case where the two can differ is a \u-escaped member, because LOWER doesn't decode escapes. The reader falls back to the SQL path when a key contains \u.
Tests: SDK aggregation with the sigma example (keys and labels), misaligned key arrays rejected, escaped keys fall back, and the SQL Server compile asserts the LOWER key columns. Against the production database, all five harm/attack-type charts are still identical to the full SQL path, at 0.4–1.7 s.
Python str.lower differs from SQL Server LOWER (for example final sigma, dotted capital I, and characters newer than the collation's Unicode tables), so compact-profile chart keys could disagree with SQL grouping and drilldown. SQL Server profiles now return LOWER(source) as key0/key1 and the SDK uses those keys. LOWER over serialized JSON cannot fold \u-escaped members, so such probes fall back to the SQL path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Description
Analytics heatmaps on Azure SQL time out for every filter. SQL Server takes 6–9 s just to compile the heatmap (matrix) statement, which exceeds the 5 s report budget. Stored JSON
nullharm categories also makeOPENJSONfail with error 13609. This PR makes harm-category and attack-type charts finish well within the budget.OPENJSONguard: membership expansions on SQL Server pass only arrays toOPENJSON, so a stored JSONnullis classified as missing instead of raising.Measured against a production database (30,767 results, 23,097 with JSON
nullharm categories), with the default 5 s budget and a warm pool:All five outputs are identical to this branch's full SQL path. Attack-type groups are also identical to
main's SQL path;maincan't produce the harm-category charts.Other heatmap axes (for example objective target or model) still use the SQL matrix statement and may still exceed the budget on large SQL Server databases; that is not addressed here. Related: #4648 bounds slow scenario-history reads, a separate problem.