Repository navigation
fix(realtime): restart the downlink pump after it crashes - #3732
Merged
qbc2016 merged 1 commit intoNov 12, 2026
Merged
Conversation
The downlink pump runs without any exception guard, so a provider stream error or a handler exception kills the task. _on_downlink_done detects the crash and clears _connected so the next input reconnects, but it leaves the finished task in self._downlink — and connect() only creates a new pump when that reference is None. Every reconnect after a crash therefore succeeds without pumping the new session's events: the agent goes deaf for the rest of its lifetime. Clear the dangling reference in the crash branch so the next connect() starts a fresh pump, and pin the recovery with a regression test that crashes the first session's event stream and asserts the second session is pumped.
2 tasks done
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.
AgentScope Version
2.0.12dev (main @
782bd43)Description
RealtimeAgent's downlink pump (_pump_downlinkinsrc/agentscope/agent/_realtime/_agent.py) runs without any exception guard: if the model's event stream raises (a provider SDK stream error) or_on_model_eventthrows, the exception escapes thewhile Trueand the pump task dies._on_downlink_donedetects the crash and clears_connected/_connected_eventso that, per its docstring, the "next input reconnects" — but it leaves the finished task inself._downlink, andconnect()only creates a new pump when that reference isNone(the only place it is reset isclose()). Every reconnect after a crash therefore succeeds — audio is pushed, the session opens — while nobody pumps the new session's events: the agent goes deaf for the rest of its lifetime, which is exactly the "silently dead session" the callback's docstring says it surfaces instead (#3731).Changes — the crash branch of
_on_downlink_donenow also clears the dangling reference, so the nextconnect()starts a fresh pump:How to test
New case in the existing
RealtimeAgentTest(tests/realtime_agent_test.py), driven by the file'sScriptedModel/FakeTransportfixtures:test_crashed_downlink_pump_is_replaced_on_reconnect— aCrashingSessionModelwhose first session'sevents()raises, whose second session behaves: fails onmain(the reconnect succeeds but the summary is empty — no events are ever pumped from the new session, andagent._downlink.done()is still true), passes with this fix (the second session's reply is delivered and the live pump is back);test_provider_timeout_reconnects_on_next_audio,test_old_downlink_cannot_disconnect_new_session, etc.) are untouched and still pass.python -m pytest tests/realtime_agent_test.py # 44 passed.Fixes #3731
Checklist