The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cron): seed Telegram forum-topic cron threads on the group slot topic replies key
teknium13c9431a87657
diff --git a/cron/scheduler_delivery.py b/cron/scheduler_delivery.pyindex 5f096340497..dee1741b225 100644--- a/cron/scheduler_delivery.py+++ b/cron/scheduler_delivery.py@@ -211,9 +211,10 @@ def _maybe_mirror_cron_delivery(# chat_type slot a platform's adapter puts on a NON-DM in-thread reply. Discord (and the default)-# key the shared "thread" lane; Slack and Matrix keep the parent channel/room's "group" — a seed-# on the wrong slot is a row no reply ever resolves to (#111896, #112918).-_THREAD_REPLY_CHAT_TYPE = {"slack": "group", "matrix": "group"}+# key the shared "thread" lane; Slack, Matrix and Telegram (forum topics: ``_build_message_event``+# types every supergroup "group") keep the parent channel/room's "group" — a seed on the wrong slot+# is a row no reply ever resolves to (#111896, #112918).+_THREAD_REPLY_CHAT_TYPE = {"slack": "group", "matrix": "group", "telegram": "group"}def _open_continuable_cron_thread(job: dict, adapter, chat_id: str, loop) -> Optional[str]:diff --git a/tests/cron/test_cron_thread_seed_dm_keying.py b/tests/cron/test_cron_thread_seed_dm_keying.pyindex 4e470d75e1f..b26a14ccbc5 100644--- a/tests/cron/test_cron_thread_seed_dm_keying.py+++ b/tests/cron/test_cron_thread_seed_dm_keying.py@@ -109,19 +109,42 @@ def test_matrix_room_thread_seed_key_matches_room_reply_key():def test_dm_seed_default_is_backward_compatible():"""Callers that don't pass is_dm keep today's thread-keyed behavior —- the new parameter must not silently rekey non-DM call sites."""+ the new parameter must not silently rekey non-DM call sites (Discord+ keys an in-thread reply on the ``thread`` slot)."""store = MagicMock()adapter = MagicMock()adapter._session_store = storewith patch("gateway.mirror.mirror_to_session", return_value=True):_seed_cron_thread_session(- {"id": "j3"}, adapter, "telegram", "123", "9001", "brief",+ {"id": "j3"}, adapter, "discord", "123", "9001", "brief",)assert _seeded_source(store).chat_type == "thread"+def test_telegram_forum_topic_seed_key_matches_topic_reply_key():+ """The Telegram adapter types every supergroup message ``group`` (forum topics included), so a+ forum-topic cron seed typed ``thread`` is a row no topic reply ever resolves to — the same+ shape as the Matrix bug, on the sibling platform."""+ store = MagicMock()+ adapter = MagicMock()+ adapter._session_store = store++ with patch("gateway.mirror.mirror_to_session", return_value=True):+ _seed_cron_thread_session(+ {"id": "j8", "name": "digest"}, adapter, "telegram",+ "-1001234567", "77", "Three bullets", chat_name="ops", is_dm=False,+ )++ reply_source = SessionSource(+ platform=Platform.TELEGRAM, chat_id="-1001234567", chat_type="group", user_id="42",+ thread_id="77",+ )+ assert build_session_key(_seeded_source(store)) == build_session_key(reply_source)+ assert build_session_key(_seeded_source(store)) == "agent:main:telegram:group:-1001234567:77"++def test_scoped_dm_thread_seed_key_matches_scoped_reply_key():"""Slack keys embed the workspace scope_id (build_session_key puts theteam segment in every Slack dm/group/thread key). A seed built withoutdiff --git a/tests/cron/test_scheduler.py b/tests/cron/test_scheduler.pyindex 3eb0bf83736..3a9ceade705 100644--- a/tests/cron/test_scheduler.py+++ b/tests/cron/test_scheduler.py@@ -2455,7 +2455,8 @@ class TestCronDeliveryMirror:# Session row created for the thread, then brief mirrored into it.store.get_or_create_session.assert_called_once()seeded_source = store.get_or_create_session.call_args[0][0]- assert seeded_source.chat_type == "thread"+ # Telegram forum-topic replies key on the parent supergroup's ``group`` slot.+ assert seeded_source.chat_type == "group"assert seeded_source.thread_id == "9001"mirror_mock.assert_called_once()assert mirror_mock.call_args.kwargs.get("thread_id") == "9001"diff --git a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/slash-commands.md b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/slash-commands.mdindex 72e0ab7c070..00fd4b74a24 100644--- a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/slash-commands.md+++ b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/slash-commands.md@@ -59,7 +59,7 @@ Hermes 有两个斜杠命令入口,均由 `hermes_cli/commands.py` 中的中| `/bg <prompt>` | 在独立的后台会话中运行 prompt。agent 独立处理你的 prompt——当前会话保持空闲可继续其他工作。任务完成后结果以面板形式显示。见 [CLI 后台会话](/user-guide/cli#background-sessions)。 || `/btw <question>` | 在不打断当前工作的情况下,就**当前对话**提出一个快速的顺带问题。由一次一次性辅助 LLM 调用根据对话快照作答——实时会话的历史和提示缓存不受影响,当前回合继续运行。需要全新上下文的独立任务请使用 `/bg`。 || `/branch [name]`(别名:`/fork`) | 分支当前会话(探索不同路径) |-| `/handoff <platform>` | **仅限 CLI。** 将当前会话移交给消息平台(Telegram、Discord、Slack、WhatsApp、Signal、Matrix)。gateway 立即接管,在支持线程的平台上创建新线程(Telegram 话题、Discord 文字频道线程、Slack 消息锚定线程),将目标重新绑定到你的 CLI session_id 以重放完整的角色感知转录,并伪造一条合成用户轮次让 agent 确认已在新位置工作。成功后 CLI 干净退出并提示 `/resume`;随时可用 `/resume <title>` 在本地恢复。轮次进行中拒绝执行。需要 gateway 正在运行且目标平台已配置 home 频道(从目标聊天中执行 `/sethome`)。见 [跨平台移交](/user-guide/sessions#cross-platform-handoff)。 |+| `/handoff <platform>` | **仅限 CLI。** 将当前会话移交给消息平台(Telegram、Discord、Slack、WhatsApp、Signal、Matrix)。gateway 立即接管,在支持线程的平台上创建新线程(Telegram 话题、Discord 文字频道线程、Slack 和 Matrix 消息锚定线程),将目标重新绑定到你的 CLI session_id 以重放完整的角色感知转录,并伪造一条合成用户轮次让 agent 确认已在新位置工作。成功后 CLI 干净退出并提示 `/resume`;随时可用 `/resume <title>` 在本地恢复。轮次进行中拒绝执行。需要 gateway 正在运行且目标平台已配置 home 频道(从目标聊天中执行 `/sethome`)。见 [跨平台移交](/user-guide/sessions#cross-platform-handoff)。 |### 配置diff --git a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/features/cron.md b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/features/cron.mdindex a1adc990010..31c2452c867 100644--- a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/features/cron.md+++ b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/features/cron.md@@ -344,7 +344,7 @@ cron:行为为**优先使用话题**,范围限定在任务的来源聊天:-- **支持话题的平台**(Telegram 话题、Discord/Slack 话题):每次投递都会新建+- **支持话题的平台**(Telegram 话题、Discord/Slack/Matrix 话题):每次投递都会新建专用话题,并将简报植入该话题的会话中,因此在话题内回复即可带完整上下文继续。- **仅 DM 的平台**(WhatsApp、Signal、SMS):不存在话题,因此简报会被镜像进来源 DM 会话——DM 本身就是继续的载体。diff --git a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/sessions.md b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/sessions.mdindex 376f97432c0..97392e72cf8 100644--- a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/sessions.md+++ b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/sessions.md@@ -162,7 +162,8 @@ Session ID 格式为 `YYYYMMDD_HHMMSS_<hex>`——CLI/TUI session 使用 6 位- **Telegram** — 开启新的论坛话题(如果在聊天中启用了 Bot API 9.4+ Topics 模式则为私信话题,或论坛超级群组话题)。- **Discord** — 在主文字频道下创建 1440 分钟自动归档的线程。- **Slack** — 发布一条种子消息并使用其 `ts` 作为线程锚点。- - **WhatsApp / Signal / Matrix / SMS** — 无原生线程,回退到直接使用主频道。+ - **Matrix** — 发布一条种子消息并使用其事件 id 作为线程根(`m.thread` 关系)。+ - **WhatsApp / Signal / SMS** — 无原生线程,回退到直接使用主频道。4. Gateway 将目标键重新绑定到你现有的 CLI session id,然后伪造一个合成用户轮次,要求 agent 确认并总结。回复会出现在新线程中。5. Gateway 确认成功后,CLI 打印 `/resume` 提示并干净退出:@@ -181,7 +182,7 @@ Session ID 格式为 `YYYYMMDD_HHMMSS_<hex>`——CLI/TUI session 使用 6 位- 线程创建失败(权限不足、话题模式未开启)→ 直接回退到主频道并仍然完成切换;没有线程隔离,但切换本身有效。- `adapter.send` 失败(速率限制、临时 API 错误)→ 切换标记为失败并附带原因;行被清除以便重试。-**值得注意的限制:** 对于无线程能力的多用户群组主频道平台,合成轮次以私信风格 session 为键。这对自私信主频道(典型设置)有效,但对真正的共享群聊并不理想。线程支持覆盖 Telegram / Discord / Slack——这是最常见的情况——因此大多数设置不会遇到此问题。+**值得注意的限制:** 对于无线程能力的多用户群组主频道平台,合成轮次以私信风格 session 为键。这对自私信主频道(典型设置)有效,但对真正的共享群聊并不理想。线程支持覆盖 Telegram / Discord / Slack / Matrix——这是最常见的情况——因此大多数设置不会遇到此问题。## Session 命名 {#session-naming}