fix(voice): don't hold session.run() open on update_agent handoffs with long-lived on_enter#6500
Merged
Merged
Conversation
k-zaher
marked this pull request as ready for review
July 21, 2026 17:21
k-zaher
force-pushed
the
fix/update-agent-run-deadlock
branch
from
July 21, 2026 17:22
001149e to
f8ca38b
Compare
k-zaher
force-pushed
the
fix/update-agent-run-deadlock
branch
from
July 21, 2026 17:22
f8ca38b to
ff44fab
Compare
|
|
longcw
reviewed
Jul 22, 2026
longcw
approved these changes
Jul 23, 2026
Contributor
|
thanks for the pr! could sign the CLA before we can merge |
Contributor
Author
|
I have signed the CLA but the bot is not picking up the updated status for some reason |
k-zaher
force-pushed
the
fix/update-agent-run-deadlock
branch
from
July 23, 2026 10:27
7e969f9 to
0c0ee8e
Compare
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.
What
session.run()deadlocks when a function tool callssession.update_agent(new_agent)and the new agent'son_enterawaits anAgentTask(orTaskGroup) that needs a future user turn to complete.The chain:
update_agent()→_update_activity_task(watched by the activeRunResultso the handoff result lands before run completion) →_update_activity(agent)with the defaultwait_on_enter=True→ awaits the new agent'son_enter→ which awaits anAgentTaskthat needs the next user turn. But the driver can't send the next turn untilrun()returns — a circular wait. The run hangs until an external timeout cancels everything (surfacing asToolError: AgentTask ... is cancelled).Both other activity-transition paths already guard against exactly this:
session.start()passeswait_on_enter=False(agent_session.py:916), which is why theexamples/surveypattern (agenton_enterawaiting a wholeTaskGroup) works when the agent is the starting agent.AgentTask.__await_implpasseswait_on_enter=Falsewith a comment describing this exact deadlock: "on_enter may spawn nested AgentTasks that require user input, but session.run() can't return until all watched handles complete — creating a circular wait."update_agent()was the only path still waiting. Entering the same agent that works viasession.start()through anupdate_agent()handoff deadlocks — reproduced on 1.6.4, 1.6.5, and 1.6.6.Fix
Pass
wait_on_enter=Falsein_update_activity_task, matching the other two paths.Test
tests/test_update_agent_long_on_enter.py— FakeLLM-scripted: a greeter tool callsupdate_agent()into an agent whoseon_enterawaits anAgentTaskneeding another user turn; assertsrun()returns on the handoff turn and the task completes on the following turn. Deadlocks (times out) without the fix; passes with it.Validation:
tests/test_agent_session.py,test_nested_agent_task.py,test_audio_recognition_handoff.py,test_agent_task_close_race.py,test_drain_timeout.py,test_tool_results_preserved_on_interruption.py,test_user_turn_exceeded.py,test_speech_handle_exception.py,test_agent_update_options.py+ the new test: 116 passed.examples/survey/test_survey_agent.py: 5 passed (live LLM).update_agent()to an agent whoseon_enterdrives a multi-task loop): its full offline suite of ~1000 tests passes against this patch; on current releases every workflow test deadlocks.