Repository navigation
fix(websocket): report backend failures before closing realtime sessions - #2
Merged
Merged
Conversation
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
force-pushed
the
fix/websocket-error-events
branch
from
October 22, 2026 01:28
9f5410e to
d6f97ef
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by mau
Before: the docs say wrong ordering on
/api/v1/realtime"emits anerrorevent 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 STTsession_startwithoutsample_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
errorevent with a stable code before closing. The codes aresample_rate_requiredplus the same codes the HTTP API uses:invalid_request,overloaded,cancelled,deadline_exceededandengine_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_backendhelper records the backend error on the session state and sends the event, andwebsocket_sessionpicks 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.mdnow documents the close codes.