From a5bf1b9bdf0fd1a1aad792f7a08e757e2f67e51d Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 23 Nov 2026 18:24:45 -0500 Subject: [PATCH] fix(pipecat): record separate transcription finalization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit > 🤖 **This text was AI-generated.** Pipecat 1.17 can send the last transcript before confirming its finalization in a separate frame. Turns that ended on that confirmation were missing `eou.end_reason`. Match the confirmation frame by class name so both forms of transcription finalization record the same reason when they end a turn. ``` TranscriptionFrame(finalized=True) -> eou.end_reason = transcription_finalized TranscriptionFinalizedFrame() -> eou.end_reason = transcription_finalized ``` --- py/src/braintrust/integrations/pipecat/patchers.py | 3 ++- .../braintrust/integrations/pipecat/test_pipecat.py | 13 ++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/py/src/braintrust/integrations/pipecat/patchers.py b/py/src/braintrust/integrations/pipecat/patchers.py index 09c7d12f0..e5757de07 100644 --- a/py/src/braintrust/integrations/pipecat/patchers.py +++ b/py/src/braintrust/integrations/pipecat/patchers.py @@ -145,7 +145,8 @@ async def traced_controller_frame(wrapped, instance, args, kwargs): if wait is not None: frame = args[0] if args else kwargs["frame"] wait.observe(frame) - if type(frame).__name__ == "TranscriptionFrame" and frame.finalized: + frame_name = type(frame).__name__ + if frame_name == "TranscriptionFinalizedFrame" or (frame_name == "TranscriptionFrame" and frame.finalized): strategies = stop_strategies(instance) strategy = strategies[0] if len(strategies) == 1 else None if ( diff --git a/py/src/braintrust/integrations/pipecat/test_pipecat.py b/py/src/braintrust/integrations/pipecat/test_pipecat.py index 214d06c81..8824b8f7f 100644 --- a/py/src/braintrust/integrations/pipecat/test_pipecat.py +++ b/py/src/braintrust/integrations/pipecat/test_pipecat.py @@ -1586,6 +1586,7 @@ async def _native_eou_controller(observer, strategies, *, observe_start=True, be "committed", "resumed", "transcript_late", + "finalization_frame", "shutdown", "unassociated", "multiple", @@ -1598,6 +1599,8 @@ async def test_eou_native_controller_lifecycle(memory_logger, tracker_observer, _instrument() frames = _frames() + if mode == "finalization_frame" and not hasattr(frames, "TranscriptionFinalizedFrame"): + pytest.skip("Pipecat does not support a separate transcription finalization frame") Strategies = _import("pipecat.turns.user_turn_strategies.UserTurnStrategies") SpeechTimeout = _import("pipecat.turns.user_stop.SpeechTimeoutUserTurnStopStrategy") options = {} @@ -1638,10 +1641,14 @@ async def on_stopped(*_args): # Multiple transcriptions/evaluations during this pause must not split it. await controller.process_frame(frames.InterimTranscriptionFrame("Hi", "caller", "0")) await controller.process_frame(pause) # Re-evaluate/re-arm this same pause. - if mode in ("transcript_late", "text_late"): + if mode in ("transcript_late", "text_late", "finalization_frame"): await asyncio.sleep(0.06) if mode != "shutdown": - if mode != "audio_only": + if mode == "finalization_frame": + await controller.process_frame(frames.TranscriptionFrame("Hi", "caller", "0")) + assert not stopped.is_set() + await controller.process_frame(frames.TranscriptionFinalizedFrame()) + elif mode != "audio_only": await controller.process_frame(frames.TranscriptionFrame("Hi", "caller", "0", finalized=True)) await asyncio.wait_for(stopped.wait(), 2) else: @@ -1660,7 +1667,7 @@ async def on_stopped(*_args): assert "eou.end_reason" not in final["metadata"] else: assert final["metadata"]["eou.outcome"] == "committed" - if mode == "transcript_late": + if mode in ("transcript_late", "finalization_frame"): assert final["metadata"]["eou.end_reason"] == "transcription_finalized" if mode == "text_late": assert "eou.end_reason" not in final["metadata"]