feat: expose configurable websocket max_size limit#3645
Open
anneheartrecord wants to merge 1 commit into
Open
Conversation
Both the Responses websocket transport (OpenAIResponsesWebSocketOptions) and the Realtime websocket transport (TransportConfig) hard-coded max_size=None, disabling the websockets library's incoming message-size limit with no way to override it short of forking or monkeypatching. Add an optional max_size field to both option types and pass it through to websockets.connect when set, mirroring the existing ping_interval / ping_timeout knobs. The default behavior is unchanged (no limit) so this is purely opt-in for long-lived agent processes that need to bound per-message memory usage behind proxies or in constrained containers.
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
Both websocket transports hard-coded
max_size=None, which disables thewebsocketslibrary's incoming message-size limit and gives applications no way to bound it without forking or monkeypatching the SDK:OpenAIResponsesWebSocketOptionsonly exposedping_interval/ping_timeout;_open_websocket_connectionpassedmax_size=None.TransportConfig(Realtime) only exposedping_interval/ping_timeout/handshake_timeout;_create_websocket_connectionpassedmax_size=None.This adds an optional
max_size: int | Noneto both option types and passes it through towebsockets.connectwhen set, mirroring the existing keepalive knobs. Long-lived agent processes running behind proxies or in memory-constrained containers can now bound per-message memory, e.g.:The default behavior is unchanged — when
max_sizeis not provided the connection is still opened with no limit, so this is purely opt-in.Test plan
test_websocket_model_passes_max_size_to_connect(Responses) andtest_max_size_config_is_applied(Realtime) verifying the value reacheswebsockets.connect.test_websocket_model_open_websocket_connection_disables_message_size_limit(asserting the default staysNone) still passes.make lint,make format,mypyandpyrighton the changed modules, and the fulltests/models/test_openai_responses.py+tests/realtime/test_openai_realtime.pysuites (181 passed) are green. Docs build succeeds.Issue number
Closes #3644
Checks
make lintandmake format