Skip to content

fix: surface server capacity error through connect()#47

Merged
AdirAmsalem merged 1 commit intomainfrom
surface-capacity-error
Apr 20, 2026
Merged

fix: surface server capacity error through connect()#47
AdirAmsalem merged 1 commit intomainfrom
surface-capacity-error

Conversation

@AdirAmsalem
Copy link
Copy Markdown
Contributor

@AdirAmsalem AdirAmsalem commented Apr 20, 2026

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() raises WebRTCError("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

  • New unit tests cover the receive-loop race and the subscribe-mode no-pending-waits case
  • Existing realtime unit suite still passes (37/37)

Note

Low Risk
Small, localized error-propagation change in the realtime WebRTC connection flow, with added unit coverage and no data/auth implications.

Overview
WebRTCConnection now tracks a first server-sent connection error (_connection_error) and uses it to fail connect() 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.

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.
@AdirAmsalem AdirAmsalem merged commit 207db2b into main Apr 20, 2026
9 checks passed
@AdirAmsalem AdirAmsalem deleted the surface-capacity-error branch April 20, 2026 10:42
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 65cfbc3. Configure here.

Comment thread decart/realtime/webrtc_connection.py
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