Skip to content

fix(telegram): refresh topic binding on compression session split#23244

Closed
devsart95 wants to merge 1 commit into
NousResearch:mainfrom
devsart95:fix/telegram-topic-binding-20470
Closed

fix(telegram): refresh topic binding on compression session split#23244
devsart95 wants to merge 1 commit into
NousResearch:mainfrom
devsart95:fix/telegram-topic-binding-20470

Conversation

@devsart95

Copy link
Copy Markdown

Summary

When context compression splits a Telegram DM topic session, the gateway updates session_store._entries[session_key].session_id to the new child session, but does not refresh the separate SQLite topic binding (telegram_dm_topic_bindings).

Root cause

In gateway/run.py:_run_agent(), after detecting a session split during compression:

if entry:
    entry.session_id = agent.session_id
    self.session_store._save()
    # ❌ No call to _record_telegram_topic_binding()

On the next inbound message in that topic, the binding lookup at the top of _handle_message_with_agent resolves to the stale parent session_id, switching the lane back to the pre-compression transcript. This causes repeated preflight compression loops on every subsequent message.

Fix

After updating session_store, also call _record_telegram_topic_binding() when the source is a Telegram topic lane. This mirrors the existing fix for /new (line 7721-7725) which already rebinds the topic after explicit session resets.

Files changed

  • gateway/run.py — +15 lines after the existing session-store update block

Fixes #20470

X: @rojassartorio

When context compression splits a Telegram DM topic session, the gateway
correctly updates session_store._entries[session_key].session_id to the
new child session, but does NOT refresh the separate SQLite topic binding
(telegram_dm_topic_bindings). On the next inbound message in that topic,
the binding resolves to the stale parent session_id, causing the gateway
to switch back to the pre-compression transcript — leading to repeated
preflight compression loops.

Fix: call _record_telegram_topic_binding() after updating session_store
when a compression split is detected in a Telegram topic lane.

This mirrors the existing fix for /new at gateway/run.py:7721-7725 which
already rebinds the topic after explicit session reset.

Fixes NousResearch#20470

X: @rojassartorio

Co-authored-by: Rojas Sartorio <rojassartorio@users.noreply.github.com>
@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 duplicate This issue or pull request already exists labels May 10, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #20485 — 4th competing fix for #20470 (Telegram DM topic binding not refreshed after compression-induced session split). Open PRs: #20485 (earliest), #23195, and now this.

@teknium1

Copy link
Copy Markdown
Contributor

Automated hermes-sweeper review: this PR's Telegram topic-binding fix has already landed on current main via a broader implementation.

Evidence:

  • Main contains db96fc60d0d3dc3f9e95dc6541d8edcccb2f2171 (fix(gateway): keep Telegram topic bindings aligned with compression children (#34409)), which explicitly fixes the stale Telegram DM topic binding after compression and closes [Bug] Telegram DM topic binding not refreshed after compression-induced session split — causes preflight compression loop #20470.
  • gateway/run.py:2641 defines _sync_telegram_topic_binding() for the exact stale parent-binding failure mode described here.
  • gateway/run.py:8570 refreshes the binding after an agent-result compression session_id rotation.
  • gateway/run.py:7854 also heals existing stale bindings by walking SessionDB.get_compression_tip() and rewriting the topic binding to the child session.
  • tests/gateway/test_telegram_topic_mode.py:452 covers the regression: a stale parent binding is advanced to the compression child on the next inbound topic message.
  • The fix is included in v2026.6.5.

Thanks for the duplicate fix attempt here; the maintainer discussion correctly identified this as one of several competing fixes for #20470, and the merged mainline fix covers the behavior this PR was targeting.

@teknium1 teknium1 closed this Jun 11, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jun 11, 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 duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists platform/telegram Telegram bot adapter sweeper:implemented-on-main Sweeper: behavior already present on current main type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Telegram DM topic binding not refreshed after compression-induced session split — causes preflight compression loop

3 participants