fix(telegram): route forum-topic replies to correct thread#512
Conversation
Outbound calls in deliver_channel_replies_to_targets and related functions passed target.chat_id (the raw numeric chat ID) instead of target.outbound_to() (which encodes chat_id:thread_id for forum topics). This caused all replies in a Telegram supergroup to land in the top-level chat regardless of which topic originated the message. Additionally, ChannelReplyTargetKey was missing the thread_id field, causing stream-dedup to treat all topics in the same supergroup as equivalent — if topic A's stream completed first, topic B's text delivery would be incorrectly skipped. Fixes #442 Entire-Checkpoint: 38dddac7b136
Merging this PR will degrade performance by 30.21%
Performance Changes
Comparing Footnotes
|
Greptile SummaryThis PR fixes Telegram forum-topic replies being routed to the wrong thread by replacing all raw Key changes:
Confidence Score: 5/5Safe to merge — changes are systematic, compile-verified, and cover all outbound call sites consistently. All outbound delivery paths are correctly updated to use No files require special attention — Important Files Changed
Sequence DiagramsequenceDiagram
participant UA as User (Topic A)
participant UB as User (Topic B)
participant Dispatcher as ChannelStreamDispatcher
participant OutboundA as Outbound (chat:thread_a)
participant OutboundB as Outbound (chat:thread_b)
participant Delivery as deliver_channel_replies
UA->>Dispatcher: message → push target {chat, thread_a}
UB->>Dispatcher: message → push target {chat, thread_b}
Dispatcher->>OutboundA: send_stream(outbound_to = "chat:thread_a")
Dispatcher->>OutboundB: send_stream(outbound_to = "chat:thread_b")
OutboundA-->>Dispatcher: Ok → insert key{chat, thread_a} into completed
OutboundB-->>Dispatcher: Ok → insert key{chat, thread_b} into completed
Dispatcher->>Delivery: completed_target_keys = {key_a, key_b}
Delivery->>Delivery: key_a ∈ streamed → skip text for Topic A ✓
Delivery->>Delivery: key_b ∈ streamed → skip text for Topic B ✓
Note over Delivery: Before fix: thread_id absent → key_a == key_b
Note over Delivery: Topic B incorrectly skipped on cron/no-message_id paths
Reviews (2): Last reviewed commit: "fix(telegram): restore raw chat_id in lo..." | Re-trigger Greptile |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Address PR review: chat_for_log in stream dispatcher was changed to the composite outbound address — revert to raw chat_id so structured log consumers are not surprised. Add thread_id field to all warn!/ debug! macros across delivery helpers so forum-topic failures can be correlated with the specific topic that failed. Entire-Checkpoint: 9302e4358187
Summary
target.outbound_to()(which encodeschat_id:thread_id) instead oftarget.chat_idin all outbound calls (send_text,send_html,send_media,send_text_silent,send_text_with_suffix,send_stream,send_location) so forum-topic replies land in the correct Telegram threadthread_idtoChannelReplyTargetKeyso stream-dedup distinguishes topics within the same supergroup — prevents silently skipping text delivery for topic B when topic A's stream completes firstFixes #442
Validation
Completed
cargo check -p moltis-chat— compiles cleancargo +nightly-2025-11-30 fmt --all -- --check— no formatting issuescargo clippy -p moltis-chat --all-targets -- -D warnings— no warningscargo test -p moltis-chat— all 151 tests passcargo test -p moltis-channels -- outbound_to— 2 tests passcargo test -p moltis-telegram -- topic— 5 tests passRemaining
./scripts/local-validate.shManual QA
🤖 Generated with Claude Code