You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cancelling an in-flight target call drops the request from memory and leaves no attack result #3733
Cancellation after target-method entry leaves no persisted prompt or AttackResult, so the attempted execution has no audit trail even though the call began.
Steps/Code to Reproduce
Run files/evidence/round5/repro-cancel-missing-audit.py with an in-memory target that signals method entry and then blocks. Cancel the task after entry; inspect stored conversation and attack results.
Additional reproduction details
Define a PromptTarget whose _send_prompt_to_target_async sets an asyncio.Event and then awaits an unset event; run PromptSendingAttack.execute_async(objective='cancellation audit probe') as a task, wait for the event, cancel, catch CancelledError, and query memory. The minimal target behavior is self.entered.set(); await asyncio.Event().wait(). Captured state: target_method_invoked=true, cancellation_propagated=true, conversation_row_exists=true, persisted_message_count=0, persisted_attack_result_count=0. This proves method entry only, not remote delivery. The recovery script uses in-memory SQLite and no network.
Expected Results
Retain at least the submitted request and an explicit cancelled/unknown execution marker, then propagate asyncio.CancelledError. Do not fabricate a response or success/failure.
Actual Results
The target method was entered and cancellation propagated, but the conversation row had zero persisted messages and no AttackResult. A subsequent attack succeeded, confirming memory remained usable. This proves target-method entry, not that an external service received the request.
Proposed fix/regression: persist cancellation/unknown state when target invocation has started before re-raising; test cancellation before, during, and after invocation and ensure persistence failure does not mask cancellation.
Screenshots
Not applicable; persisted state is the evidence.
Versions
Tested commit d3446e0, PyRIT 1.2.0.dev0, offline in-memory scope. Evidence: files/evidence/round5/repro-cancel-missing-audit.py and cancel-missing-audit.json; local paths are not attachments.
Reproduced on main (f3a88daf) with in-memory SQLite. A MockPromptTarget subclass whose _send_prompt_to_target_async sets an event and then blocks drives PromptSendingAttack.execute_async(objective="cancellation audit probe") as a task. After the target is entered, I cancel the task. CancelledError propagates, but memory holds 0 message pieces and 0 attack results.
There are two separate gaps:
No request is persisted.PromptNormalizer.send_prompt_async persists the request after the target returns, or in its except Exception branch. CancelledError is a BaseException, so it skips both.
No AttackResult is persisted.Strategy.execute_with_context_async only routes Exception to ON_ERROR. That handler is what builds the error AttackResult.
Planned fix:
Normalizer. On asyncio.CancelledError from target.send_prompt_async, persist the converted request, then re-raise. The rule for whether the target may have been invoked is the same as the Exception branch's: a send_context that never reached the target persists nothing. No response piece is fabricated. If the write fails, that's logged and never replaces the cancellation.
Attack. In AttackStrategy.execute_with_context_async, a CancelledError raised after the attack started sending to the objective target persists an AttackResult and then re-raises. _ObjectiveTargetConversationLifecycle already records those invocations. The result has outcome UNDETERMINED (not success, failure or error), the same conversation and related conversations as an error result, and a typed cancellation marker in metadata, modelled on AttackPreparationFailure. Cancellation before any objective-target send records nothing. A failed result write is logged and doesn't mask the cancellation.
Scenario resume._get_completed_objective_hashes_async currently counts every non-ERROR row as completed, including UNDETERMINED. Without a change there, a resumed scenario would skip objectives that were cancelled mid-flight. Rows carrying the cancellation marker would stay pending, like ERROR rows.
Tests. Cancellation before the target call, during it and after it (target returned, cancelled while scoring). Persistence failure in the normalizer and in the result write does not mask CancelledError. A resumed scenario re-runs a cancelled objective.
Scope update: #3796 is merged and fixes the first half — on cancellation after target entry, PromptNormalizer now persists the request before re-raising, with tests. What remains is the attack-result half: AttackStrategy.execute_with_context_async still routes only Exception to error-result persistence, so a cancelled attack leaves no AttackResult and no cancellation marker, and scenario resume has nothing to re-run. This issue now tracks that remaining piece: persist an UNDETERMINED result with a typed cancellation marker when the objective target was invoked, re-raise without masking, and make resume treat those rows as pending. See the plan in the first comment for details.
Thanks for the scope update. I'll take the remaining half: persist an UNDETERMINED result with a typed cancellation marker once the objective target was invoked, re-raise the cancellation unchanged, and have scenario resume treat those rows as pending, with tests for each.
I have the attack and resume parts working locally: a cancellation after the objective target was invoked persists an UNDETERMINED result with an AttackCancellation marker, and _get_completed_objective_hashes_by_attack_async keeps those objectives pending.
One question before I open the PR. Seven scenario and backend tests change, because scenario progress and ScenarioResult.attack_results count the cancelled row like any other UNDETERMINED result. For example, a cancelled objective shows as completed=1 of 2 in progress while resume re-runs it. Preparation failures already behave this way in progress. Should progress and attack_results leave out AttackCancellation rows (they would stay in memory for audit), or count them like other UNDETERMINED rows, with those tests updated to match?
Also relevant: test_cancelled_target_call_keeps_the_request_without_a_response in test_prompt_sending.py asserts there is no attack result, with the comment "Interrupted attempts are recorded as scenario provenance, not as attack results." If that provenance is the intended record for interrupted attempts, is the cancellation AttackResult still wanted, or should this issue be closed as covered?
Thanks for stopping to ask. Both questions point at the same conflict, and it's in my scope update, not in your work.
Please don't open the PR as built. A cancelled attempt should not get an AttackResult.
#3643 already settled how interrupted attempts are recorded, and #3796 kept to it: no result row, counts and denominators unchanged, the conversation reachable through the run's recorded conversations, and resume re-runs the objective because it has no completed row. test_cancelled_provenance_preserves_mixed_outcome_denominators_and_resume_async pins all of that. My 2026-11-18 update asked for an UNDETERMINED row on the premise that resume had nothing to re-run. That premise was wrong, so I'm withdrawing that part of the scope.
The underlying reason: UNDETERMINED means the attempt finished and no verdict was reachable, so resume treats it as done. A cancelled attempt didn't finish, and resume has to treat it as pending. Putting both under one outcome with a metadata marker means every consumer must read metadata to tell them apart, and today only resume would.
1. Progress and attack_results: neither. Counting the row shows completed=1 of 2 for an objective that resume will re-run, lowers the all-outcome success rate, and adds a retry once it's resumed. Leaving it out would put the marker check into analytics, the SQL aggregates and the ScenarioResult loader. With no row there is nothing to count or filter, and the seven tests stay as they are. You're right that preparation failures already have this mismatch in progress. That's a separate question and not one to extend here.
2. The existing test: keep test_cancelled_target_call_keeps_the_request_without_a_response and its == [] assertion. The comment is misleading, because that test runs a standalone attack with no scenario. Please reword it along the lines of: "A cancelled attempt has no result, because no outcome was reached. Inside a scenario the conversation stays reachable through the run's recorded conversations."
That also answers your question from #3796: for a standalone execute_async, the saved request and its conversation are the record, and that's enough for now.
What's left for this issue is a small PR, if you're up for it:
the comment fix above;
the tests from your branch that still hold without the result row: cancelled before the target call, during it, and after the target returned while scoring, each asserting what is saved and that no result is written;
a sentence or two in the resiliency section of doc/code/scenarios/0_scenarios.py: a cancelled attempt keeps its request and conversation, leaves no AttackResult, and resume runs it again.
Activity
adimalkar commentedon Nov 1, 2026
I would like to take this.
Reproduced on
main(f3a88daf) with in-memory SQLite. AMockPromptTargetsubclass whose_send_prompt_to_target_asyncsets an event and then blocks drivesPromptSendingAttack.execute_async(objective="cancellation audit probe")as a task. After the target is entered, I cancel the task.CancelledErrorpropagates, but memory holds 0 message pieces and 0 attack results.There are two separate gaps:
PromptNormalizer.send_prompt_asyncpersists the request after the target returns, or in itsexcept Exceptionbranch.CancelledErroris aBaseException, so it skips both.Strategy.execute_with_context_asynconly routesExceptiontoON_ERROR. That handler is what builds the errorAttackResult.Planned fix:
asyncio.CancelledErrorfromtarget.send_prompt_async, persist the converted request, then re-raise. The rule for whether the target may have been invoked is the same as theExceptionbranch's: asend_contextthat never reached the target persists nothing. No response piece is fabricated. If the write fails, that's logged and never replaces the cancellation.AttackStrategy.execute_with_context_async, aCancelledErrorraised after the attack started sending to the objective target persists anAttackResultand then re-raises._ObjectiveTargetConversationLifecyclealready records those invocations. The result has outcomeUNDETERMINED(not success, failure or error), the same conversation and related conversations as an error result, and a typed cancellation marker inmetadata, modelled onAttackPreparationFailure. Cancellation before any objective-target send records nothing. A failed result write is logged and doesn't mask the cancellation._get_completed_objective_hashes_asynccurrently counts every non-ERRORrow as completed, includingUNDETERMINED. Without a change there, a resumed scenario would skip objectives that were cancelled mid-flight. Rows carrying the cancellation marker would stay pending, likeERRORrows.CancelledError. A resumed scenario re-runs a cancelled objective.romanlutz commentedon Nov 18, 2026
Scope update: #3796 is merged and fixes the first half — on cancellation after target entry,
PromptNormalizernow persists the request before re-raising, with tests. What remains is the attack-result half:AttackStrategy.execute_with_context_asyncstill routes onlyExceptionto error-result persistence, so a cancelled attack leaves noAttackResultand no cancellation marker, and scenario resume has nothing to re-run. This issue now tracks that remaining piece: persist an UNDETERMINED result with a typed cancellation marker when the objective target was invoked, re-raise without masking, and make resume treat those rows as pending. See the plan in the first comment for details.adimalkar commentedon Nov 18, 2026
Thanks for the scope update. I'll take the remaining half: persist an UNDETERMINED result with a typed cancellation marker once the objective target was invoked, re-raise the cancellation unchanged, and have scenario resume treat those rows as pending, with tests for each.
adimalkar commentedon Nov 21, 2026
I have the attack and resume parts working locally: a cancellation after the objective target was invoked persists an
UNDETERMINEDresult with anAttackCancellationmarker, and_get_completed_objective_hashes_by_attack_asynckeeps those objectives pending.One question before I open the PR. Seven scenario and backend tests change, because scenario progress and
ScenarioResult.attack_resultscount the cancelled row like any otherUNDETERMINEDresult. For example, a cancelled objective shows ascompleted=1of 2 in progress while resume re-runs it. Preparation failures already behave this way in progress. Should progress andattack_resultsleave outAttackCancellationrows (they would stay in memory for audit), or count them like otherUNDETERMINEDrows, with those tests updated to match?adimalkar commentedon Nov 21, 2026
Also relevant:
test_cancelled_target_call_keeps_the_request_without_a_responseintest_prompt_sending.pyasserts there is no attack result, with the comment "Interrupted attempts are recorded as scenario provenance, not as attack results." If that provenance is the intended record for interrupted attempts, is the cancellationAttackResultstill wanted, or should this issue be closed as covered?romanlutz commentedon Nov 21, 2026
Thanks for stopping to ask. Both questions point at the same conflict, and it's in my scope update, not in your work.
Please don't open the PR as built. A cancelled attempt should not get an
AttackResult.#3643 already settled how interrupted attempts are recorded, and #3796 kept to it: no result row, counts and denominators unchanged, the conversation reachable through the run's recorded conversations, and resume re-runs the objective because it has no completed row.
test_cancelled_provenance_preserves_mixed_outcome_denominators_and_resume_asyncpins all of that. My 2026-11-18 update asked for anUNDETERMINEDrow on the premise that resume had nothing to re-run. That premise was wrong, so I'm withdrawing that part of the scope.The underlying reason:
UNDETERMINEDmeans the attempt finished and no verdict was reachable, so resume treats it as done. A cancelled attempt didn't finish, and resume has to treat it as pending. Putting both under one outcome with a metadata marker means every consumer must read metadata to tell them apart, and today only resume would.1. Progress and
attack_results: neither. Counting the row showscompleted=1of 2 for an objective that resume will re-run, lowers the all-outcome success rate, and adds a retry once it's resumed. Leaving it out would put the marker check into analytics, the SQL aggregates and theScenarioResultloader. With no row there is nothing to count or filter, and the seven tests stay as they are. You're right that preparation failures already have this mismatch in progress. That's a separate question and not one to extend here.2. The existing test: keep
test_cancelled_target_call_keeps_the_request_without_a_responseand its== []assertion. The comment is misleading, because that test runs a standalone attack with no scenario. Please reword it along the lines of: "A cancelled attempt has no result, because no outcome was reached. Inside a scenario the conversation stays reachable through the run's recorded conversations."That also answers your question from #3796: for a standalone
execute_async, the saved request and its conversation are the record, and that's enough for now.What's left for this issue is a small PR, if you're up for it:
doc/code/scenarios/0_scenarios.py: a cancelled attempt keeps its request and conversation, leaves noAttackResult, and resume runs it again.I'll close this once that lands.