fix: relay confirmation interrupts past muted input

This commit is contained in:
Xin Wang
2026-08-04 11:12:34 +08:00
parent da828aca41
commit 775e4058bc
8 changed files with 153 additions and 70 deletions

View File

@@ -8,7 +8,6 @@
import asyncio
import base64
from collections.abc import Awaitable, Callable
from io import BytesIO
from typing import Any
@@ -107,21 +106,6 @@ ON_DEMAND_KNOWLEDGE_SYSTEM_HINT = (
)
async def _wait_for_output_stop(
wait_until_stopped: Callable[[], Awaitable[None]],
*,
timeout_seconds: float = 3.0,
) -> None:
"""Wait for the transport's real stop event after an interruption."""
try:
await asyncio.wait_for(
wait_until_stopped(),
timeout=timeout_seconds,
)
except TimeoutError as exc:
raise RuntimeError("等待客户端语音停止超时") from exc
def _compact_knowledge_metadata(value: str, max_length: int) -> str:
"""Keep tool metadata useful without letting it dominate the model context."""
compact = " ".join(value.split())
@@ -437,6 +421,11 @@ async def run_pipeline(
should_ignore_update=lambda: call_end.ending,
)
client_tools = ClientToolBroker()
# Confirmation nodes mute the user aggregator, which intentionally drops
# InterruptionFrame. Relay confirmation interruptions from the next
# processor instead so LLM, assistant aggregation, TTS, and output all see
# the frame before the workflow continues.
client_tools.set_interrupt_handler(user_turn_router.broadcast_interruption)
vision_capture = VisionCaptureProcessor()
knowledge_retrieval = KnowledgeRetrievalProcessor(
automatic_knowledge_id,
@@ -751,11 +740,6 @@ async def run_pipeline(
current_enable_interrupt = enable_interrupt
current_turn_config = normalized
async def wait_for_output_stopped() -> None:
"""Keep workflow continuation behind the interrupted output."""
if call_end.speaking:
await _wait_for_output_stop(call_end.wait_until_silent)
def set_system_prompt(text: str) -> None:
"""替换上下文里的系统提示(节点切换时整体替换,而非追加)。"""
messages = context.get_messages()
@@ -788,7 +772,6 @@ async def run_pipeline(
set_vision_scope=lambda scope: workflow_vision_scope.update(scope),
vision_function=workflow_vision_function,
set_input_enabled=lambda enabled: input_state.__setitem__("enabled", enabled),
wait_for_output_stopped=wait_for_output_stopped,
apply_turn_config=apply_workflow_turn_config,
flow_global_functions=flow_global_functions,
),
@@ -877,6 +860,7 @@ async def run_pipeline(
vision_enabled=vision_enabled,
vision_state=vision_state,
submit_user_input=submit_user_input,
client_tools=client_tools,
)
runner = WorkerRunner(handle_sigint=False)
run_status = "completed"