fix: harden realtime pipeline lifecycle
This commit is contained in:
@@ -103,7 +103,7 @@ from services.realtime.protocol import (
|
||||
PipelineProtocolRuntime,
|
||||
RealtimeProviderControlFrame,
|
||||
)
|
||||
from pipecat.workers.runner import WorkerRunner
|
||||
from services.pipecat.pipeline_runner import run_media_worker
|
||||
|
||||
|
||||
KNOWLEDGE_TOOL_NAME = "search_knowledge_base"
|
||||
@@ -260,6 +260,7 @@ async def run_pipeline(
|
||||
assistant_id=assistant_id,
|
||||
channel=channel,
|
||||
protocol_adapter=protocol_adapter,
|
||||
client_tool_names=client_tool_names,
|
||||
)
|
||||
return
|
||||
|
||||
@@ -987,25 +988,7 @@ async def run_pipeline(
|
||||
submit_user_input=submit_user_input,
|
||||
client_tools=client_tools,
|
||||
)
|
||||
runner = WorkerRunner(handle_sigint=False)
|
||||
run_status = "completed"
|
||||
can_finalize_recorder = True
|
||||
try:
|
||||
await runner.add_workers(worker)
|
||||
await runner.run()
|
||||
except GeneratorExit:
|
||||
# A coroutine being synchronously closed cannot perform async cleanup.
|
||||
# The WebRTC route now prevents this by retaining every pipeline task;
|
||||
# keep this guard so a future unmanaged caller cannot corrupt asyncpg.
|
||||
run_status = "failed"
|
||||
can_finalize_recorder = False
|
||||
raise
|
||||
except Exception:
|
||||
run_status = "failed"
|
||||
raise
|
||||
finally:
|
||||
if recorder and can_finalize_recorder:
|
||||
await recorder.finish(status=run_status)
|
||||
await run_media_worker(worker, recorder)
|
||||
logger.info("管线已结束")
|
||||
|
||||
|
||||
@@ -1018,6 +1001,7 @@ async def run_realtime_pipeline(
|
||||
assistant_id: str | None = None,
|
||||
channel: str = "webrtc",
|
||||
protocol_adapter: PipelineProtocolAdapter | None = None,
|
||||
client_tool_names: set[str] | None = None,
|
||||
) -> None:
|
||||
"""Run a speech-to-speech model that owns ASR, reasoning, and synthesis."""
|
||||
realtime = create_realtime_service(
|
||||
@@ -1239,20 +1223,5 @@ async def run_realtime_pipeline(
|
||||
vision_enabled=vision_enabled,
|
||||
vision_state=vision_state,
|
||||
)
|
||||
runner = WorkerRunner(handle_sigint=False)
|
||||
run_status = "completed"
|
||||
can_finalize_recorder = True
|
||||
try:
|
||||
await runner.add_workers(worker)
|
||||
await runner.run()
|
||||
except GeneratorExit:
|
||||
run_status = "failed"
|
||||
can_finalize_recorder = False
|
||||
raise
|
||||
except Exception:
|
||||
run_status = "failed"
|
||||
raise
|
||||
finally:
|
||||
if recorder and can_finalize_recorder:
|
||||
await recorder.finish(status=run_status)
|
||||
await run_media_worker(worker, recorder)
|
||||
logger.info("Realtime 管线已结束")
|
||||
|
||||
Reference in New Issue
Block a user