fix: surface server capacity error through connect()#47
Merged
AdirAmsalem merged 1 commit intomainfrom Apr 20, 2026
Merged
Conversation
When the server rejects a connection at capacity, it sends a structured error message and then closes the WebSocket. The receive loop's finally block was overwriting the specific error with a generic "WebSocket disconnected" before the awaiting caller could read it, and subscribe mode had no pending waits to surface the error at all — callers hung until the 5-minute connection timeout. Store the first specific error on the connection and have both the finally block and connect()'s wait loop defer to it, matching the JS SDK's "first reject wins" semantics.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 65cfbc3. Configure here.
2 tasks
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.

Summary
When the realtime server rejects a connection because it's at capacity, it sends a structured error message and closes the WebSocket. The Python SDK was swallowing that message and surfacing a generic "WebSocket disconnected" instead — indistinguishable from a real network drop. In subscribe mode, there was no pending operation to deliver the error at all, so callers hung for the full 5-minute connection timeout before seeing any failure.
With this change,
connect()raisesWebRTCError("Server at capacity. Please try again later.")promptly, so callers can distinguish capacity rejection from a network drop and back off / inform the user appropriately. Matches the JS SDK's behavior.Test plan
Note
Low Risk
Small, localized error-propagation change in the realtime WebRTC connection flow, with added unit coverage and no data/auth implications.
Overview
WebRTCConnectionnow tracks a first server-sent connection error (_connection_error) and uses it to failconnect()fast (including subscribe mode) instead of waiting for the full timeout.The WebSocket receive-loop’s cleanup no longer overwrites structured server errors with a generic "WebSocket disconnected"; it resolves pending waits using the preserved server error when present. New unit tests cover the disconnect race and the immediate
connect()failure behavior.Reviewed by Cursor Bugbot for commit 65cfbc3. Bugbot is set up for automated code reviews on this repo. Configure here.