From 2193a64c8020007609dbf0cf4989eaa19a7b9699 Mon Sep 17 00:00:00 2001 From: chengyongru Date: Mon, 20 Apr 2026 10:56:27 +0800 Subject: [PATCH] fix(agent): align subagent result session key with main agent for mid-turn injection When mid-turn message injection (PR #2985) was introduced, the pending queue routing uses the effective session key to match incoming messages against active sessions. Subagent results, however, use channel="system" which produces a session key of "system:feishu:ou_..." instead of the main agent's "feishu:ou_...", causing the result to bypass the pending queue and be dispatched as a competing independent task. Fix: set session_key_override to the original channel:chat_id so _effective_session_key returns the correct key and the subagent result gets routed into the main agent's pending queue. --- nanobot/agent/subagent.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nanobot/agent/subagent.py b/nanobot/agent/subagent.py index 388a634c7..58daafb63 100644 --- a/nanobot/agent/subagent.py +++ b/nanobot/agent/subagent.py @@ -240,12 +240,16 @@ class SubagentManager: result=result, ) - # Inject as system message to trigger main agent + # Inject as system message to trigger main agent. + # Use session_key_override to align with the main agent's session key + # so the result is routed to the pending queue (mid-turn injection) + # instead of being dispatched as a competing independent task. msg = InboundMessage( channel="system", sender_id="subagent", chat_id=f"{origin['channel']}:{origin['chat_id']}", content=announce_content, + session_key_override=f"{origin['channel']}:{origin['chat_id']}", metadata={ "injected_event": "subagent_result", "subagent_task_id": task_id,