Repository navigation
FIX: Bound slow scenario-history reads and stop false compatibility dialog - #4648
Open
Behnam (behnam-o) wants to merge 1 commit into
Open
Behnam (behnam-o) wants to merge 1 commit into
Behnam (behnam-o) wants to merge 1 commit into
Conversation
…ialog Long scenario-history reads kept running after the proxy abandoned the request, piled up on every frontend refresh, exhausted the connection pool, and starved the default executor. The /api/version handshake then timed out and the GUI showed a misleading "deploy matching builds" dialog. - AzureSQLMemory: set a pyodbc query timeout on async-engine connections so the driver cancels long statements server-side and frees the connection. Cancelling the asyncio task does not interrupt the ODBC call. Configurable via query_timeout_seconds / AZURE_SQL_DB_QUERY_TIMEOUT_SECONDS (default 300, 0 disables); schema migrations are not limited. - /api/version: read build info once in the app lifespan instead of on the default executor per request. - useAutoRefresh: optional exponential backoff (up to 16 intervals) while a view's last read failed; used by Scanner History and Home, which both call GET /api/scenarios/runs. - Scanner History: queue changes wait for the in-flight read instead of starting a parallel one, and do not bypass the backoff after a failure. - Compatibility gate: a failed or timed-out version check (now 30 s) shows "PyRIT backend unavailable" instead of build-mismatch guidance. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Nov 25, 2026
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Retry backoff can carry over between outages and increase during pending background reads, so counter reset and scheduling fixes with regression coverage are still needed.
3 open issues
What changed in this PR
This PR limits the impact of slow scenario-history reads on PyRIT’s GUI and distinguishes backend unavailability from build incompatibility. It complements the query improvements in #4649 and #4650 without changing the history query itself.
Changes:
- Adds a configurable Azure SQL statement timeout, excluding schema migrations.
- Caches build metadata at startup and gives failed version checks separate unavailable messaging with a 30-second request timeout.
- Adds refresh backoff and defers queue-triggered history reloads while a read is pending.
| File | Description |
|---|---|
tests/unit/memory/test_azure_sql_memory.py |
Tests timeout configuration, validation, and connection assignment. |
tests/unit/backend/test_main.py |
Verifies build metadata is cached during startup. |
tests/unit/backend/test_api_routes.py |
Tests cached version responses and metadata fallbacks. |
pyrit/memory/azure_sql_memory.py |
Configures driver-level timeouts for async statements. |
pyrit/backend/routes/version.py |
Serves cached metadata without per-request disk reads. |
pyrit/backend/main.py |
Loads build metadata during application startup. |
frontend/src/services/compatibility.ts |
Separates unavailable checks from compatibility mismatches. |
frontend/src/services/compatibility.test.ts |
Tests unavailable status and request blocking. |
frontend/src/services/api.ts |
Sets the version request timeout to 30 seconds. |
frontend/src/services/api.test.ts |
Verifies the version request timeout configuration. |
frontend/src/hooks/useAutoRefresh.ts |
Adds capped exponential refresh backoff. |
frontend/src/hooks/useAutoRefresh.test.tsx |
Tests backoff, recovery, and visibility timing. |
frontend/src/components/Home/Home.tsx |
Passes source failures into refresh scheduling. |
frontend/src/components/Home/Home.test.tsx |
Tests refresh backoff after source failures. |
frontend/src/components/History/ScenarioHistory.tsx |
Defers queue reloads and enables failure backoff. |
frontend/src/components/History/ScenarioHistory.test.tsx |
Tests deferred reloads and failure backoff. |
frontend/src/components/CompatibilityGate.tsx |
Displays distinct backend-unavailable guidance. |
frontend/src/components/CompatibilityGate.test.tsx |
Tests timeout messaging and blocked business requests. |
doc/code/memory/0_memory.md |
Documents statement timeout behavior and migration exclusion. |
.env_example |
Shows the optional Azure SQL timeout setting. |
Review effort: Balanced
| reloadCurrentPage() | ||
| } | ||
| }, validReference && !displayLoading) | ||
| }, validReference && !displayLoading, error !== null) |
| const onRefresh = useEffectEvent(refresh) | ||
| const isFailing = useEffectEvent((): boolean => failing) | ||
| const running = useRef(false) | ||
| const failedRetries = useRef(0) |
Comment on lines
+39
to
+41
| <h1 id="compatibility-notice-title"> | ||
| {snapshot.status === 'unavailable' ? 'PyRIT backend unavailable' : 'PyRIT compatibility blocked'} | ||
| </h1> |
This branch has not been deployed
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.


Description
One slow scenario-history read can take down the whole GUI. The query keeps running after the client gives up, each auto-refresh starts another one until the DB connection pool is exhausted, and
/api/versionthen times out, so users see a misleading "deploy matching builds" dialog. This PR puts a limit on slow reads and fixes the misleading message. It doesn't change the history query itself.query_timeout_seconds/AZURE_SQL_DB_QUERY_TIMEOUT_SECONDS, or use0to disable it. Schema migrations aren't limited./api/version: reads build info once at startup, so it no longer waits behind database calls on the default executor.Related: #4649 and #4650 fix the slow query itself. This PR stands on its own and limits the damage from any slow read.