Skip to content

fix: reconnect to dispatcher DO and flush messages#64

Merged
rpurdel merged 1 commit intomainfrom
rpurdel/reconnect-to-dispatcher-do
Feb 6, 2026
Merged

fix: reconnect to dispatcher DO and flush messages#64
rpurdel merged 1 commit intomainfrom
rpurdel/reconnect-to-dispatcher-do

Conversation

@rpurdel
Copy link

@rpurdel rpurdel commented Feb 6, 2026

Fixes a bug where on dispatcher DO disconnect it will silently drop messages.

  1. Added message queue for transcriptions when dispatcher is disconnected (instead of dropping
    them silently)
  2. Added reconnection logic with exponential backoff (1s → 2s → 4s → ... max 30s):
  • connectToDispatcher() function to connect/reconnect to DO
  • scheduleReconnect() function with exponential backoff
  • flushMessageQueue() to send queued messages after reconnection
  1. Added close/error handlers for dispatcher WebSocket to detect mid-session disconnects and
    trigger reconnection
  2. Added flushBeforeClose() - when client disconnects, attempts to reconnect and flush any
    remaining queued messages using ctx.waitUntil()
  3. Fixed reconnection trigger condition - changed from !dispatcherWs to !dispatcherWs ||
    dispatcherWs.readyState !== WebSocket.READY_STATE_OPEN so reconnection triggers even when
    WebSocket object exists but is CLOSED

@rpurdel rpurdel merged commit 1c0e195 into main Feb 6, 2026
1 check passed
@rpurdel rpurdel deleted the rpurdel/reconnect-to-dispatcher-do branch February 6, 2026 11:29
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.

2 participants