Skip to content

fix(gateway): preserve new Telegram DM topic lanes#31444

Merged
teknium1 merged 2 commits into
mainfrom
hermes/hermes-eb168c5c
May 24, 2026
Merged

fix(gateway): preserve new Telegram DM topic lanes#31444
teknium1 merged 2 commits into
mainfrom
hermes/hermes-eb168c5c

Conversation

@teknium1

@teknium1 teknium1 commented May 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Brand-new Telegram DM topics no longer get hijacked into the previous topic's session. _recover_telegram_topic_thread_id now only rewrites lobby/General thread_ids (preserving the #3206 strip recovery); any explicit, non-lobby thread_id is trusted as-is so a freshly-created topic can be recorded as its own lane.

Root cause (#31086): the recovery function ran before _record_telegram_topic_binding, and its "unknown non-lobby thread_id -> snap to most-recent" arm matched every new topic. The hijack was self-reinforcing because the new topic's binding row was never written, so every subsequent message looked unknown and was hijacked again.

Changes

  • gateway/run.py: drop the inbound in known short-circuit; non-lobby thread_ids return None unconditionally. Docstring rewritten.
  • tests/gateway/test_telegram_topic_mode.py: invert the existing test_recover_rewrites_unknown_thread_id_to_most_recent -> test_recover_preserves_unknown_thread_id_for_new_topic, plus a new test_recover_returns_none_for_brand_new_topic regression that mirrors the live failure mode (one prior binding + a brand-new thread_id).
  • tests/gateway/test_telegram_thread_fallback.py: stub _fake_telegram_ext.TypeHandler so the shared fake module covers all handler classes the real telegram-ext exposes.

Validation

Result
tests/gateway/test_telegram_topic_mode.py 43/43 pass
tests/gateway/test_telegram_thread_fallback.py 41/41 pass
tests/gateway/ (full suite) 5820/5820 pass

Credit

Closes #31086.
Supersedes #28605, #29287, #29546, #30422, #31088.

Infographic

Telegram DM topic hijack fix

@github-actions

github-actions Bot commented May 24, 2026

Copy link
Copy Markdown
Contributor

🔎 Lint report: hermes/hermes-eb168c5c vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 9092 on HEAD, 9089 on base (🆕 +3)

🆕 New issues (2):

Rule Count
unresolved-attribute 1
invalid-argument-type 1
First entries
tests/gateway/test_telegram_thread_fallback.py:101: [unresolved-attribute] unresolved-attribute: Unresolved attribute `TypeHandler` on type `ModuleType`
tests/gateway/test_telegram_topic_mode.py:1229: [invalid-argument-type] invalid-argument-type: Argument to bound method `SessionDB.bind_telegram_topic` is incorrect: Expected `str`, found `str | None`

✅ Fixed issues: none

Unchanged: 4840 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@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 May 24, 2026
Qwinty and others added 2 commits May 24, 2026 15:03
The cherry-picked fix from #28605 inverts an existing test (an unknown
non-lobby thread_id no longer rewrites to the most-recent binding), but
that test only seeds two bindings and queries a third thread_id. Add a
second regression test that more closely mirrors the live failure mode:
seed exactly one prior binding, then query a brand-new thread_id and
assert recovery returns None — so the new topic is allowed to get its
own session row instead of being silently merged into the previous
topic's session.

Co-authored-by: Fábio Siqueira <fabioxxx@gmail.com>
Co-authored-by: dillweed <dillweed@users.noreply.github.com>
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] _recover_telegram_topic_thread_id hijacks every brand-new Telegram DM topic into the previous topic

3 participants