Repository navigation
FIX: Deliver scenario progress results that commit behind the cursor - #4796
Open
Richard Lundeen (richlundeen) wants to merge 1 commit into
Open
Richard Lundeen (richlundeen) wants to merge 1 commit into
Richard Lundeen (richlundeen) wants to merge 1 commit into
Conversation
AttackResult.timestamp records creation, so a concurrent attack can commit a row ordered before a progress keyset cursor that already passed it. The read model and client cursors then skipped that result forever, so a completed run could report fewer results than it stored. - Memory: add get_scenario_attack_result_count_async, counting run rows at or before a keyset cursor with the same order as the delta query. - Read model: after hydrating, compare the stored count through the cache cursor with the cached deltas and rebuild the entry on mismatch. - Progress API: version 2 cursors record how many results the client holds through the bookmark. When storage holds more (or for version 1 cursors), the page restarts from the first result with the plan and reset: true. - Frontend: a reset page replaces held results, including a terminal page. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
A critical cursor-validation flaw allows a timestamp edit to mask a late insertion, permanently skipping a row even after completion.
1 open issue
What changed in this PR
This PR addresses missing scenario results when concurrent attacks commit behind the progress cursor, coordinating storage checks, API resets, and frontend state replacement.
Changes:
- Detect missed results and rebuild the progress cache.
- Add versioned cursors with result counts and reset responses.
- Handle resets in the frontend and add regression coverage.
| File | Description |
|---|---|
| tests/unit/memory/memory_interface/test_interface_scenario_progress.py | Tests cursor-bounded result counts. |
| tests/unit/backend/test_scenario_run_service.py | Tests cursor validation, resets, and late commits. |
| tests/unit/backend/test_scenario_progress_read_model.py | Updates mocks for count checks. |
| tests/unit/backend/mocks.py | Adds a count-aware memory wrapper. |
| pyrit/models/scenario_progress.py | Adds the reset response field. |
| pyrit/memory/memory_interface.py | Adds counts using shared cursor ordering. |
| pyrit/backend/services/scenario_run_service.py | Implements v2 cursors and reset pages. |
| pyrit/backend/services/scenario_progress_read_model.py | Rebuilds caches when stored counts differ. |
| pyrit/backend/README.md | Documents cursor and reset semantics. |
| frontend/src/types/index.ts | Types the reset response field. |
| frontend/src/hooks/useScenarioRunProgress.tsx | Replaces held results on reset. |
| frontend/src/hooks/useScenarioRunProgress.test.tsx | Tests terminal and empty reset pages. |
Review effort: Balanced
| # A result that committed late can sort before the client's bookmark. The client then | ||
| # holds fewer results through that bookmark than storage does, so it must start over. | ||
| # An edited result moves past the bookmark instead and is re-sent on this page. | ||
| reset = cursor is not None and (cursor.seen is None or start > cursor.seen) |
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
Scenario run progress could permanently miss an attack result.
AttackResult.timestampis set when the result is created, but concurrent atomic attacks commit later. A result created earlier can therefore commit after the progress keyset cursor has already passed its(timestamp, id)position. The server's progress read model and the client'ssincecursor never fetched it again. As a result, a COMPLETED run could report fewer results than it stored. This was seen in CI asfrontend/e2e/scenario-techniques.spec.tsreturning 2 of 3 results after completion.get_scenario_attack_result_count_async(scenario_result_id, through=...). It counts the run's results at or before a cursor and uses the same ordering condition as the delta query.reset: true.useScenarioRunProgressreplaces held results when a page hasreset: true, including a terminal page, before it stops polling.pyrit/backend/README.md, and add regression tests: a SQLite late-commit test, cursor reset and decoding tests, a memory count test, and hook reset tests.