Skip to content

The agent that grows with you

fix(gateway): key Telegram forum handoffs on the group slot the adapter replies on

teknium19a41a8be6668
diff --git a/gateway/run_startup.py b/gateway/run_startup.py
index 75e6e440700..a66c17a5487 100644
--- a/gateway/run_startup.py
+++ b/gateway/run_startup.py
@@ -1499,6 +1499,10 @@ class GatewayStartupMixin:
is_thread = bool(new_thread_id) and not is_telegram_private_chat
chat_type = "thread" if is_thread else "dm"
scope_id = None
+ if platform == Platform.TELEGRAM and not is_telegram_private_chat:
+ # The Telegram adapter keys forum-topic replies ``group:<chat>:<topic>`` (never
+ # ``thread``); bind the handoff on the same slot.
+ chat_type = "group"
if platform == Platform.SLACK:
# Slack keys a thread reply on the parent channel's type ("dm" for a D… channel, else
# "group") plus the workspace id — never on a "thread" slot. Mirror the adapter's inbound
diff --git a/tests/gateway/test_handoff_thread_session_key.py b/tests/gateway/test_handoff_thread_session_key.py
index 7f344c9b7f1..f0a0f8e1fca 100644
--- a/tests/gateway/test_handoff_thread_session_key.py
+++ b/tests/gateway/test_handoff_thread_session_key.py
@@ -158,3 +158,13 @@ def test_slack_handoff_without_stored_scope_uses_the_sole_workspace_on_a_cold_ch
adapter._channel_team, adapter._channel_teams, adapter._team_clients = {}, {}, {"T0C2HL96FH6": object()}
_dest, handoff = _handoff_destination(Platform.SLACK, "D0C1HFBMQAX", "1789474088.089709", None, adapter)
assert handoff == _organic_slack_reply_key("D0C1HFBMQAX", "1789474088.089709", "T0C2HL96FH6", "dm")
+
+
+def test_telegram_forum_handoff_key_matches_the_topic_reply_key():
+ """The Telegram adapter keys forum-topic replies ``group:<chat>:<topic>``; the handoff must
+ bind the same slot, not ``thread``."""
+ _dest, handoff = _handoff_destination(Platform.TELEGRAM, "-1001234567", "77", None, SimpleNamespace())
+ assert handoff == build_session_key(SessionSource(
+ platform=Platform.TELEGRAM, chat_id="-1001234567", chat_type="group", user_id="42",
+ thread_id="77"), thread_sessions_per_user=False)
+ assert handoff == "agent:main:telegram:group:-1001234567:77"