Skip to content

FIX finish WebSocket conversation cleanup before cancellation - #2428

Merged
Roman Lutz (romanlutz) merged 5 commits into
microsoft:mainfrom
romanlutz:romanlutz-daily-audit-2026-08-19
Aug 22, 2026
Merged

FIX finish WebSocket conversation cleanup before cancellation#2428
Roman Lutz (romanlutz) merged 5 commits into
microsoft:mainfrom
romanlutz:romanlutz-daily-audit-2026-08-19

Conversation

@romanlutz

Copy link
Copy Markdown
Contributor

Description

Per-conversation WebSocket cleanup removed the connection from tracking before awaiting close(). If the cleanup task was cancelled at that point, the socket could remain open with no tracked handle available for later cleanup.

This change aligns cleanup_conversation_async() with the target's existing whole-target cleanup contract: it shields the close operation, waits for it to finish, and then propagates CancelledError.

Tests and Documentation

Added a deterministic unit test that cancels cleanup while close() is blocked and verifies:

  • cleanup remains pending until the close completes
  • the connection is closed exactly once
  • cancellation propagates after close completes
  • no stale conversation entry remains

Validation included 31 focused WebSocket tests, 1,856 attack/scenario/WebSocket tests, Ruff, targeted ty, pre-commit hooks, and git diff --check.

Documentation changes were not applicable. JupyText was not run because no notebook or documentation source changed.

Copilot AI added 2 commits August 19, 2026 01:40
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 5cd848f4-78c8-4b36-83c6-70f07c323896
Comment thread pyrit/prompt_target/websocket_target.py Outdated
Copilot AI added 3 commits August 20, 2026 15:44
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 5cd848f4-78c8-4b36-83c6-70f07c323896
Python 3.10 replaces a task's propagated CancelledError and drops its chained cause. Assert the cross-version contract—the cancellation itself—while retaining coverage that close() fails and completes exactly once.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 5cd848f4-78c8-4b36-83c6-70f07c323896
Continue checking the chained close failure on Python 3.11 and newer while accounting for Python 3.10 replacing the propagated CancelledError.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 5cd848f4-78c8-4b36-83c6-70f07c323896
@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Aug 22, 2026
Merged via the queue into microsoft:main with commit c65d733 Aug 22, 2026
54 checks passed
@romanlutz
Roman Lutz (romanlutz) deleted the romanlutz-daily-audit-2026-08-19 branch August 22, 2026 04:03
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.

3 participants