From ef73babea1c3460e75ccb469c88ab54314ea4565 Mon Sep 17 00:00:00 2001 From: willy-scr <187001140+willy-scr@users.noreply.github.com> Date: Sun, 12 Apr 2026 04:36:31 +0800 Subject: [PATCH] fix(gateway): use source.thread_id instead of undefined event in queued response MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- gateway/run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gateway/run.py b/gateway/run.py index 469abe9ec..9b1e5c275 100644 --- a/gateway/run.py +++ b/gateway/run.py @@ -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