Skip to content

fix(telegram): route resumed DM topic sends directly#27937

Closed
Qwinty wants to merge 1 commit into
NousResearch:mainfrom
Qwinty:codex/telegram-dm-topic-resume-direct
Closed

fix(telegram): route resumed DM topic sends directly#27937
Qwinty wants to merge 1 commit into
NousResearch:mainfrom
Qwinty:codex/telegram-dm-topic-resume-direct

Conversation

@Qwinty

@Qwinty Qwinty commented May 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add direct_messages_topic_id to the base platform thread metadata for Telegram DM topics, matching the GatewayRunner metadata path
  • when a DM-topic reply fallback has no reply anchor, send with direct_messages_topic_id instead of dropping all topic kwargs
  • add regression coverage for resumed/synthetic DM-topic sends without reply anchors

Root cause

After a gateway shutdown/resume, the final response path goes through gateway/platforms/base.py::_thread_metadata_for_source. That helper marked Telegram private topics with telegram_dm_topic_reply_fallback, but it did not include direct_messages_topic_id. Resumed/synthetic events often have no message_id, so TelegramAdapter._thread_kwargs_for_send() returned {} for the no-anchor fallback path and delivered the response to the root DM / All Messages lane even though the session key still had the topic thread_id.

GatewayRunner._thread_metadata_for_source already had the direct-topic metadata path from the earlier synthetic/queued-message fix, but the base adapter helper and adapter no-anchor fallback were missing the same routing.

Related

Fixes #27139.
Related to #27114, #26945, #27462, and #27166.

This intentionally does not fall back to message_thread_id alone for the no-anchor case; live Telegram DM-topic replies still keep the reply-anchor route, while synthetic/resumed sends use direct_messages_topic_id when metadata has it.

Test plan

  • uv run --extra messaging pytest -o addopts= tests/gateway/test_telegram_thread_fallback.py::test_base_gateway_metadata_marks_telegram_dm_topics_as_reply_fallback tests/gateway/test_telegram_thread_fallback.py::test_base_gateway_metadata_for_resumed_telegram_dm_topic_uses_direct_topic tests/gateway/test_telegram_thread_fallback.py::test_send_private_dm_topic_uses_direct_messages_topic_id tests/gateway/test_telegram_thread_fallback.py::test_send_uses_reply_fallback_for_hermes_dm_topics tests/gateway/test_telegram_thread_fallback.py::test_send_dm_topic_fallback_without_anchor_does_not_crash -q

@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter P2 Medium — degraded but workaround exists labels May 18, 2026
@BoardJames-Bot

Copy link
Copy Markdown

BoardJames triage: this looks shared/systemic rather than branch-local. The PR-specific checks (lint/nix/e2e/builds/attribution/history) are green where completed; the remaining blocker is the main Tests / test job, which is currently failing/timing out across unrelated PRs and on main itself (latest main run hit the same aux/session_search + kanban dashboard + compression/Anthropic test drift). I pushed the missing aux/session_search default fix onto the existing systemic fix PR #27931 and validated the affected files locally (125 passed). Next action is maintainer review/workflow approval/merge of #27931, then rerun this PR's Tests / test; no branch-local author action is indicated from the logs I can see.

@teknium1

Copy link
Copy Markdown
Contributor

Merged — cherry-picked your commit onto current main with authorship preserved (rebase-merge). 35/35 thread-fallback tests passing. Docstring conflict resolved against the just-merged #24004 (reply_to_mode). Thanks.

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

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/telegram Telegram bot adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram DM topic messages leak to All Messages on synthetic events

4 participants