fix(voice): don't raise when interrupting a cancelled or finished speech - #6767
Merged
Merged
Conversation
SpeechHandle.interrupt() tested allow_interruptions before the state of the handle, so a protected handle raised RuntimeError even after it was interrupted or done. The allow_interruptions setter already refuses to set protection on an interrupted handle, because protection has no meaning in that state. Callers that walk a group of handles then need a special case for handles that can never play. In AgentActivity.interrupt(), a queued protected handle that the caller already cancelled stopped the queue walk, and the interruptible speeches behind it kept playing. session.interrupt(force=True) followed by session.interrupt() no longer raises on a protected current speech.
chenghao-mou
approved these changes
Aug 10, 2026
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.
Problem
SpeechHandle.interrupt()testedallow_interruptionsbefore it tested the state of the handle, so a handle withallow_interruptions=FalseraisedRuntimeErroreven after it was interrupted or done.The
allow_interruptionssetter already refuses to set protection on a handle that is interrupted, because protection has no meaning in that state.interrupt()did not agree with it.Callers that walk a group of handles then need a special case for handles that can never play. In
AgentActivity.interrupt()(added in #6644), a queued protected handle that the caller already cancelled stopped the queue walk. The interruptible speeches behind it kept playing, and the warning named a handle that never plays.Reachable today:
session.say("hold please", allow_interruptions=False)queues behind another speech, and the caller cancels the returned handle withhandle.interrupt(force=True). The handle stays in_speech_quntil the scheduling task drops it. Asession.interrupt()in that window stops at the dead handle.Change
interrupt()returns the handle unchanged when it is interrupted or done, before theallow_interruptionstest.Task.cancel()andFuture.cancel()do the same on work that is finished.AgentActivity.interrupt()needs no change. The walk stops seeing aRuntimeErrorthat it must not see.One behavior change:
session.interrupt(force=True)followed bysession.interrupt()no longer raises on a protected current speech.