From 4298c6fd9acab69544f4855370b6244735c0b0cb Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Sun, 15 Mar 2026 23:01:57 -0700 Subject: [PATCH] fix: route background process watcher notifications to Telegram forum topics (#1481) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Salvaged from PR #1146 by spanishflu-est1918. Background process progress/completion messages were sent with only chat_id, landing in the general topic instead of the originating forum topic. Thread the thread_id from HERMES_SESSION_THREAD_ID through the watcher payload and pass it as metadata to adapter.send() so Telegram routes notifications to the correct topic. The env var export (HERMES_SESSION_THREAD_ID in _set_session_env / _clear_session_env) already existed on main — this commit adds the missing watcher plumbing. Co-authored-by: spanishflu-est1918 --- gateway/run.py | 7 +++++-- tools/terminal_tool.py | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/gateway/run.py b/gateway/run.py index 7475564d..94c9bfa4 100644 --- a/gateway/run.py +++ b/gateway/run.py @@ -3683,6 +3683,7 @@ class GatewayRunner: session_key = watcher.get("session_key", "") platform_name = watcher.get("platform", "") chat_id = watcher.get("chat_id", "") + thread_id = watcher.get("thread_id", "") notify_mode = self._load_background_notifications_mode() logger.debug("Process watcher started: %s (every %ss, notify=%s)", @@ -3730,7 +3731,8 @@ class GatewayRunner: break if adapter and chat_id: try: - await adapter.send(chat_id, message_text) + send_meta = {"thread_id": thread_id} if thread_id else None + await adapter.send(chat_id, message_text, metadata=send_meta) except Exception as e: logger.error("Watcher delivery error: %s", e) break @@ -3749,7 +3751,8 @@ class GatewayRunner: break if adapter and chat_id: try: - await adapter.send(chat_id, message_text) + send_meta = {"thread_id": thread_id} if thread_id else None + await adapter.send(chat_id, message_text, metadata=send_meta) except Exception as e: logger.error("Watcher delivery error: %s", e) diff --git a/tools/terminal_tool.py b/tools/terminal_tool.py index 27c405de..fc22bf3f 100644 --- a/tools/terminal_tool.py +++ b/tools/terminal_tool.py @@ -1066,6 +1066,7 @@ def terminal_tool( "session_key": session_key, "platform": os.getenv("HERMES_SESSION_PLATFORM", ""), "chat_id": os.getenv("HERMES_SESSION_CHAT_ID", ""), + "thread_id": os.getenv("HERMES_SESSION_THREAD_ID", ""), }) return json.dumps(result_data, ensure_ascii=False)