fix(voice): recover dialogue after abandoned message recordings

This commit is contained in:
stu2not
2026-10-28 12:22:58 +08:00
parent a02e0d5f13
commit 9ebb1a78ec
10 changed files with 622 additions and 85 deletions
@@ -1,6 +1,8 @@
from services.interrupt_handler import interrupt_handler
from services.audio_session import audio_session_manager
from utils.logger import session_logger
from services.device_target_cache import device_target_cache
from services.task_manager import task_manager
async def handle_old_session_cleanup(old_session, session_key):
"""
@@ -21,19 +23,22 @@ async def handle_old_session_cleanup(old_session, session_key):
session_logger.error("unknown", "unknown", f"清理旧会话资源时出错: {e}")
async def cleanup_device_sessions(device_id):
async def cleanup_device_sessions(device_id, websocket=None):
"""
清理设备所有会话
Args:
device_id: 设备ID
"""
await device_target_cache.remove_target(device_id, websocket=websocket, reason="disconnected")
sessions_to_clean = []
for session_key, session in await audio_session_manager.get_all_sessions():
if session_key[0] == device_id:
if session_key[0] == device_id and (websocket is None or session.websocket is websocket):
sessions_to_clean.append((session_key, session))
for session_key, session in sessions_to_clean:
if websocket is not None and session.websocket is not websocket:
continue
if hasattr(session, "set_interrupted"):
session_logger.info(
device_id, session_key[1], "WebSocket连接断开,中断会话"
@@ -44,8 +49,11 @@ async def cleanup_device_sessions(device_id):
await interrupt_handler.set_interrupt_state(session_key, True)
if session.llm_service and hasattr(session.llm_service, "closed"):
session.llm_service.closed = True
await task_manager.cancel_session_tasks(session_key)
for session_key, _ in sessions_to_clean:
for session_key, session in sessions_to_clean:
if websocket is not None and session.websocket is not websocket:
continue
await audio_session_manager.remove_session(session_key)
await interrupt_handler.remove_session(session_key)
session_logger.info(