[Core][Frontend] Bound duplex output delivery and reject cancelled audio (#7644)

Signed-off-by: Nolen Liang <nliang@nvidia.com>
Signed-off-by: bcsdhjew <nliang@nvidia.com>
This commit is contained in:
bcsdhjew authored and GitHub committed 2026-10-04 14:06:04 -07:00
1 parent 3f20252151
commit f781f7bb08
26 files changed
+1170 -147

No files matched your search

+8 -4
View File
@@ -22,6 +22,7 @@ import json
from collections.abc import Mapping
from contextlib import suppress
from dataclasses import dataclass, replace
from functools import partial
from fastapi import WebSocket, WebSocketDisconnect
from vllm.logger import init_logger
@@ -478,7 +479,7 @@ class OmniDuplexSessionHandler:
attachment_generation=credentials.attachment_generation,
resume_token=credentials.resume_token,
)
await self._send_event(session_id, event)
await self._send_event(session_id, event, handle=handle)
if isinstance(event, SessionClosed):
close_reason = event.reason or event.type
break
@@ -523,19 +524,22 @@ class OmniDuplexSessionHandler:
with suppress(Exception):
await asyncio.wait_for(asyncio.shield(pump), _PUMP_DRAIN_TIMEOUT_S)
async def _send_event(self, session_id: str, event: DuplexEvent) -> None:
async def _send_event(self, session_id: str, event: DuplexEvent, *, handle: DuplexSessionHandle) -> None:
payload = event.to_realtime()
journal = not isinstance(event, _UNJOURNALED_EVENTS) and session_id not in self._resync_required_sessions
event_guard = partial(handle.output_guard, event)
try:
try:
await self._attachment_registry.send_event(session_id, payload, journal=journal)
await self._attachment_registry.send_event(
session_id, payload, journal=journal, event_guard=event_guard
)
except DuplexJournalOverflowError:
first_overflow = session_id not in self._resync_required_sessions
self._resync_required_sessions.add(session_id)
if first_overflow:
resync = SessionResyncRequired(session_id=session_id, reason="journal_overflow")
await self._attachment_registry.send_event(session_id, resync.to_realtime(), journal=False)
await self._attachment_registry.send_event(session_id, payload, journal=False)
await self._attachment_registry.send_event(session_id, payload, journal=False, event_guard=event_guard)
except KeyError:
# Attachment already closed (takeover or teardown); the journal is gone.
pass
@@ -11,6 +11,7 @@ import secrets
import time
from collections import deque
from collections.abc import Awaitable, Callable, Mapping
from contextlib import AbstractContextManager, nullcontext
from dataclasses import dataclass, field
from types import MappingProxyType
@@ -291,6 +292,7 @@ class DuplexSessionAttachmentRegistry:
*,
journal: bool = True,
on_accepted: Callable[[], None] | None = None,
event_guard: Callable[[], AbstractContextManager[bool]] | None = None,
) -> JournalEntry | None:
"""Sequence and dispatch one event to the current attachment.
@@ -309,9 +311,15 @@ class DuplexSessionAttachmentRegistry:
async with self._lock:
if self._sessions.get(session_id) is not state:
raise KeyError(f"unknown duplex attachment session: {session_id}")
entry = state.journal.record(payload) if journal else None
attachment = state.attachment
wire_payload = dict(entry.payload) if entry is not None else dict(payload)
# The producer may invalidate held audio while this coroutine
# waits for an attachment lock. Commit order before sequencing;
# release the cross-thread guard before awaiting network I/O.
with event_guard() if event_guard is not None else nullcontext(True) as valid:
if not valid:
return None
entry = state.journal.record(payload) if journal else None
attachment = state.attachment
wire_payload = dict(entry.payload) if entry is not None else dict(payload)
if entry is not None and on_accepted is not None:
on_accepted()
if attachment is not None: