Skip to content

fix(websocket): report backend failures before closing realtime sessions - #2

Merged
autoantohaki merged 1 commit into
mainfrom
fix/websocket-error-events
Oct 22, 2026
Merged

autoantohaki merged 1 commit into
mainfrom
fix/websocket-error-events

Conversation

@autoantohaki

Copy link
Copy Markdown
Member

Requested by mau

Before: the docs say wrong ordering on /api/v1/realtime "emits an error event and closes the session", but several failure paths sent no error event at all and closed with a generic 1002 protocol error. These were an STT session_start without sample_rate, an unsupported sample rate, the STT engine being at capacity, failures while pushing audio or committing, and a failed speech synthesis. A client couldn't tell "you sent bad input" from "the server is busy, try again" or "the engine crashed".

After: every one of those paths sends an error event with a stable code before closing. The codes are sample_rate_required plus the same codes the HTTP API uses: invalid_request, overloaded, cancelled, deadline_exceeded and engine_error. The close code matches the failure: 1013 (try again later) for overload, 1011 for engine failures, 1008 for deadline expiry, and 1002 for everything else.

How: a small fail_backend helper records the backend error on the session state and sends the event, and websocket_session picks the close code from the recorded error. A new test drives the missing-rate, overload and engine-failure cases over a real socket. docs/api.md now documents the close codes.

Several realtime failure paths closed the socket with a bare 1002 and no
error event: a missing STT sample_rate, start_transcription errors
(including overload), audio push and commit errors, and failed speech
synthesis. Emit a stable error code first, as the API docs promise, and
close overload with 1013, engine failures with 1011 and deadline expiry
with 1008.
@autoantohaki
autoantohaki force-pushed the fix/websocket-error-events branch from 9f5410e to d6f97ef Compare October 22, 2026 01:28
@autoantohaki
autoantohaki merged commit f46b676 into main Oct 22, 2026
6 checks passed
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