[Bugfix][MiniCPM-o] Isolate duplex handoff failures and barge-in (#6170)
Signed-off-by: Sy03 <1370724210@qq.com>
This commit is contained in:
23 files changed
+817
-98
No files matched your search
@@ -18,6 +18,7 @@ from vllm_omni.experimental.fullduplex.openai.commit_policy import (
|
||||
decide_commit_action,
|
||||
)
|
||||
from vllm_omni.experimental.fullduplex.openai.protocol import (
|
||||
DuplexOverlapPolicy,
|
||||
DuplexPlaybackCommitPolicy,
|
||||
DuplexSession,
|
||||
DuplexSessionState,
|
||||
@@ -248,6 +249,9 @@ class DuplexSessionRunnerMixin:
|
||||
await actor.enqueue_event(event)
|
||||
except WebSocketDisconnect:
|
||||
await actor.enqueue_event({"type": "__disconnect__"})
|
||||
except Exception as exc:
|
||||
await emit_event({"type": "error", "error": str(exc), "code": "realtime_input_failed"})
|
||||
await actor.enqueue_event({"type": "__disconnect__"})
|
||||
|
||||
async def next_actor_event() -> dict[str, object]:
|
||||
nonlocal pending_turn_reservations, transport_detached
|
||||
@@ -411,6 +415,8 @@ class DuplexSessionRunnerMixin:
|
||||
)
|
||||
return append_ok
|
||||
except asyncio.CancelledError:
|
||||
if pcm_reservation is not None:
|
||||
pcm_reservation.rollback()
|
||||
raise
|
||||
except Exception as exc:
|
||||
if pcm_reservation is not None:
|
||||
@@ -670,6 +676,9 @@ class DuplexSessionRunnerMixin:
|
||||
if handshake is None:
|
||||
return
|
||||
session = handshake.session
|
||||
if initial_update_error := self._runtime_session_candidate_update_error(session, session.config):
|
||||
await emit_event(initial_update_error)
|
||||
return
|
||||
if handshake.resumed:
|
||||
native = self._serving_runtime_adapter.session_states[session.session_id]
|
||||
actor.tasks = self._session_tasks[session.session_id]
|
||||
@@ -721,6 +730,8 @@ class DuplexSessionRunnerMixin:
|
||||
)
|
||||
if isinstance(open_result, dict):
|
||||
created_payload["runtime_control"] = self._redact_runtime_control_result(open_result)
|
||||
if realtime_protocol is not None:
|
||||
realtime_protocol.commit_realtime_turn_detection_update()
|
||||
await emit_event(created_payload)
|
||||
resume_credential_delivered = session.capabilities.supports_session_resume
|
||||
reader_task = asyncio.create_task(read_event_loop(), name="duplex-session-reader")
|
||||
@@ -903,7 +914,11 @@ class DuplexSessionRunnerMixin:
|
||||
|
||||
if event_type in {"input.cancel", "response.cancel", "barge_in", "output_audio_buffer.clear"}:
|
||||
cancel_reason = (
|
||||
"output_audio_buffer_clear" if event_type == "output_audio_buffer.clear" else "barge_in"
|
||||
"output_audio_buffer_clear"
|
||||
if event_type == "output_audio_buffer.clear"
|
||||
else "client_cancelled"
|
||||
if event_type == "response.cancel"
|
||||
else "barge_in"
|
||||
)
|
||||
cancelled_fence = DuplexFence(
|
||||
session.session_id,
|
||||
@@ -1068,9 +1083,20 @@ class DuplexSessionRunnerMixin:
|
||||
await emit_event(self._barge_in_unsupported_error(session))
|
||||
continue
|
||||
if turn_event == "session.update":
|
||||
realtime_event_id = event.get("realtime_event_id")
|
||||
|
||||
async def emit_update_event(update_event: dict[str, object]) -> None:
|
||||
if isinstance(realtime_event_id, str) and realtime_event_id:
|
||||
update_event = {**update_event, "realtime_event_id": realtime_event_id}
|
||||
await emit_event(update_event)
|
||||
|
||||
def reject_update() -> None:
|
||||
if realtime_protocol is not None:
|
||||
realtime_protocol.reject_realtime_turn_detection_update()
|
||||
|
||||
payload = event.get("payload")
|
||||
if not isinstance(payload, dict):
|
||||
await emit_event(
|
||||
await emit_update_event(
|
||||
{
|
||||
"type": "error",
|
||||
"session_id": session.session_id,
|
||||
@@ -1078,12 +1104,22 @@ class DuplexSessionRunnerMixin:
|
||||
"error": "session.update requires a session payload",
|
||||
}
|
||||
)
|
||||
reject_update()
|
||||
continue
|
||||
if not await wait_for_native_append_tail():
|
||||
await emit_update_event(
|
||||
{
|
||||
"type": "error",
|
||||
"code": "session_update_aborted",
|
||||
"error": "session.update was not applied because the preceding append failed",
|
||||
}
|
||||
)
|
||||
reject_update()
|
||||
continue
|
||||
runtime_update_error = self._runtime_session_update_error(session, payload)
|
||||
if runtime_update_error is not None:
|
||||
await emit_event(runtime_update_error)
|
||||
await emit_update_event(runtime_update_error)
|
||||
reject_update()
|
||||
continue
|
||||
previous_config = session.config
|
||||
candidate_config = deepcopy(previous_config)
|
||||
@@ -1093,14 +1129,16 @@ class DuplexSessionRunnerMixin:
|
||||
finally:
|
||||
session.replace_config(previous_config)
|
||||
if update_error is not None:
|
||||
await emit_event(update_error)
|
||||
await emit_update_event(update_error)
|
||||
reject_update()
|
||||
continue
|
||||
runtime_update_error = self._runtime_session_candidate_update_error(
|
||||
session,
|
||||
candidate_config,
|
||||
)
|
||||
if runtime_update_error is not None:
|
||||
await emit_event(runtime_update_error)
|
||||
await emit_update_event(runtime_update_error)
|
||||
reject_update()
|
||||
continue
|
||||
try:
|
||||
candidate_runtime_config = self._runtime_config_for_session_update(
|
||||
@@ -1108,7 +1146,7 @@ class DuplexSessionRunnerMixin:
|
||||
candidate_config,
|
||||
)
|
||||
except ServingRuntimeConfigError as exc:
|
||||
await emit_event(
|
||||
await emit_update_event(
|
||||
{
|
||||
"type": "error",
|
||||
"session_id": session.session_id,
|
||||
@@ -1116,18 +1154,22 @@ class DuplexSessionRunnerMixin:
|
||||
"error": str(exc),
|
||||
}
|
||||
)
|
||||
reject_update()
|
||||
continue
|
||||
if not await self._signal_runtime_session(
|
||||
session,
|
||||
turn_event,
|
||||
emit_event,
|
||||
emit_update_event,
|
||||
session_config=candidate_config.as_dict(),
|
||||
runtime_config=candidate_runtime_config,
|
||||
):
|
||||
reject_update()
|
||||
continue
|
||||
session.replace_config(candidate_config)
|
||||
session.replace_runtime_config(candidate_runtime_config)
|
||||
await emit_event(
|
||||
if realtime_protocol is not None:
|
||||
realtime_protocol.commit_realtime_turn_detection_update()
|
||||
await emit_update_event(
|
||||
{
|
||||
"type": "session.updated",
|
||||
"session": session.as_public_dict(),
|
||||
@@ -1337,7 +1379,16 @@ class DuplexSessionRunnerMixin:
|
||||
buffer_overlap_audio = True
|
||||
if self._uses_native_input_append(session):
|
||||
mark_pending_silence_superseded()
|
||||
overlap_active = not self._session_auto_responds(session) and native_response_in_progress()
|
||||
overlap_active = native_response_in_progress() and (
|
||||
not self._session_auto_responds(session)
|
||||
or (
|
||||
session.capabilities.supports_barge_in
|
||||
and (
|
||||
session.config.overlap_policy == DuplexOverlapPolicy.BARGE_IN_ON_SPEECH.value
|
||||
or self._event_requests_barge_in(event)
|
||||
)
|
||||
)
|
||||
)
|
||||
if overlap_active:
|
||||
decision = self._overlap_decision(session, event, payload)
|
||||
await self._emit_overlap_decision(emit_event, session, decision)
|
||||
@@ -1378,11 +1429,12 @@ class DuplexSessionRunnerMixin:
|
||||
native.speech_since_commit = False
|
||||
await actor.cancel_append_tasks()
|
||||
had_native_stream = native.data_plane_task is not None
|
||||
cancel_reason = str(decision.get("cancel_reason") or "barge_in")
|
||||
cancelled = await self._cancel_active_response(
|
||||
session,
|
||||
actor.active_response_task,
|
||||
emit_event,
|
||||
reason="barge_in",
|
||||
reason=cancel_reason,
|
||||
)
|
||||
had_native_stream = (
|
||||
await self._cancel_native_data_plane_stream(session) or had_native_stream
|
||||
@@ -1398,7 +1450,7 @@ class DuplexSessionRunnerMixin:
|
||||
"type": "audio.cancelled",
|
||||
"session_id": session.session_id,
|
||||
"response_id": old_response_id,
|
||||
"reason": "barge_in",
|
||||
"reason": cancel_reason,
|
||||
"cancelled_epoch": old_epoch,
|
||||
"epoch": new_epoch,
|
||||
"committed_ms": committed_ms,
|
||||
@@ -1418,7 +1470,7 @@ class DuplexSessionRunnerMixin:
|
||||
"type": "audio.cancelled",
|
||||
"session_id": session.session_id,
|
||||
"response_id": session.last_response_id,
|
||||
"reason": "barge_in",
|
||||
"reason": cancel_reason,
|
||||
"cancelled_epoch": old_epoch,
|
||||
"epoch": new_epoch,
|
||||
"committed_ms": committed_ms,
|
||||
@@ -1950,6 +2002,8 @@ class DuplexSessionRunnerMixin:
|
||||
with suppress(Exception):
|
||||
await emit_event({"type": "error", "error": str(exc), "code": "internal_error"})
|
||||
finally:
|
||||
if realtime_protocol is not None:
|
||||
realtime_protocol.reject_realtime_turn_detection_update()
|
||||
if session is not None:
|
||||
if reader_task is not None and not reader_task.done():
|
||||
reader_task.cancel()
|
||||
|
||||
Reference in new issue
Block a user