Fix realtime disconnect cancellation and response timeouts#225
Closed
andimarafioti wants to merge 1 commit intohuggingface:mainfrom
Closed
Fix realtime disconnect cancellation and response timeouts#225andimarafioti wants to merge 1 commit intohuggingface:mainfrom
andimarafioti wants to merge 1 commit intohuggingface:mainfrom
Conversation
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
SESSION_ENDcontrol messages in the realtime audio send loopWhy
Two failure modes showed up in realtime use:
responses.create(..., stream=True)call could hang for minutes before failing, which meant the robot never answered.PipelineControlMessagebecause it tried to treatSESSION_ENDas audio bytes.This patch makes disconnect behave like a real cancellation boundary and makes the LLM client fail fast enough to recover instead of leaving the session stuck.
Validation
python3 -m py_compile LLM/openai_api_language_model.py api/openai_realtime/websocket_router.py tests/test_openai_api_language_model.py tests/openai_realtime/test_websocket_router.pyuv run ruff check LLM/openai_api_language_model.py api/openai_realtime/websocket_router.py tests/test_openai_api_language_model.py tests/openai_realtime/test_websocket_router.pyuv run pytest -q tests/openai_realtime/test_websocket_router.pyuv run pytest -q tests/test_openai_api_language_model.py -k "streams_text_from_response_events or handles_cancellation or read_timeout or disable_thinking or no_disable_thinking"Note
tests/test_openai_api_language_model.py::test_second_turn_flattens_assistant_history_for_responsesis already failing onupstream/mainfor an unrelated assistant-history formatting issue, so I kept this PR scoped to the realtime cancellation/timeout fixes above.