File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -463,9 +463,7 @@ extension RealtimeTalkRelaySession {
463463 case " audioDone " :
464464 self . finishOutputPlaybackStream ( )
465465 case " clear " :
466- let marks = self . takePendingPlaybackMarks ( )
467- self . stopOutputPlayback ( )
468- self . acknowledgePlaybackMarks ( marks )
466+ self . handleOutputClear ( payload )
469467 case " mark " :
470468 self . handlePlaybackMark ( payload )
471469 case " transcript " :
@@ -508,6 +506,14 @@ extension RealtimeTalkRelaySession {
508506 }
509507 }
510508
509+ private func handleOutputClear ( _ payload : [ String : AnyCodable ] ) {
510+ let turnId = self . nonEmpty ( payload [ " talkEvent " ] ? . dictionaryValue ? [ " turnId " ] ? . stringValue )
511+ guard turnId == nil || turnId == self . activeOutputTurnId else { return }
512+ let marks = self . takePendingPlaybackMarks ( )
513+ self . stopOutputPlayback ( )
514+ self . acknowledgePlaybackMarks ( marks )
515+ }
516+
511517 private func waitForStartupResult (
512518 timeoutSeconds : Int ,
513519 lifecycleGeneration : UInt64 ) async -> StartupWaitResult
Original file line number Diff line number Diff line change @@ -209,11 +209,17 @@ struct RealtimeTalkRelayCancellationResultTests {
209209 await fixture . output ( " turn-b " )
210210 await barrier . release ( )
211211 await waitForRealtimeRelayMainActorCheckpoint ( )
212+ await fixture . session . _test_handleGatewayEvent (
213+ RealtimeTalkRelaySessionTests . clearEvent ( turnId : " turn-a " ) )
212214
213215 #expect ( fixture . session . _test_isOutputPlaying ( ) )
214216 #expect ( fixture . observations . issues . isEmpty )
215217 #expect ( fixture . observations . statuses . isEmpty )
216218 #expect ( await fixture . requests . snapshot ( ) . map ( \. method ) == [ " talk.session.cancelOutput " ] )
219+
220+ await fixture . session . _test_handleGatewayEvent (
221+ RealtimeTalkRelaySessionTests . clearEvent ( turnId : " turn-b " ) )
222+ #expect ( ! fixture . session . _test_isOutputPlaying ( ) )
217223 }
218224
219225 @ Test func `cancellation failure after stop cannot close the retired lifecycle` ( ) async throws {
@@ -613,4 +619,17 @@ struct RealtimeTalkRelaySessionTests {
613619 seq : nil ,
614620 stateversion : nil )
615621 }
622+
623+ fileprivate static func clearEvent ( turnId : String ) -> EventFrame {
624+ EventFrame (
625+ type : " event " ,
626+ event : " talk.event " ,
627+ payload : AnyCodable ( [
628+ " relaySessionId " : " relay-1 " ,
629+ " type " : " clear " ,
630+ " talkEvent " : [ " turnId " : turnId ] ,
631+ ] ) ,
632+ seq : nil ,
633+ stateversion : nil )
634+ }
616635}
You can’t perform that action at this time.
0 commit comments