Skip to content

fix(gateway): restore Telegram DM topic thread_id after session split (closes #27166)#28524

Merged
teknium1 merged 2 commits into
mainfrom
hermes/hermes-6063e704
May 19, 2026
Merged

fix(gateway): restore Telegram DM topic thread_id after session split (closes #27166)#28524
teknium1 merged 2 commits into
mainfrom
hermes/hermes-6063e704

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Salvage of #27239 (@jackjin1997). After mid-turn context compression splits a session, the final response was routing to the General thread instead of the original Telegram DM topic. Now source.thread_id is recovered from the topic binding (reverse lookup by session_id, using the existing UNIQUE INDEX) so _thread_metadata_for_source produces the right message_thread_id.

Conflict resolution: kept both list_telegram_topic_bindings_for_chat (from #28488 salvage) AND new get_telegram_topic_binding_by_session — they serve different purposes.

Authorship preserved via cherry-pick. 42/42 topic-mode tests passing.

jackjin1997 and others added 2 commits May 18, 2026 22:41
…#27166)

When context compression triggers a mid-turn session split, source.thread_id
can be None on synthetic/recovered events. _thread_metadata_for_source then
returns None, causing the Telegram adapter to send with no message_thread_id
and the response lands in the General thread instead of the active DM topic.

Fix:
- hermes_state.py: Add get_telegram_topic_binding_by_session() for reverse
  lookup by session_id (enabled by the existing UNIQUE INDEX on session_id).
- gateway/run.py: After session-split detection, if source is a Telegram DM
  and source.thread_id is None, recover it from the binding via the new
  method so _thread_metadata_for_source produces the correct thread routing.
- tests/: Coverage for the new lookup method and the recovery flow.
@teknium1 teknium1 merged commit 721d47f into main May 19, 2026
@teknium1 teknium1 deleted the hermes/hermes-6063e704 branch May 19, 2026 05:42
@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: hermes/hermes-6063e704 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: 8933 on HEAD, 8931 on base (🆕 +2)

🆕 New issues (1):

Rule Count
invalid-argument-type 1
First entries
gateway/run.py:16562: [invalid-argument-type] invalid-argument-type: Argument to bound method `SessionDB.get_telegram_topic_binding_by_session` is incorrect: Expected `str`, found `object`

✅ Fixed issues: none

Unchanged: 4679 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 platform/telegram Telegram bot adapter comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists labels May 19, 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.

3 participants