Skip to content

fix(gateway): restore Telegram DM topic isolation#40525

Open
konsisumer wants to merge 1 commit into
NousResearch:mainfrom
konsisumer:fix/telegram-root-dm-topic-mode-30411
Open

fix(gateway): restore Telegram DM topic isolation#40525
konsisumer wants to merge 1 commit into
NousResearch:mainfrom
konsisumer:fix/telegram-root-dm-topic-mode-30411

Conversation

@konsisumer

Copy link
Copy Markdown
Contributor

What changed and why

Per the reporter's clarification on 2026-06-06, this restores the expected Telegram DM topic flow in two places.

  • Make _recover_telegram_topic_thread_id() opt-in via gateway.platforms.telegram.extra.pin_root_dm_replies instead of always rewriting lobby-shaped root-DM replies to the most recent topic. This keeps fresh root-DM messages from being silently redirected into an older topic lane.
  • Auto-enable Telegram topic mode when _schedule_telegram_topic_title_rename() sees a real DM topic thread for the first time, so the existing rename pipeline can run even if /topic was never explicitly invoked beforehand.
  • Add regression coverage for both behaviors in tests/gateway/test_telegram_topic_mode.py.

Fixes #30411

Addressing maintainer feedback

This issue was previously tied to the #26609 / #28513 regression cluster, with #28605 called out as the canonical follow-up and #29287 / #29546 noted as duplicate fix PRs. The new 2026-06-06 followup added fresh, specific behavior that was still missing on main: opt-in root-DM pinning and lazy topic-mode seeding for auto-rename, so this PR implements that narrower follow-on instead of reopening any of those older branches.

How to test

  • Activate the repo venv and run pytest tests/gateway/test_telegram_topic_mode.py -q.
  • Verify test_recover_returns_none_without_opt_in_pinning keeps root-DM messages from being rebound when pin_root_dm_replies is unset.
  • Verify test_recover_rewrites_lobby_thread_id_to_most_recent still passes when pin_root_dm_replies is explicitly enabled.
  • Verify test_schedule_topic_rename_auto_enables_topic_mode_for_new_dm_topic proves the rename scheduler now seeds topic mode for a newly created DM topic lane.

What platforms tested on

  • Local macOS worker environment (focused pytest coverage only)
  • No live Telegram gateway manual run in this sandbox

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review Summary

Verdict: Approved

Small targeted DM-fix; changed area matches the title.

✅ Looks Good

  • Tight scope (1 changed file / +97 lines)
  • No stale debug artifacts or broad new surface area

Reviewed by Hermes Agent

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter labels Jun 6, 2026
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.

[Bug]: Telegram DM auto-topic-rename and tool-call routing broken by _recover_telegram_topic_thread_id()

3 participants