fix(telegram): restore thread_id=1 handling for DMs (regression from 19b8416a8)#10942
Conversation
| } | ||
| const normalized = Math.trunc(thread.id); | ||
| if (normalized === TELEGRAM_GENERAL_TOPIC_ID && thread.scope === "forum") { | ||
|
|
There was a problem hiding this comment.
Falsy thread IDs dropped
buildTelegramThreadParams() returns early on if (!thread?.id) which treats id=0 as “no thread”. But the function then normalizes with Math.trunc(thread.id) and the tests explicitly exercise id: 0 as an “edge value”, so callers can pass numeric values outside the forum-topic range. If 0 is a valid sentinel/thread id in any upstream input, it will be silently omitted regardless of scope, which is inconsistent with the later normalization logic. Consider changing the guard to only skip on thread?.id == null (or typeof thread.id !== "number") so 0 is handled intentionally.
Also appears in: src/telegram/bot/helpers.test.ts (test asserts id: 0 behavior).
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/telegram/bot/helpers.ts
Line: 74:76
Comment:
**Falsy thread IDs dropped**
`buildTelegramThreadParams()` returns early on `if (!thread?.id)` which treats `id=0` as “no thread”. But the function then normalizes with `Math.trunc(thread.id)` and the tests explicitly exercise `id: 0` as an “edge value”, so callers can pass numeric values outside the forum-topic range. If `0` is a valid sentinel/thread id in any upstream input, it will be silently omitted regardless of `scope`, which is inconsistent with the later normalization logic. Consider changing the guard to only skip on `thread?.id == null` (or `typeof thread.id !== "number"`) so `0` is handled intentionally.
Also appears in: `src/telegram/bot/helpers.test.ts` (test asserts `id: 0` behavior).
How can I resolve this? If you propose a fix, please make it concise.|
✅ Fixed: Addressed the falsy thread IDs issue Thanks for the thorough review! I've implemented the suggested fix: Changes made:
Result:
The fix ensures that thread ID 0 is treated as a valid numeric value while maintaining the correct semantics for DMs vs forums/regular groups. |
|
Confirmed that this fixes the issue with Telegram receiving announce messages. |
- Change test from expecting message_thread_id:1 for DMs to expecting no thread_id - DMs (private chats) don't support threads, so thread_id should be omitted - This aligns with the fix in buildTelegramThreadParams that returns undefined for dm scope - Fixes CI failure in PR openclaw#10942
6a00bb8 to
8f7e4d8
Compare
- DMs should not have thread_id (private chats don't support threads) - Restore PR openclaw#848 fix: skip thread_id=1 for General forum topics - Fixes regression from commit 19b8416 that broke sub-agent announce in DMs - Closes openclaw#10926
- Change guard condition from if (!thread?.id) to if (thread?.id == null) - Allows thread id 0 to pass through and be handled appropriately - Fixes Greptile bot review comment about falsy thread IDs being dropped
- Change test from expecting message_thread_id:1 for DMs to expecting no thread_id - DMs (private chats) don't support threads, so thread_id should be omitted - This aligns with the fix in buildTelegramThreadParams that returns undefined for dm scope - Fixes CI failure in PR openclaw#10942
8f7e4d8 to
a49d607
Compare
|
PR #10942 - fix(telegram): restore thread_id=1 handling for DMs (regression from 19b8416) (#10942) Merged via squash.
Thanks @garnetlyx! |
|
@garnetlyx @Takhoffman This fix introduces a regression for Telegram DMs with Topics enabled. Telegram private chats (1:1 with a bot) do support topics — when the user enables them, The fix for General topic ( There are several open PRs trying to address this: #6192, #17433, #12864, #15818, #7261, #16882, #2778 and issue #12625. |
|
For reference: Telegram Bot API 9.3 (December 31, 2025) officially added Topics in private chats — The API added |
|
Regression note: we are seeing a follow-up behavior regression after the DM thread-id omission fix in 2026.2.15.\n\nTracked in: #17960\n\nSymptom: in Telegram private topics, inbound routing remains thread-aware, but outbound replies often appear in the main tab (topic UX regression). |
Summary
Fixes regression introduced in commit 19b8416 that broke PR #848's fix for Telegram General topic (thread_id=1) handling.
Problem
Sub-agent announce messages fail in Telegram DMs with error: "Bad Request: message thread not found"
Root Cause
Commit 19b8416 ("fix: unify telegram thread handling") modified the logic to only skip thread_id=1 when
scope === "forum":In DMs with
thread_id=1:thread.scope = "dm"1 === 1 && "dm" === "forum"→ falsemessage_thread_id: 1to Telegram API"Bad Request: message thread not found"Fix
Implements Option C (recommended approach) with two explicit checks:
Changes
src/telegram/bot/helpers.ts: UpdatedbuildTelegramThreadParams()with explicit DM checksrc/telegram/bot/helpers.test.ts: Updated tests to reflect new behaviorTesting
Related
Greptile Overview
Greptile Summary
message_thread_identirely whenthread.scope === "dm".thread_id=1) by omitting it from API params.buildTelegramThreadParamsdocs and adjusts/extends unit tests to cover DM and edge-value normalization.[email protected]and updates lockfile accordingly;.gitignoreupdated to ignoredocs/SESSION_LOG.md.Confidence Score: 4/5
!thread?.idguard, which unconditionally dropsid=0before normalization, potentially conflicting with intended semantics if upstream can produce 0 as a meaningful value.