Skip to content

fix(realtime): cancel the generation when a speech is interrupted - #6962

Merged
longcw merged 1 commit into
mainfrom
longc/rt-interrupt-cancels-generation
Aug 24, 2026
Merged

longcw merged 1 commit into
mainfrom
longc/rt-interrupt-cancels-generation

Conversation

@longcw

@longcw longcw commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem

SpeechHandle.interrupt() marks the handle interrupted and releases wait_for_playout(). It does not stop the model.

Only AgentActivity.interrupt() pairs the local interruption with RealtimeSession.interrupt(), and an AgentTask cannot use it. Its future resolves when every interrupted speech is done, and one of them is the task's own on_enter speech.

So an app that interrupts a handle directly keeps the response alive. The interrupted reply completes a few seconds later.

Fix

The realtime generation task owns the server-side response, so it now sends the cancel where it observes the interrupt. This covers every interrupt path and adds no new API.

The cancel is session-wide, so it must not go out after the provider ended the response. Both streams of the generation are drained through a tee, and the cancel is skipped once they close.

Playout lags generation by seconds, so that guard is load-bearing. Without it, an interrupt on a speech that is still playing buffered audio can stop whichever response took its place.

SpeechHandle.interrupt() marked the handle interrupted and released
wait_for_playout(), but only AgentActivity.interrupt() paired that
with RealtimeSession.interrupt(). An app that interrupts a handle
directly left the model generating server-side, and AgentActivity's
own interrupt deadlocks inside an AgentTask because its future waits
for the task's own speech.

The realtime generation task owns the response, so it now sends the
cancel wherever it observes the interrupt. The cancel is session-wide,
so both streams of the generation are drained through a tee and the
cancel is skipped once the provider ended the response. Playout lags
generation by seconds, so without that guard an interrupt on a speech
that is still playing can stop whichever response took its place.
@longcw
longcw requested a review from a team as a code owner August 24, 2026 06:21

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

@longcw
longcw merged commit c8b8eed into main Aug 24, 2026
27 of 28 checks passed
@longcw
longcw deleted the longc/rt-interrupt-cancels-generation branch August 24, 2026 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants