@@ -46,6 +46,7 @@ import {
4646 adoptRelayProviderToolCallId ,
4747 broadcastRelayTurnStarted ,
4848 broadcastToOwner ,
49+ clearTalkRealtimeRelayOutputGeneration ,
4950 ensureRelayTurn ,
5051 relaySessions ,
5152 type CreateTalkRealtimeRelaySessionParams ,
@@ -214,6 +215,7 @@ export function createTalkRealtimeRelaySession(
214215 const recorded = relay . harness . recordOutputAudio ( audio ) ;
215216 broadcastRelayTurnStarted ( relay , recorded . turn . event ) ;
216217 if ( recorded . outputAudioStarted ) {
218+ relay . outputGeneration += 1 ;
217219 broadcastEvent ( { relaySessionId, type : "audioStarted" } , recorded . outputAudioStarted ) ;
218220 }
219221 broadcastEvent (
@@ -232,13 +234,13 @@ export function createTalkRealtimeRelaySession(
232234 if ( ! relay ) {
233235 return ;
234236 }
235- // Advance the harness flush generation before publishing the provider clear.
236- // This suppresses the barge-in fallback so clients receive one clear only.
237- relay . harness . flushOutput ( ( ) => {
238- broadcastEvent (
239- { relaySessionId , type : "clear" , ... ( reason ? { reason } : { } ) } ,
240- relay . harness . finishOutputAudio ( reason ?? "clear" ) ,
241- ) ;
237+ const generation = relay . pendingProviderClearGeneration ?? relay . outputGeneration ;
238+ relay . pendingProviderClearGeneration = undefined ;
239+ clearTalkRealtimeRelayOutputGeneration ( {
240+ session : relay ,
241+ generation ,
242+ reason : reason ?? "clear" ,
243+ providerReason : reason ,
242244 } ) ;
243245 } ,
244246 sendMark : ( markName ) => {
@@ -592,6 +594,7 @@ export function createTalkRealtimeRelaySession(
592594 pendingWorkingToolResults : new Map ( ) ,
593595 forcedTerminalProviderResults : new Map ( ) ,
594596 toolResultEpoch : 0 ,
597+ outputGeneration : 0 ,
595598 ...( params . cfg ? { voiceConfig : params . cfg } : { } ) ,
596599 voiceSessionCreated : false ,
597600 voiceTranscriptSeq : 0 ,
0 commit comments