fix: await message confirmation interruption

This commit is contained in:
Xin Wang
2026-08-03 17:11:43 +08:00
parent 67389fc5a1
commit c3cb410c17
5 changed files with 48 additions and 9 deletions

View File

@@ -8,7 +8,6 @@ from unittest.mock import AsyncMock, patch
from models import AssistantConfig, RuntimeTool
from pipecat.flows import FlowManager
from pipecat.frames.frames import (
InterruptionFrame,
LLMContextFrame,
LLMFullResponseEndFrame,
LLMFullResponseStartFrame,
@@ -1536,14 +1535,15 @@ class WorkflowBrainTests(unittest.IsolatedAsyncioTestCase):
async def queue_frame(frame):
if isinstance(frame, TTSSpeakFrame):
events.append(("speech", frame.text))
elif isinstance(frame, InterruptionFrame):
events.append("interrupted")
elif (
isinstance(frame, OutputTransportMessageUrgentFrame)
and frame.message.get("event") == "message_completed"
):
events.append("message_completed")
async def interrupt_output():
events.append("interrupted")
class OrderedCallEnd(FakeCallEnd):
def __init__(self):
super().__init__()
@@ -1580,6 +1580,7 @@ class WorkflowBrainTests(unittest.IsolatedAsyncioTestCase):
call_end=call_end,
client_tools=client_tools,
set_input_enabled=input_states.append,
interrupt_output=interrupt_output,
)
brain._message_stages.set_client_tools(client_tools)

View File

@@ -2,7 +2,7 @@ from __future__ import annotations
import unittest
from types import SimpleNamespace
from unittest.mock import patch
from unittest.mock import AsyncMock, patch
from pipecat.frames.frames import (
BotStartedSpeakingFrame,
@@ -10,6 +10,7 @@ from pipecat.frames.frames import (
OutputTransportMessageUrgentFrame,
)
from services.pipecat.pipeline_events import bind_cascade_pipeline_events
from services.pipecat.pipeline import _interrupt_pipeline_output
class _EventSource:
@@ -80,6 +81,25 @@ class _Brain:
class PipelineEventTest(unittest.IsolatedAsyncioTestCase):
async def test_output_interruption_broadcasts_before_flush_barrier(self):
events = []
source = SimpleNamespace(
broadcast_interruption=AsyncMock(
side_effect=lambda: events.append("broadcast")
)
)
worker = SimpleNamespace(
flush_pipeline=AsyncMock(
side_effect=lambda **_kwargs: events.append("flush")
)
)
await _interrupt_pipeline_output(source, worker)
self.assertEqual(events, ["broadcast", "flush"])
source.broadcast_interruption.assert_awaited_once_with()
worker.flush_pipeline.assert_awaited_once_with(timeout=1.0)
async def test_greeting_keeps_playback_timestamp_until_client_ready(self):
transport = _EventSource()
text_input = _EventSource()