Skip to content

fix(cron): route Telegram DM-topic cron delivery through DeliveryRouter (#22773) - #50023

Merged
kshitijk4poor merged 2 commits into
mainfrom
salvage/f3b-telegram-dmtopic
Jun 21, 2026
Merged

fix(cron): route Telegram DM-topic cron delivery through DeliveryRouter (#22773)#50023
kshitijk4poor merged 2 commits into
mainfrom
salvage/f3b-telegram-dmtopic

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Summary

PR #22410 added three-mode Telegram topic routing to the live message path (TelegramAdapter.send via the gateway DeliveryRouter), but the cron delivery path never got it. cron/scheduler.py::_deliver_result sent through the live adapter with a bare {"thread_id": …} and fell back to the standalone _send_telegram — neither addresses Bot API Direct Messages topics correctly.

After Bot API 10.0 (2026-05-08), sending to a private chat with a bare message_thread_id is rejected / mis-routed, so cron deliveries to a private DM topic landed in the General topic instead of the requested lane (#22773).

Fix

The cron live-adapter branch now routes the text send through the gateway's DeliveryRouter._deliver_to_platform — the same canonical path live messages use — so cron inherits all three Telegram routing modes:

Mode Target shape Routing
1. Forum / supergroup negative chat_id message_thread_id
2. Bot API DM topic private chat_id + numeric topic id direct_messages_topic_id ← the #22773 case
3. Hermes named DM-topic lane private chat_id + named topic ensure_dm_topic + reply anchor

For mode 2, a private-chat target with a numeric topic id is passed as direct_messages_topic_id metadata. Verified end-to-end: TelegramAdapter._thread_kwargs_for_send({"direct_messages_topic_id": "7072"}){message_thread_id: None, direct_messages_topic_id: 7072}not a bare message_thread_id. Forum/supergroup and home-channel deliveries are unchanged; the standalone fallback (gateway down) is preserved.

No new config knob and no duplicated routing logic — this reuses the existing DeliveryRouter (which landed since the candidate PRs were opened) rather than reimplementing topic routing in the cron path, per "extend, don't duplicate."

Salvage / attribution

Salvaged from #42051 (@stepanov1975) and #23249 (@devsart95), which both diagnosed the missing three-mode routing in the cron/standalone path. Reimplemented onto the canonical DeliveryRouter (different, lower-duplication approach), so authored here with both contributors co-credited. devsart95 added to AUTHOR_MAP (chore commit).

To be closed with crediting redirects: #42051, #23249 (and the adjacent #33397).

Tests

Replaced the stale test_live_adapter_thread_fallback_records_delivery_error (which asserted the buggy bare-thread_id send) with test_live_adapter_private_dm_topic_routes_via_direct_messages_topic_id, a behavior contract asserting a private-chat numeric topic routes via direct_messages_topic_id and never sets a bare message_thread_id. Updated the live-adapter test harness to actually run the routed coroutine.

485 passed in tests/cron/; 146 passed in tests/tools/test_send_message_tool.py; 220 passed in gateway delivery tests.

Fixes #22773

@github-actions

github-actions Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

🔎 Lint report: salvage/f3b-telegram-dmtopic vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 11288 on HEAD, 11287 on base (🆕 +1)

🆕 New issues (1):

Rule Count
invalid-argument-type 1
First entries
cron/scheduler.py:900: [invalid-argument-type] invalid-argument-type: Argument to `DeliveryRouter.__init__` is incorrect: Expected `dict[Platform, Any]`, found `Unknown | None`

✅ Fixed issues: none

Unchanged: 5919 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@alt-glitch alt-glitch added type/bug Something isn't working comp/cron Cron scheduler and job management platform/telegram Telegram bot adapter P2 Medium — degraded but workaround exists labels Jun 21, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related: #22773 (issue being fixed), #42051 and #23249 (salvaged predecessors, both open), #33397 (adjacent webhook metadata), #22410 (merged DeliveryRouter three-mode foundation).

Competing open fix-PRs for the same #22773 path, each a different mechanism: #48836 (patches send_message_tool.py + scheduler), #49649 (inline direct_messages_topic_id + utf-8 in scheduler, Windows angle). This PR reuses the canonical DeliveryRouter instead ("extend, don't duplicate"). Related, not duplicate — reviewer's choice of mechanism.

@kshitijk4poor
kshitijk4poor force-pushed the salvage/f3b-telegram-dmtopic branch from 6908606 to 8748951 Compare June 21, 2026 07:45
kshitijk4poor and others added 2 commits June 21, 2026 13:35
…er (#22773)

PR #22410 added three-mode Telegram topic routing to the live message path
(TelegramAdapter.send via the gateway DeliveryRouter), but the cron delivery
path never got it. cron/scheduler.py::_deliver_result sent through the live
adapter with a bare ``{"thread_id": ...}`` and fell back to the standalone
_send_telegram, neither of which addresses Bot API Direct Messages topics
correctly. After Bot API 10.0 (2026-05-08), sending to a private chat with a
bare ``message_thread_id`` is rejected/mis-routed, so cron deliveries to a
private DM topic landed in the General topic instead of the requested lane.

Fix: the cron live-adapter branch now routes the text send through the
gateway's ``DeliveryRouter._deliver_to_platform`` — the same canonical path
live messages use — so it inherits all three Telegram routing modes:

  1. Forum/supergroup (negative chat_id) -> message_thread_id
  2. Bot API DM topics (private chat_id + numeric topic id) ->
     direct_messages_topic_id  (the case #22773 reported)
  3. Hermes-created named private DM-topic lanes -> ensure_dm_topic +
     reply anchor

For mode 2, a private-chat target with a numeric topic id is passed as
``direct_messages_topic_id`` metadata (verified end-to-end:
TelegramAdapter._thread_kwargs_for_send turns it into
``{message_thread_id: None, direct_messages_topic_id: <int>}``), instead of a
bare message_thread_id. Forum/supergroup and home-channel deliveries are
unchanged. The standalone fallback (gateway down) is preserved.

No new config knob and no duplicated routing logic — this reuses the existing
DeliveryRouter rather than reimplementing topic routing in the cron path.

Salvaged from #42051 (stepanov1975) and #23249 (devsart95), which both
diagnosed the missing three-mode routing in the cron/standalone path;
reimplemented onto the canonical DeliveryRouter that landed since those PRs
were opened.

Co-authored-by: Alex <9785479+stepanov1975@users.noreply.github.com>
Co-authored-by: devsart95 <devsart95@gmail.com>
@kshitijk4poor
kshitijk4poor force-pushed the salvage/f3b-telegram-dmtopic branch from 8748951 to f43c616 Compare June 21, 2026 08:07
@kshitijk4poor
kshitijk4poor enabled auto-merge June 21, 2026 08:07
@kshitijk4poor
kshitijk4poor merged commit 3051a16 into main Jun 21, 2026
34 checks passed
@kshitijk4poor
kshitijk4poor deleted the salvage/f3b-telegram-dmtopic branch June 21, 2026 08:17
indigokarasu pushed a commit to indigokarasu/hermes-agent that referenced this pull request Jul 1, 2026
…elegram-dmtopic

fix(cron): route Telegram DM-topic cron delivery through DeliveryRouter (NousResearch#22773)
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
…elegram-dmtopic

fix(cron): route Telegram DM-topic cron delivery through DeliveryRouter (NousResearch#22773)
habarmc1223-sudo pushed a commit to habarmc1223-sudo/hermes-agent-fluxmem that referenced this pull request Jul 8, 2026
…elegram-dmtopic

fix(cron): route Telegram DM-topic cron delivery through DeliveryRouter (NousResearch#22773)
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
…elegram-dmtopic

fix(cron): route Telegram DM-topic cron delivery through DeliveryRouter (NousResearch#22773)
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
…elegram-dmtopic

fix(cron): route Telegram DM-topic cron delivery through DeliveryRouter (NousResearch#22773)
leewenjie pushed a commit to leewenjie/hermes-agent that referenced this pull request Aug 7, 2026
…elegram-dmtopic

fix(cron): route Telegram DM-topic cron delivery through DeliveryRouter (NousResearch#22773)
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 P2 Medium — degraded but workaround exists platform/telegram Telegram bot adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cron delivery to private DM topics broken after PR #22410 — send_message_tool.py missing three-mode routing

2 participants