fix(agent): acquire per-session lock in process_direct (#4080)

This commit is contained in:
04cb 2026-05-30 08:10:51 +08:00 committed by Xubin Ren
parent 3dcf511c84
commit e29c9c3906
2 changed files with 11 additions and 7 deletions

View File

@ -1667,7 +1667,10 @@ class AgentLoop:
channel=channel, sender_id="user", chat_id=chat_id, channel=channel, sender_id="user", chat_id=chat_id,
content=content, media=media or [], content=content, media=media or [],
) )
# Share the dispatch lock so direct calls serialize with bus turns.
lock = self._session_locks.setdefault(session_key, asyncio.Lock())
try: try:
async with lock:
return await self._process_message( return await self._process_message(
msg, msg,
session_key=session_key, session_key=session_key,

View File

@ -406,6 +406,7 @@ async def test_process_direct_accepts_media() -> None:
loop = AgentLoop.__new__(AgentLoop) loop = AgentLoop.__new__(AgentLoop)
loop._connect_mcp = AsyncMock() loop._connect_mcp = AsyncMock()
loop._session_locks = {}
captured_msg = None captured_msg = None