Skip to content

fix: sessions navigation, DM thread display, and DM thread delivery regression#3368

Closed
Lukavyi wants to merge 3 commits intoopenclaw:mainfrom
Lukavyi:fix/telegram-dm-thread-display
Closed

fix: sessions navigation, DM thread display, and DM thread delivery regression#3368
Lukavyi wants to merge 3 commits intoopenclaw:mainfrom
Lukavyi:fix/telegram-dm-thread-display

Conversation

@Lukavyi
Copy link
Copy Markdown
Contributor

@Lukavyi Lukavyi commented Jan 28, 2026

Summary

CleanShot 2026-01-28 at 16 27 14@2x

Fixes #3367

Three related fixes for Telegram DM topics:

  1. Display: Adds ThreadLabel so DM topic sessions show their thread ID
  2. Navigation: Fixes clicking a session in Sessions tab redirecting to Main instead of the selected session
  3. Delivery: Fixes bot replies going to General instead of the originating DM thread (regression from commit 9154971)

Changes

  • src/telegram/bot-message-context.ts: Set ThreadLabel: "Thread: N" for non-group messages with messageThreadId; introduce effectiveThreadId for correct outbound delivery in DM threads
  • src/telegram/bot-message-context.dm-threads.test.ts: Add tests for ThreadLabel in DM threads
  • ui/src/ui/app-lifecycle.ts: Read URL session param before syncTabWithLocation overwrites it with localStorage value

Problem 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 before applySettingsFromUrl(), 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) changed resolveTelegramForumThreadId to return undefined when is_forum is false. This correctly fixed reply-chain pollution in regular groups, but broke DM thread delivery:

  • Telegram Bot API never sets is_forum=true for private chats (only supergroups)
  • context.resolvedThreadId (used by bot-message-dispatch.ts for draft streaming and reply delivery) became undefined for all DM threads
  • Replies, typing indicators, and voice recording indicators all went to General

Fix: Introduce effectiveThreadId = isGroup ? resolvedThreadId : messageThreadId — uses raw messageThreadId for DMs (bypassing the forum gate) while preserving forum-resolved value for groups.

Testing

pnpm test src/telegram/bot-message-context.dm-threads.test.ts

All 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 ThreadLabel payload field so DM topic sessions can be distinguished in the Sessions UI, (2) ensures URL settings (including ?session=) are applied before syncTabWithLocation() 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 when is_forum is absent (private chats never set is_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

  • This PR is generally safe to merge, with one edge-case routing concern around non-group non-DM chat types.
  • Changes are localized and covered by targeted tests for DM thread session keys/labels; the main remaining risk is that effectiveThreadId is applied to all non-group chats (e.g., channels), which may not support message_thread_id semantics and could cause misrouting or Telegram API errors.
  • src/telegram/bot-message-context.ts

lobster-biscuit

@openclaw-barnacle openclaw-barnacle bot added channel: telegram Channel integration: telegram app: web-ui App: web-ui labels Jan 28, 2026
@Lukavyi Lukavyi changed the title feat(telegram): display thread ID for DM topics in Sessions tab feat(telegram): display thread ID for DM topics + fix Sessions tab navigation Jan 28, 2026
@Lukavyi Lukavyi changed the title feat(telegram): display thread ID for DM topics + fix Sessions tab navigation fix(ui): clicking session in Sessions tab navigates to wrong session + add Telegram DM thread display Jan 28, 2026
@Lukavyi Lukavyi force-pushed the fix/telegram-dm-thread-display branch from 92f2e59 to 6025fa6 Compare January 28, 2026 14:25
@Lukavyi Lukavyi changed the title fix(ui): clicking session in Sessions tab navigates to wrong session + add Telegram DM thread display fix: sessions navigation, DM thread display, and DM thread delivery regression Jan 28, 2026
@@ -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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.
Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +164 to 167
// 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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[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.

@Glucksberg
Copy link
Copy Markdown
Contributor

📋 Duplicate triage note: PR #8170 appears to implement the same fix. Consider consolidating efforts or closing one in favor of the other.

@steipete
Copy link
Copy Markdown
Contributor

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.
Given that issue is closed, this fix PR is no longer needed in the active queue and is being closed as stale.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui channel: telegram Channel integration: telegram

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sessions navigation fix + DM thread display + DM thread delivery regression

4 participants