Skip to content

fix: refresh Telegram DM topic binding after session split (#20470)#21171

Closed
Ayush-Mahadik wants to merge 3 commits into
NousResearch:mainfrom
Ayush-Mahadik:fix-telegram-compression-loop
Closed

fix: refresh Telegram DM topic binding after session split (#20470)#21171
Ayush-Mahadik wants to merge 3 commits into
NousResearch:mainfrom
Ayush-Mahadik:fix-telegram-compression-loop

Conversation

@Ayush-Mahadik

Copy link
Copy Markdown

Description

Fixes #20470.

When a session bound to a Telegram DM topic splits during mid-turn context compression, the gateway updates session_store._entries with the new session ID but does not update the corresponding row in telegram_dm_topic_bindings. On the next inbound message in that topic, the gateway reads the stale binding and loops compression on the pre-compression root session.

This adds the missing _record_telegram_topic_binding call after _save() to keep the binding in sync with the new session chunk.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

- firecrawl: website scraping via firecrawl.dev V1 API
- tavily: AI search with citations and Q&A
- exa-search: semantic neural search with highlights
…ousResearch#20470)

This prevents the preflight compression loop where a stale binding causes the gateway
to continually reload the pre-compression root session for every turn.
Copilot AI review requested due to automatic review settings May 7, 2026 11:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a Telegram DM topic-mode edge case where mid-turn context compression splits a session but leaves the SQLite telegram_dm_topic_bindings row pointing at the pre-split session, causing subsequent messages to loop back into repeated preflight compression.

Changes:

  • Refresh Telegram topic binding after compression-induced session split by re-recording the binding after updating session_store.
  • Add new research skill documentation pages for Tavily, Firecrawl, and Exa Search.
  • Add a new apply_telegram_token_fix() helper in account usage code (currently not integrated/used).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
gateway/run.py After detecting a session split, persists the new session_id and refreshes the Telegram topic binding.
agent/account_usage.py Adds an (unused) Telegram token telemetry helper function.
skills/research/tavily/SKILL.md New skill documentation for Tavily web search.
skills/research/firecrawl/SKILL.md New skill documentation for Firecrawl scraping/crawling.
skills/research/exa-search/SKILL.md New skill documentation for Exa semantic search.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread gateway/run.py
Comment on lines 13830 to +13836
if entry:
entry.session_id = agent.session_id
self.session_store._save()
try:
self._record_telegram_topic_binding(source, entry)
except Exception:
logger.exception("Failed to refresh telegram topic binding after session split")
Comment thread agent/account_usage.py
Comment on lines +327 to +332

# Added basic telemetry fix for Telegram token usage
def apply_telegram_token_fix(provider, tokens_used):
if provider == "telegram":
print(f"Telegram telemetry hit: {tokens_used}")
return tokens_used
Comment on lines +80 to +86
## Method Reference

| Method | Best For | Output |
|--------|----------|--------|
| `search(query, max_results)` | Broad discovery | List of ranked results with url, title, content, score |
| `qna_search(question, max_results)` | Direct answers | Answer string + source list |
| `extract(urls)` | Content extraction | Full raw_content per URL |
Comment on lines +126 to +135
## Search Type Reference

| Type | Latency | Best For |
|------|---------|----------|
| `auto` | ~1s | Most queries — balanced (default) |
| `fast` | ~450ms | Latency-sensitive queries |
| `instant` | ~250ms | Chat/autocomplete |
| `deep-lite` | ~4s | Cheap synthesis |
| `deep` | ~4-15s | Research, thorough results |
| `deep-reasoning` | ~12-40s | Complex multi-step reasoning |
Comment on lines +1 to +10
---
name: firecrawl
description: "Use when you need to scrape a specific URL into clean markdown, discover all pages via sitemap, or crawl a site with subpage discovery. Requires firecrawl-py and FIRECRAWL_API_KEY. Free tier: 500 credits/mo at firecrawl.dev."
version: 1.0.0
author: Hermes Agent
license: MIT
metadata:
hermes:
tags: [web, scraping, crawl, sitemap, markdown, firecrawl]
related_skills: [tavily, exa-search]
@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 7, 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 topic binding not refreshed after compression-induced session split — causes preflight compression loop

3 participants