Skip to content

fix(telegram): resolve DM topic thread ids#80726

Open
Audiofool934 wants to merge 1 commit into
openclaw:mainfrom
Audiofool934:fix/telegram-dm-topic-thread-id
Open

fix(telegram): resolve DM topic thread ids#80726
Audiofool934 wants to merge 1 commit into
openclaw:mainfrom
Audiofool934:fix/telegram-dm-topic-thread-id

Conversation

@Audiofool934

Copy link
Copy Markdown

Summary

  • add a shared Telegram helper that resolves thread ids from message_thread_id or Bot API direct_messages_topic.topic_id
  • use that helper across Telegram inbound message context, native commands, runtime handlers, and sequential keys
  • add regression coverage for BotFather Threaded Mode/private DM topic routing

Testing

  • OPENCLAW_VITEST_INCLUDE_FILE=/tmp/openclaw-vitest-include.json OPENCLAW_VITEST_MAX_WORKERS=1 corepack pnpm vitest run --config test/vitest/vitest.extension-telegram.config.ts --typecheck --reporter verbose
  • OPENCLAW_VITEST_INCLUDE_FILE=/tmp/openclaw-vitest-include-2.json OPENCLAW_VITEST_MAX_WORKERS=1 corepack pnpm vitest run --config test/vitest/vitest.extension-telegram.config.ts --typecheck --reporter dot
  • corepack pnpm format:check extensions/telegram/src/bot/helpers.ts extensions/telegram/src/bot/helpers.test.ts extensions/telegram/src/bot-message-context.ts extensions/telegram/src/bot-message-context.dm-topic-threadid.test.ts extensions/telegram/src/bot-native-commands.ts extensions/telegram/src/bot-handlers.runtime.ts extensions/telegram/src/sequential-key.ts
  • git diff --check

@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 11, 2026
@clawsweeper

clawsweeper Bot commented May 11, 2026

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed July 3, 2026, 11:50 PM ET / 03:50 UTC.

Summary
The PR adds a Telegram helper that falls back from message_thread_id to direct_messages_topic.topic_id and uses it across inbound context, native commands, runtime handlers, sequential keys, and regression tests.

PR surface: Source +23, Tests +37. Total +60 across 7 files.

Reproducibility: yes. by source inspection: current main reads only message_thread_id in key inbound routing paths while the PR proof describes BotFather DM-topic updates exposing only direct_messages_topic.topic_id. I did not run a live Telegram repro in this read-only review.

Review metrics: none identified.

Merge readiness
Overall: 🦐 gold shrimp
Proof: 🦞 diamond lobster ✨ media proof bonus
Patch quality: 🦐 gold shrimp
Result: needs maintainer review before merge.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Refresh the branch against current main without dropping outbound direct_messages_topic_id callback/send handling.
  • Rerun focused Telegram DM-topic validation on the refreshed head.

Mantis proof suggestion
Native Telegram Desktop proof after the refresh would directly show whether replies stay in the originating BotFather Threaded Mode DM topic. A maintainer can ask Mantis to capture proof by posting this exact PR comment:

@openclaw-mantis telegram desktop proof: verify BotFather Threaded Mode DM-topic messages route and reply inside the originating Telegram topic after the branch is refreshed.

Risk before merge

  • [P1] The PR head is currently conflicting/dirty, so maintainers cannot trust the exact merge result until the branch is refreshed.
  • [P2] The refresh must preserve current main's outbound direct_messages_topic_id handling while adding only the inbound direct_messages_topic.topic_id fallback.
  • [P1] Topic-id handling affects both visible Telegram reply placement and session/sequential-key isolation.

Maintainer options:

  1. Refresh And Revalidate Topic Routing (recommended)
    Resolve the branch against current main, keep inbound topic identity separate from outbound send params, then rerun focused Telegram DM-topic tests and visible proof.
  2. Accept Existing Proof After Manual Refresh
    Maintainers could accept the screenshots only if the refreshed diff is manually checked to preserve the same visible topic routing and newer direct-topic send path.
  3. Replace If The Branch Stalls
    If the contributor branch cannot be refreshed cleanly, pause or close it and land a narrow replacement PR carrying the same inbound fallback onto current main.

Next step before merge

  • [P2] Manual review is appropriate because the remaining blocker is a conflicting branch refresh plus topic-sensitive validation, not a clean automated repair on a mergeable head.

Security
Cleared: The diff is limited to Telegram TypeScript routing helpers and tests, with no dependency, workflow, secret-handling, or package-execution changes.

Review findings

  • [P1] Refresh the conflicting branch before merge — extensions/telegram/src/bot-handlers.runtime.ts:434
Review details

Best possible solution:

Land a refreshed Telegram plugin fix that adds the inbound DM-topic fallback across context, native commands, runtime routing, and sequential keys while preserving forum-topic and outbound direct-topic semantics.

Do we have a high-confidence way to reproduce the issue?

Yes by source inspection: current main reads only message_thread_id in key inbound routing paths while the PR proof describes BotFather DM-topic updates exposing only direct_messages_topic.topic_id. I did not run a live Telegram repro in this read-only review.

Is this the best way to solve the issue?

Yes after refresh: a Telegram-local resolver is the narrow owner-boundary fix, but the branch must first be reconciled with current main without merging outbound direct_messages_topic_id and inbound message_thread_id semantics.

Full review comments:

  • [P1] Refresh the conflicting branch before merge — extensions/telegram/src/bot-handlers.runtime.ts:434
    GitHub reports this head as CONFLICTING/DIRTY, and current main has newer Telegram topic callback/send handling in the same runtime file. Resolve the branch against current main before maintainers can trust the exact merged topic-routing behavior.
    Confidence: 0.92

Overall correctness: patch is incorrect
Overall confidence: 0.86

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 9d68f877ac3e.

Label changes

Label justifications:

  • P2: The PR targets a real Telegram DM-topic routing bug with channel-specific blast radius and no core outage evidence.
  • merge-risk: 🚨 message-delivery: The changed topic id controls Telegram reply placement, so a bad merge could send replies to the flat chat or wrong DM topic.
  • merge-risk: 🚨 session-state: The same topic id drives DM-topic session isolation and sequential lanes, so a bad merge could collapse or split topic sessions incorrectly.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (screenshot): The PR discussion includes redacted live-flow notes and Telegram Desktop screenshots showing replies remaining inside distinct DM topics after the change.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR discussion includes redacted live-flow notes and Telegram Desktop screenshots showing replies remaining inside distinct DM topics after the change.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. The PR discussion includes redacted live-flow notes and Telegram Desktop screenshots showing replies remaining inside distinct DM topics after the change.
  • mantis: telegram-visible-proof: Mantis should capture Telegram visible proof. The PR changes visible Telegram DM-topic reply placement and session separation, which can be demonstrated in Telegram Desktop.
Evidence reviewed

PR surface:

Source +23, Tests +37. Total +60 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 5 33 10 +23
Tests 2 37 0 +37
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 70 10 +60

What I checked:

  • Current main inbound message context gap: Current main derives messageThreadId from msg.message_thread_id before resolving the Telegram thread spec, so updates carrying only direct_messages_topic.topic_id do not populate the DM topic id here. (extensions/telegram/src/bot-message-context.ts:149, 9d68f877ac3e)
  • Current main runtime routing gap: Current main passes normalizedMsg.message_thread_id into inbound authorization/message handling, so DM-topic updates with only direct_messages_topic.topic_id can miss topic-aware session and reply-chain routing. (extensions/telegram/src/bot-handlers.runtime.ts:3380, 9d68f877ac3e)
  • Current main sequential lane gap: Current main builds Telegram sequential keys from msg.message_thread_id, so private DM-topic updates with only direct_messages_topic.topic_id collapse to the chat-level key. (extensions/telegram/src/sequential-key.ts:192, 9d68f877ac3e)
  • Current main outbound direct-topic handling to preserve: Current main separately maps callback direct_messages_topic.topic_id into outbound direct_messages_topic_id; a refresh must preserve that outbound send parameter instead of treating it as interchangeable with inbound message-thread identity. (extensions/telegram/src/bot-handlers.runtime.ts:2509, 9d68f877ac3e)
  • PR diff adds the intended shared fallback: The PR adds resolveTelegramMessageThreadId, preferring message_thread_id and falling back to direct_messages_topic.topic_id, then wires that helper into context, native commands, runtime handlers, and sequential keys. (extensions/telegram/src/bot/helpers.ts:83, c4c03134e1c6)
  • Live PR merge state: GitHub reports the PR head as CONFLICTING and DIRTY, with base 85b668e9ee6e86aac378a4480dc94ef7f51f60c4 behind current main 9d68f877ac3ea28c1abffaf7a043c8c916bea217. (c4c03134e1c6)

Likely related people:

  • obviyus: Commit c13b35b implemented adjacent DM-topic support across message context, runtime handlers, native commands, tests, and helpers, and recent GitHub commit history shows continued Telegram runtime work. (role: introduced adjacent DM-topic support and recent Telegram contributor; confidence: high; commits: c13b35b83d5b, 049c3c487789; files: extensions/telegram/src/bot-message-context.ts, extensions/telegram/src/bot-handlers.runtime.ts, extensions/telegram/src/bot-native-commands.ts)
  • 8BlT: Merged PR fix: handle forum/topics in Telegram DM thread routing #18021 changed resolveTelegramThreadSpec for DM/forum topic routing in the same helper family. (role: adjacent topic-routing contributor; confidence: high; commits: e20b87f1ba33, 405f50782c11; files: extensions/telegram/src/bot/helpers.ts, extensions/telegram/src/bot/helpers.test.ts)
  • brokemac79: Merged PR [codex] Fix Telegram DM topic session routing #88421 changed Telegram DM-topic outbound session routing and is adjacent to this inbound fallback work. (role: adjacent outbound session-routing contributor; confidence: medium; commits: 72c61bc1235b; files: extensions/telegram/src/channel.ts, extensions/telegram/src/session-route.test.ts)
  • Audiofool934: The author supplied the current branch and redacted Telegram Desktop proof; included for routing only because the next action is likely branch refresh by the contributor, not because of prior main ownership. (role: current PR author with proof context; confidence: medium; commits: c4c03134e1c6; files: extensions/telegram/src/bot/helpers.ts, extensions/telegram/src/bot-handlers.runtime.ts, extensions/telegram/src/bot-message-context.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added the mantis: telegram-visible-proof Mantis should capture Telegram visible proof. label May 11, 2026
@Audiofool934

Copy link
Copy Markdown
Author

Added real Telegram behavior proof for this change.

Verified against a BotFather Threaded Mode private chat with OpenClaw configured for inbound topic/session isolation:

  • Sent a message inside a Telegram DM topic.
  • The inbound update exposed the topic through direct_messages_topic.topic_id rather than only message_thread_id.
  • OpenClaw resolved the thread id with the new helper fallback.
  • The assistant reply appeared in the same originating DM topic, not in the flat “New Chat” area.
  • Outbound replies were sent using message_thread_id, which Telegram rendered correctly as a topic message.

Private chat/user/topic details are redacted, but this matches the failure mode this PR fixes.

Local verification also covered:

  • threadReplies = "inbound" config path
  • inbound resolution via msg.message_thread_id ?? msg.direct_messages_topic?.topic_id
  • outbound DM topic replies using message_thread_id
  • relevant dist/source JS passes syntax check
  • post-update topic-routing guard passed on our live OpenClaw Telegram setup

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented May 13, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@Takhoffman

Copy link
Copy Markdown
Contributor

@openclaw-mantis telegram desktop proof: verify Telegram DM topic thread routing. Show that messages in BotFather Threaded Mode/private DM topics route to the correct topic/session instead of losing or misrouting the thread id.

@openclaw-mantis

openclaw-mantis Bot commented May 17, 2026

Copy link
Copy Markdown
Contributor

Mantis Telegram Desktop Proof

Summary: Mantis skipped Telegram Desktop before/after GIF proof because this PR did not have an honest native Telegram-visible before/after.

@Audiofool934

Audiofool934 commented May 20, 2026

Copy link
Copy Markdown
Author

Added redacted Telegram Desktop proof for BotFather Threaded Mode DM-topic behavior.

Evidence:

Telegram topic proof: Chat topic

Telegram topic proof: Spotify topic

These screenshots show OpenClaw replies remaining inside separate Telegram DM topics instead of collapsing into the flat New Chat area. The topic histories are distinct, which verifies real Telegram-visible topic/session separation.

This matches the PR's target behavior: inbound DM-topic messages resolve to the originating topic/thread id, and outbound replies are rendered by Telegram in that same topic.

Private chat/user details are redacted.

@clawsweeper re-review

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. labels May 20, 2026
@clawsweeper

clawsweeper Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

✨ Hatched: 💎 rare Cosmic Test Hopper

Hatch command

Comment @clawsweeper hatch when this PR is hatchable.

Hatchability rules:

  • Merged PRs are hatchable.
  • Open PRs are hatchable when they are status: 👀 ready for maintainer look, status: 🚀 automerge armed, or labeled clawsweeper:automerge.
  • Closed unmerged PRs are hatchable only when one of those hatchable labels is still present in the durable record.

Rarity: 💎 rare.
Trait: watches the merge queue.
Image traits: location proof lagoon; accessory tiny test log scroll; palette rose quartz and slate; mood focused; pose guarding a tiny green check; shell brushed metal shell; lighting soft studio lighting; background tiny shells and proof notes.
Share on X: post this hatch
Copy: My PR egg hatched a 💎 rare Cosmic Test Hopper in ClawSweeper.

What is this egg doing here?
  • Eggs appear after the PR passes real-behavior proof. It is here for vibes, not verdicts: it does not change labels, ratings, merge decisions, or automation.
  • The shell reacts to review momentum: open follow-up work warms it up, re-review makes it wobble, and a clean final review lets it hatch.
  • Hatchability usually comes from sufficient real-behavior proof, no blocking P0/P1/P2 findings, no security attention needed, and clean correctness. A merged PR is already final, so merge makes the egg hatchable independently.
  • The hatch is seeded from this repository and PR number, so the same PR keeps the same creature; the reviewed head SHA can only change safe visual details.
  • Rarity is just collectible sparkle: 🥚 common, 🌱 uncommon, 💎 rare, ✨ glimmer, and 🌈 legendary.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. mantis: telegram-visible-proof Mantis should capture Telegram visible proof. rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. labels May 20, 2026
@clawsweeper clawsweeper Bot added the mantis: telegram-visible-proof Mantis should capture Telegram visible proof. label May 23, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jun 21, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jun 21, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jun 21, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jul 19, 2026
@clawsweeper

clawsweeper Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: fix(telegram): resolve DM topic thread ids This is item 1/1 in the current shard. Shard 16/22.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

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

Labels

channel: telegram Channel integration: telegram mantis: telegram-visible-proof Mantis should capture Telegram visible proof. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S stale Marked as stale due to inactivity status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants