Skip to content

fix(cron): use message_thread_id for private-chat forum topics (#55265) - #55270

Closed
nniicckk6 wants to merge 1 commit into
NousResearch:mainfrom
nniicckk6:fix/cron-dm-topic-forum-regression
Closed

fix(cron): use message_thread_id for private-chat forum topics (#55265)#55270
nniicckk6 wants to merge 1 commit into
NousResearch:mainfrom
nniicckk6:fix/cron-dm-topic-forum-regression

Conversation

@nniicckk6

Copy link
Copy Markdown

Problem

PR #50023 blanket-switched all Telegram private-chat cron deliveries from message_thread_id to direct_messages_topic_id. This silently broke forum-style topics in private chats (created via createForumTopic API), because Telegram accepts direct_messages_topic_id with ok: true but renders the message in General instead of the requested topic — no error, no retry, silent failure.

Full details in #55265.

Root Cause

There are two distinct private-chat topic topologies:

Topology message_thread_id direct_messages_topic_id How created
Forum topics in private chat ✅ Works ❌ Silently ignored → General createForumTopic API
Native DM-topics mode ✅ Works (after May 9 server fix) ✅ Works Telegram client UI

The Bot API 10.0 regression (#22022) that originally broke message_thread_id was fixed by Telegram server-side on May 9, 2026. Both parameters now work for both topologies — except direct_messages_topic_id is silently ignored for forum topics.

cron/scheduler.py:1251-1266 could not distinguish between the topologies and used the parameter wrong for the more common case (forum topics).

Fix

Remove the is_private_dm_topic branch that set direct_messages_topic_id. Route through message_thread_id (the default path for all other targets). The adapter's existing thread-not-found fallback (plugins/platforms/telegram/adapter.py) already retries with direct_messages_topic_id if Telegram returns 400 thread not found — so native DM-topics mode is still covered.

Evidence

# message_thread_id → CORRECT (lands in topic)
sendMessage(chat_id=978174799, message_thread_id=252345)
→ ok: true, message_thread_id: 252345, is_topic_message: true

# direct_messages_topic_id → WRONG (silently ignored, lands in General)
sendMessage(chat_id=978174799, direct_messages_topic_id=252345)
→ ok: true, message_thread_id: null, is_topic_message: null  ← wrong location!

User confirmed via Telegram client: message_thread_id appears in the correct topic, direct_messages_topic_id appears in General.

Why not detect the topology?

getChat does not return is_forum: true for private chats with forum topics (the field is absent). There is no reliable Bot API to distinguish the two topologies at send time. Using message_thread_id first with a direct_messages_topic_id fallback is the robust approach — matching how the gateway adapter already works.

Testing

  • Syntax: python3 -m py_compile cron/scheduler.py
  • Lint: no new errors introduced
  • Live test: cron delivery to forum-topic private chat → message lands in correct topic
  • Regression: cron delivery to native DM-topic private chat → thread-not-found fallback fires correctly

Related

…esearch#55265)

PR NousResearch#50023 blanket-switched all private-chat cron deliveries to use
direct_messages_topic_id instead of message_thread_id. This silently
broke forum-style topics in private chats (created via createForumTopic),
because Telegram accepts direct_messages_topic_id with ok: true but
silently renders the message in General instead of the topic.

The Bot API 10.0 server-side regression (NousResearch#22022) that motivated the
switch was fixed by Telegram on May 9, 2026 — message_thread_id works
for all private-chat topic types again.

Fix: route via message_thread_id (the default path). The adapter's
existing thread-not-found fallback already retries with
direct_messages_topic_id for native DM-topics mode if needed.

Closes NousResearch#55265
Relates to NousResearch#22773, NousResearch#22022
@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 Jun 29, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Competing fix with #52079 for the same bug (forum topics in private chats mis-routed to General via the cron is_private_dm_topic heuristic; tracked at #52060/#55265). This PR removes the heuristic branch and routes via message_thread_id, relying on the adapter's 400-thread-not-found fallback for native DM-topics mode. #52079 instead gates the DM-topic route on an explicit direct_messages_topic_id signal. Same code site, different mechanism — maintainer should pick one (#52079 is earlier and handles native DM-topics explicitly rather than via the retry fallback).

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

Verdict: LGTM

Fixes cron topic routing for private-chat forum topics. Uses message_thread_id directly instead of the overly-broad blanket switch from PR #50023.

  • Clean simplification of topic routing logic
  • Fixes regression from prior PR
  • Well-scoped: 1 file, 28 additions

Reviewed 1 file, 28 additions. Approved.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the focused diagnosis. This is already fixed on current main by a stronger implementation. This is an automated hermes-sweeper review.

  • Commit fc31f14cdaa1471181956d78bb9d7727bf22bde5 (fix(cron): disambiguate Telegram forum vs channel DM topics at delivery time (#52060)) shipped in v2026.7.7.
  • cron/scheduler.py:1349 probes the live adapter and defaults private/forum targets safely to message_thread_id; only confirmed type == "channel" targets use direct_messages_topic_id.
  • cron/scheduler.py:1645 applies that distinction consistently to both text and media delivery metadata.
  • tests/cron/test_scheduler.py:3382 covers the reported forum-topic route, while tests/cron/test_scheduler.py:3628 preserves the channel DM-topic route.

This also addresses the member comment identifying the competing approaches: main retained the forum-topic fix while avoiding regression for genuine channel DM topics.

@teknium1 teknium1 closed this Jul 15, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jul 15, 2026
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:implemented-on-main Sweeper: behavior already present on current main 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.

[Bug] Cron delivery to private chat forum-topics lands in General — direct_messages_topic_id silently ignored (regression from #50023)

4 participants