mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-06-13 14:23:58 +00:00
fix(agent): acquire per-session lock in process_direct (#4080)
This commit is contained in:
parent
3dcf511c84
commit
e29c9c3906
@ -1667,14 +1667,17 @@ 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:
|
||||||
return await self._process_message(
|
async with lock:
|
||||||
msg,
|
return await self._process_message(
|
||||||
session_key=session_key,
|
msg,
|
||||||
on_progress=on_progress,
|
session_key=session_key,
|
||||||
on_stream=on_stream,
|
on_progress=on_progress,
|
||||||
on_stream_end=on_stream_end,
|
on_stream=on_stream,
|
||||||
)
|
on_stream_end=on_stream_end,
|
||||||
|
)
|
||||||
finally:
|
finally:
|
||||||
if channel == "websocket":
|
if channel == "websocket":
|
||||||
await self._webui_turns.publish_run_status(msg, "idle")
|
await self._webui_turns.publish_run_status(msg, "idle")
|
||||||
|
|||||||
@ -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
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user