fix(gateway): use source.thread_id instead of undefined event in queued response

In _run_agent(), the pending message handler references 'event' which
is not defined in that scope — it only exists in the caller. This
causes a NameError when sending the first response before processing a
queued follow-up message.

Replace getattr(event, 'metadata', None) with the established pattern
using source.thread_id, consistent with lines 2625, 2810, 3678, 4410, 4566
in the same file.
This commit is contained in:
willy-scr 2026-04-12 04:36:31 +08:00 committed by Teknium
parent f2893fe51a
commit ef73babea1

View file

@ -8131,7 +8131,7 @@ class GatewayRunner:
if first_response and not _already_streamed:
try:
await adapter.send(source.chat_id, first_response,
metadata=getattr(event, "metadata", None))
metadata={"thread_id": source.thread_id} if source.thread_id else None)
except Exception as e:
logger.warning("Failed to send first response before queued message: %s", e)
# else: interrupted — discard the interrupted response ("Operation