Skip to content

fix: resolve pending waits when WebSocket disconnects#38

Merged
AdirAmsalem merged 1 commit intomainfrom
fix/disconnect-during-phase2
Mar 14, 2026
Merged

fix: resolve pending waits when WebSocket disconnects#38
AdirAmsalem merged 1 commit intomainfrom
fix/disconnect-during-phase2

Conversation

@AdirAmsalem
Copy link
Contributor

Summary

  • When the WebSocket disconnects during the pre-handshake initial-state phase (Phase 2), pending asyncio.Event waits now resolve immediately instead of timing out after 30s.
  • Extracted _resolve_pending_waits() from the duplicate logic in _handle_error() and also call it in _receive_messages()'s finally block.

Problem

_handle_error() already had fail-fast resolution for server errors during Phase 2 (added in PR #32), but a WebSocket disconnect only set state to "disconnected" without resolving the pending events. This meant _send_initial_image_and_wait(), _send_initial_prompt_and_wait(), and _send_passthrough_and_wait() would hang for the full 30s timeout on WS close.

Fix

  • Extract the pending-wait resolution into _resolve_pending_waits(error_message).
  • Call it from both _handle_error() (server errors, existing behavior) and _receive_messages() finally (WS disconnect, new behavior).

Tests

All 35 existing tests pass, including the 3 fail-fast tests that exercise the same _resolve_pending_waits codepath.

Extract _resolve_pending_waits() from _handle_error() and also call it
in _receive_messages() finally block so that WS disconnects during the
initial-state phase surface immediately instead of timing out after 30s.
@AdirAmsalem AdirAmsalem changed the title fix: resolve pending Phase-2 waits on WebSocket disconnect fix: resolve pending waits when WebSocket disconnects Mar 14, 2026
@AdirAmsalem AdirAmsalem merged commit 399c502 into main Mar 14, 2026
8 checks passed
@AdirAmsalem AdirAmsalem deleted the fix/disconnect-during-phase2 branch March 14, 2026 21:23
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.

1 participant