App freezes permanently (ANR) when opening a forum topic while a bot is streaming a draft.
Steps to reproduce:
A bot streams live message drafts (Bot API sendMessageDraft) into a forum topic.
While it streams, open that topic with the "Unread messages" divider visible (or scroll up while older history is loading).
Within seconds the app stops responding to all input; after ~5 s Android shows "Telegram isn't responding". It never recovers — it must be force-closed.
Expected: draft updates keep rendering and the UI stays responsive.
This happens many times per day for me (28 identical ANR traces in 3 days). The main thread is always Runnable in ChatActivity.calculateHeightUntilOutOwner (SourceFile:24444), called from BotForumHelper.onBotForumDraftUpdate. Full ANR trace attached below.
Root cause (from published source of 12.9.0/6966): calculateHeightUntilOutOwner iterates rows in a while(true) loop with a++ at the bottom. If the view at position a is neither ChatMessageCell nor ChatActionCell (e.g. ChatUnreadCell or a loading cell), or its messageObject is null, the continue branches (ChatActivity.java:24458 and :24461) skip the increment, so the loop re-queries the same position forever on the main thread; each pass rescans all children and replays pending adapter updates via findViewByPosition/getChildAdapterPosition. The sibling method calculateFirstMessageGroupHeight handles the same case correctly with break. Suggested fix: a++; continue; in both branches (or break).
Create a private chat with a bot that has forum topics enabled, and have the bot stream live message drafts into a topic (Bot API sendMessageDraft, several updates per second — e.g. an AI bot "typing" its answer).
Let a few bot messages accumulate unread in that topic while you are elsewhere (another topic or chat).
While the bot is still actively streaming its draft, open the topic — the "Unread messages" divider is visible near the bottom.
Wait for the next draft update to arrive (1-2 seconds). The chat freezes: no scrolling, no taps, no back button.
After ~5 seconds Android shows the "Telegram isn't responding" dialog. Tapping "Wait" never helps — the main thread is in an infinite loop — so the app must be force-closed.
Alternative trigger for step 3: open the streaming topic and immediately scroll up so the history-loading spinner is attached; the next draft update then freezes the app the same way.
Device info
Telegram Android 12.9.0 (69662), Google Pixel 6, 17 (37)
Full ANR trace attached (system dropbox data_app_anr entry from the Pixel 6). Main thread stack at the moment of the hang:
at org.telegram.ui.Components.RecyclerListView.findViewByPosition at org.telegram.ui.ChatActivity.calculateHeightUntilOutOwner (SourceFile:24444) at org.telegram.ui.ChatActivity.didReceivedNotification at org.telegram.messenger.NotificationCenter.postNotificationName at org.telegram.messenger.BotForumHelper.onBotForumDraftUpdate (SourceFile:145) at org.telegram.messenger.MessagesController.processUpdateArray
All 28 recorded ANRs over 3 days have this exact same stack (some enter via ChatActivity.processNewMessages instead of the draft-update notification — same loop).
at org.telegram.ui.Components.RecyclerListView.findViewByPosition
at org.telegram.ui.ChatActivity.calculateHeightUntilOutOwner (SourceFile:24444)
at org.telegram.ui.ChatActivity.didReceivedNotification
at org.telegram.messenger.NotificationCenter.postNotificationName
at org.telegram.messenger.BotForumHelper.onBotForumDraftUpdate (SourceFile:145)
at org.telegram.messenger.MessagesController.processUpdateArray
All 28 recorded ANRs over 3 days have this exact same stack (some enter via ChatActivity.processNewMessages instead of the draft-update notification — same loop).