fix: sessions navigation, DM thread display, and DM thread delivery regression#3368
fix: sessions navigation, DM thread display, and DM thread delivery regression#3368Lukavyi wants to merge 3 commits intoopenclaw:mainfrom
Conversation
92f2e59 to
6025fa6
Compare
| @@ -161,6 +161,9 @@ export const buildTelegramMessageContext = async ({ | |||
| isForum, | |||
| messageThreadId, | |||
| }); | |||
| // Effective thread ID for outbound delivery: groups use forum-resolved; DMs use raw messageThreadId | |||
| // (private chats never set is_forum=true per Telegram Bot API, so resolvedThreadId is always undefined for DMs) | |||
| const effectiveThreadId = isGroup ? resolvedThreadId : messageThreadId; | |||
There was a problem hiding this comment.
had issues with threaded mode on DMs in telegram.
Fixed it for myself, came to open a PR and found you already have it here 🙂🙏
- Add ThreadLabel for DM threads (format: 'Thread: N') - Add unit tests for ThreadLabel in DM threads - Fix UI: read URL session param before syncTabWithLocation overwrites it
Commit 9154971 changed resolveTelegramForumThreadId to return undefined when is_forum is false. This broke DM thread delivery because Telegram Bot API never sets is_forum=true for private chats. Introduce effectiveThreadId that uses raw messageThreadId for DMs while preserving forum-resolved value for groups.
8a67184 to
4ae5687
Compare
| // Effective thread ID for outbound delivery: groups use forum-resolved; DMs use raw messageThreadId | ||
| // (private chats never set is_forum=true per Telegram Bot API, so resolvedThreadId is always undefined for DMs) | ||
| const effectiveThreadId = isGroup ? resolvedThreadId : messageThreadId; | ||
| const { groupConfig, topicConfig } = resolveTelegramGroupConfig(chatId, resolvedThreadId); |
There was a problem hiding this comment.
[P1] effectiveThreadId applies to all non-group chats, including channels.
const effectiveThreadId = isGroup ? resolvedThreadId : messageThreadId; assumes any non-group chat is a DM where message_thread_id should be honored. However Telegram “channel” chats are also non-group (chat.type === "channel"), and channels don’t support message_thread_id the same way; passing it into sendChatAction / reply routing can misroute or cause API errors depending on message shape. Consider gating this to private chats specifically (e.g. msg.chat.type === "private") so only DM topics use raw messageThreadId.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/telegram/bot-message-context.ts
Line: 164:167
Comment:
[P1] `effectiveThreadId` applies to all non-group chats, including channels.
`const effectiveThreadId = isGroup ? resolvedThreadId : messageThreadId;` assumes any non-group chat is a DM where `message_thread_id` should be honored. However Telegram “channel” chats are also non-group (`chat.type === "channel"`), and channels don’t support `message_thread_id` the same way; passing it into `sendChatAction` / reply routing can misroute or cause API errors depending on message shape. Consider gating this to private chats specifically (e.g. `msg.chat.type === "private"`) so only DM topics use raw `messageThreadId`.
How can I resolve this? If you propose a fix, please make it concise.|
📋 Duplicate triage note: PR #8170 appears to implement the same fix. Consider consolidating efforts or closing one in favor of the other. |
bfc1ccb to
f92900f
Compare
|
Closing as AI-assisted stale-fix triage. Linked issue #3367 ("Sessions navigation fix + DM thread display + DM thread delivery regression") is currently closed and was closed on 2026-02-04T00:57:57Z with state reason completed. If this specific implementation is still needed on current main, please reopen #3368 (or open a new focused fix PR) and reference #3367 for fast re-triage. |
Summary
Fixes #3367
Three related fixes for Telegram DM topics:
ThreadLabelso DM topic sessions show their thread IDChanges
ThreadLabel: "Thread: N"for non-group messages withmessageThreadId; introduceeffectiveThreadIdfor correct outbound delivery in DM threadssyncTabWithLocationoverwrites it with localStorage valueProblem 1: Display
All DM topic sessions showed the same display name. Now each shows its thread ID (
Thread: 42,Thread: 99).Problem 2: Navigation
Clicking a session in the Sessions tab redirected to Main instead of the clicked session.
Root cause:
syncTabWithLocation()was called beforeapplySettingsFromUrl(), overwriting the URL?session=param with localStorage.Fix: Call
applySettingsFromUrl()first.Problem 3: DM Thread Delivery (regression)
Commit 9154971 (
fix(telegram): ignore message_thread_id for non-forum group sessions) changedresolveTelegramForumThreadIdto returnundefinedwhenis_forumis false. This correctly fixed reply-chain pollution in regular groups, but broke DM thread delivery:is_forum=truefor private chats (only supergroups)context.resolvedThreadId(used bybot-message-dispatch.tsfor draft streaming and reply delivery) becameundefinedfor all DM threadsFix: Introduce
effectiveThreadId = isGroup ? resolvedThreadId : messageThreadId— uses rawmessageThreadIdfor DMs (bypassing the forum gate) while preserving forum-resolved value for groups.Testing
pnpm test src/telegram/bot-message-context.dm-threads.test.tsAll 7 tests pass, including 2 new tests for ThreadLabel.
Greptile Overview
Greptile Summary
This PR fixes three related Telegram DM-topic regressions: (1) adds a
ThreadLabelpayload field so DM topic sessions can be distinguished in the Sessions UI, (2) ensures URL settings (including?session=) are applied beforesyncTabWithLocation()overwrites state from localStorage, and (3) restores correct DM-thread outbound routing by using a DM-specific thread id (message_thread_id) for typing indicators and dispatch context whenis_forumis absent (private chats never setis_forum=true).The changes integrate into the existing Telegram context builder (
buildTelegramMessageContext) by adjusting how thread IDs are computed and emitted, and into the UI lifecycle by reordering initialization to preserve URL-driven navigation.Confidence Score: 4/5
effectiveThreadIdis applied to all non-group chats (e.g., channels), which may not supportmessage_thread_idsemantics and could cause misrouting or Telegram API errors.lobster-biscuit