Skip to content

fix(cron): route Telegram forum topics via message_thread_id, support channel DM topics (#52060) - #58165

Merged
kshitijk4poor merged 1 commit into
NousResearch:mainfrom
kshitijk4poor:fix/52060-cron-dm-topic-routing
Jul 4, 2026
Merged

fix(cron): route Telegram forum topics via message_thread_id, support channel DM topics (#52060)#58165
kshitijk4poor merged 1 commit into
NousResearch:mainfrom
kshitijk4poor:fix/52060-cron-dm-topic-routing

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Summary

Cron deliveries to a Telegram topic now land in the right thread — both ordinary forum-style topics in a private chat and genuine Bot API channel Direct-Messages topics.

Root cause: the #22773 heuristic classified any telegram:<positive_chat_id>:<numeric_thread_id> cron target as a Bot API channel Direct-Messages topic and routed it via direct_messages_topic_id, which makes the adapter null message_thread_id. A normal forum-style topic inside a private chat has the identical shape, so every such cron delivery landed in General instead of the target thread (#52060). It also meant the only way to address a genuine channel DM topic was this same ambiguous guess.

Changes

  • cron/scheduler.py: new _is_channel_dm_topic() helper replaces the shape-based heuristic. It probes the live adapter's get_chat_info() once at delivery time and routes via direct_messages_topic_id only when the chat is actually a channel; everything else (private-chat forum topic, forum supergroup, group) and any probe error/timeout/None fall back to message_thread_id — parity with 0.16.0 and with live reply routing. thread_id is placed in route_metadata deliberately so the anchorless cron send bypasses the DeliveryRouter's private-chat reply-anchor requirement.
  • tests/cron/test_scheduler.py: behavior-contract tests for forum-topic → message_thread_id, channel-DM-topic → direct_messages_topic_id (text + media each), plus two fail-safe paths (probe raises, probe returns None).

Validation

Check Result
cron scheduler suite 211 passed
forum-topic test on main RED (routes via direct_messages_topic_id — the bug)
forum-topic test with fix GREEN (routes via message_thread_id)
E2E, real cross-thread event loop forum→message_thread_id, channel→direct_messages_topic_id, raise/None/no-probe→fail-safe
Full _deliver_result E2E correct metadata reaches adapter.send in both branches

Credit

Thanks to @Tranquil-Flow (#52079) for reporting and diagnosing #52060. This takes their idea — gate the DM-topic route rather than infer it from chat-id sign — and grounds it in a real runtime signal (get_chat_info chat type) instead of an origin key that no code path produces, so genuine channel DM-topic cron delivery works too.

Closes #52060

…ry time (NousResearch#52060)

The NousResearch#22773 heuristic classified any telegram:<positive_chat_id>:<numeric_thread_id>
cron target as a Bot API channel Direct-Messages topic and routed it via
direct_messages_topic_id, which nulls message_thread_id. A normal forum-style
topic inside a private chat has the identical shape, so every such cron
delivery landed in General instead of the target thread (NousResearch#52060). It also
means the only way to address a genuine channel DM topic was this same
ambiguous guess.

Disambiguate with the real runtime signal instead: probe the live adapter's
get_chat_info once and route via direct_messages_topic_id only when the chat
is actually a channel; everything else (private forum topic, forum supergroup,
group) and any probe failure fall back to message_thread_id — parity with
0.16.0 and with live reply routing. This fixes forum-topic delivery AND makes
genuine channel DM-topic cron delivery work correctly.
@kshitijk4poor
kshitijk4poor force-pushed the fix/52060-cron-dm-topic-routing branch from 6ab8eab to fc31f14 Compare July 4, 2026 09:03
@kshitijk4poor
kshitijk4poor enabled auto-merge July 4, 2026 09:03
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/cron Cron scheduler and job management comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages labels Jul 4, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Related: this is the active resubmission of the closed #52079 (both fix #52060). Competing OPEN fix: #55270 removes the is_private_dm_topic branch entirely and leans on the adapter's 400-thread-not-found fallback, whereas this PR probes get_chat_info() live and routes direct_messages_topic_id only for real channels (preserving genuine channel-DM-topic routing). Same underlying bug (#52060 / dup #55265). Flagging the cluster so a maintainer can pick one — the live-probe approach here looks the more complete of the two.

@kshitijk4poor
kshitijk4poor merged commit 5e94bc1 into NousResearch:main Jul 4, 2026
29 checks passed
@kshitijk4poor
kshitijk4poor deleted the fix/52060-cron-dm-topic-routing branch July 4, 2026 09:13
habarmc1223-sudo pushed a commit to habarmc1223-sudo/hermes-agent-fluxmem that referenced this pull request Jul 8, 2026
…on-dm-topic-routing

fix(cron): route Telegram forum topics via message_thread_id, support channel DM topics (NousResearch#52060)
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
…on-dm-topic-routing

fix(cron): route Telegram forum topics via message_thread_id, support channel DM topics (NousResearch#52060)
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
…on-dm-topic-routing

fix(cron): route Telegram forum topics via message_thread_id, support channel DM topics (NousResearch#52060)
leewenjie pushed a commit to leewenjie/hermes-agent that referenced this pull request Aug 7, 2026
…on-dm-topic-routing

fix(cron): route Telegram forum topics via message_thread_id, support channel DM topics (NousResearch#52060)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cron Cron scheduler and job management comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/telegram Telegram bot adapter sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cron Telegram nudges land in General topic — #22773 DM-topic heuristic mis-classifies threaded-DM forum topics

2 participants