#151057 put a "native id" step in the private-topic retry ladders: after
"message thread not found" the same topic was retried as
direct_messages_topic_id. Bot API honours that field only in a channel's DM
supergroup (Client::check_message_topic builds a direct-messages topic only for
a supergroup with is_direct_messages; #55265 saw ok:true and the message in
General). In a bot's private chat the native-id send lands in the root and
returns success, so the ladder read it as "delivered in the topic": the dead
binding was never pruned (topic mode never turned off, #95517), cron lost its
thread_fallback note, and every later send paid the full ladder again.
All three ladders (text send, media, control messages) now go from the
same-thread retry straight to the chat root without the dead anchor, prune the
binding and (text) report thread_fallback, as before #151057.
direct_topic_retry_kwargs is gone. A channel DM supergroup still routes by
direct_messages_topic_id first (_thread_kwargs_for_send, unchanged).
The thread-fallback tests that pinned the native-id step now pin the root
route; the three that only exercised failures of that step are removed.
Fixes#151852. Found by @kshitijk4poor's post-merge review.
Review finding (kshitijk4poor, smaller items, #151057): direct_topic_retry_kwargs
now reads the telegram_direct_messages_topic_id alias _metadata_direct_messages_topic_id
accepts and names the General-topic "1"; the unused reply_to_message_id parameter
of _send_with_dm_topic_reply_anchor_retry is dropped; _send_message_with_thread_fallback's
docstring and the media loop comment describe the current ladder; telegram.md
mentions the named-topic (created_for_send) fail-closed exception.
Review finding (kshitijk4poor 2 / BearHuddleston should-fix 1, #151057): control
messages and attachments raised when the native direct_messages_topic_id attempt
answered a missing-topic BadRequest other than "thread not found" (TOPIC_DELETED),
where origin/main delivered to the root. One private-chat-only topic_gone()
predicate restores origin/main's topic wordings; forum supergroups keep "thread not
found" only, and parse/permission/flood errors still raise and keep the binding.
Co-authored-by: BearHuddleston <BearHuddleston@users.noreply.github.com>
Finding: named-topic media silently falls into the root chat. _send_with_dm_topic_reply_anchor_retry retried a
dead private topic by native id and then the chat root for every positive chat id, ignoring
metadata['telegram_dm_topic_created_for_send']. Text already refuses that fallback so DeliveryRouter can
recreate the named topic; attachments now follow the same rule (telegram_dm_topic_send.dead_topic_may_reroute).
Ordinary private-reply sends keep the native-id-then-root ladder.
A Telegram private-topic send that Bot API rejects now takes one step per
failure instead of dropping all routing at once:
- deleted reply anchor ("message to be replied not found" / "reply message
not found"): drop only the anchor, keep message_thread_id (text, overflow
continuation, every media kind, control messages). Media used to lose the
thread and land in the root chat (#35739, #136808).
- "message thread not found" in a private chat: retry the same id once as
direct_messages_topic_id (native DM topics accept only that, #137568),
then deliver to the chat root without the reply anchor (it points into the
dead topic) and prune the binding (#95517). The text path used to return a
non-retryable failure, so base.py's plain-text fallback re-sent the same
dead thread + anchor and the reply was lost.
The ladder helpers live in plugins/platforms/telegram/telegram_dm_topic_send.py;
adapter.py shrinks by 7 lines.
Fixes#136808, fixes#137568, fixes#95517, fixes#35739.
Salvages #136811 (@KoNit-K).