Skip to content

feat(telegram): sync auto-generated session titles to forum topic names - #16408

Closed
cola-runner wants to merge 1 commit into
NousResearch:mainfrom
cola-runner:codex/fix-16255-telegram-topic-title-sync
Closed

feat(telegram): sync auto-generated session titles to forum topic names#16408
cola-runner wants to merge 1 commit into
NousResearch:mainfrom
cola-runner:codex/fix-16255-telegram-topic-title-sync

Conversation

@cola-runner

Copy link
Copy Markdown
Contributor

Summary

Closes #16255. Connects two systems that were developed independently:

  • agent/title_generator.py generates a session title and saves it to SQLite.
  • gateway/platforms/telegram.py creates / tracks forum topics but never updates their names after creation.

After this PR, when a session title is auto-generated or set manually via /title, the corresponding Telegram forum topic name is updated via editForumTopic so the topic list and /history stay in sync.

Architecture

Three small layers, no behaviour change for non-Telegram platforms:

  1. BasePlatformAdapter.update_topic_title — new async hook, default no-op. Platforms with per-thread titles override it. Errors must be swallowed by the implementation — title sync is best-effort UX.
  2. TelegramAdapter.update_topic_title — calls editForumTopic with the new name, truncates to Telegram's 128-char limit, skips the implicit "General" topic (its name is owned by the chat, not the bot), DEBUG-logs Bot API failures, and re-aligns the local _dm_topics cache so /resume lookups by name still find the renamed topic.
  3. title_generator — adds an on_title_set callback that fires after the new title is persisted to SQLite. Callback exceptions are swallowed so a flaky platform call can't crash the daemon worker.

Sync→async bridge

maybe_auto_title runs in a daemon threading.Thread, so we hop back to the gateway loop via asyncio.run_coroutine_threadsafe:

  • GatewayRunner._make_topic_title_sync_callback builds the callback (skipping early when the source has no thread_id — most non-forum chats).
  • GatewayRunner._sync_topic_title_to_platform looks up the right adapter and awaits its update_topic_title.

The /title command reuses the same _sync_topic_title_to_platform so manual renames push to the platform immediately.

Files

  • gateway/platforms/base.py — new update_topic_title no-op default
  • gateway/platforms/telegram.py — Telegram override + cache realignment
  • agent/title_generator.pyon_title_set callback through maybe_auto_title / auto_title_session
  • gateway/run.py — gateway helpers + wires both auto-title and /title
  • tests/agent/test_title_generator.py — 5 new tests for the callback
  • tests/gateway/test_telegram_topic_title.py — 13 new tests for the override

Test plan

  • pytest tests/agent/test_title_generator.py tests/gateway/test_telegram_topic_title.py tests/gateway/test_telegram_format.py — 125 passed locally
  • No-op for non-Telegram adapters (covered by base test)
  • Cache stays consistent across renames (covered)
  • Bot API errors don't propagate (covered)
  • Truncation to 128-char Telegram limit (covered)

@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/gateway Gateway runner, session dispatch, delivery comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint platform/telegram Telegram bot adapter labels Apr 27, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #9921 — same feature: auto-rename Telegram forum topics on session title change. Both close #16255.

@alt-glitch alt-glitch added the duplicate This issue or pull request already exists label Apr 27, 2026
Hermes auto-generates a session title via ``agent/title_generator.py``
and saves it to SQLite, but never propagates the change to the
corresponding Telegram forum topic.  Users with many concurrent topics
can't tell them apart in the Telegram sidebar — every topic stays
named "New Session" forever while ``/history`` shows the real title.

This wires the two systems together with three small layers:

- ``BasePlatformAdapter.update_topic_title`` — new optional async hook,
  default no-op.  Platforms with per-thread titles override it.
- ``TelegramAdapter.update_topic_title`` — calls ``editForumTopic`` with
  the new name (truncated to Telegram's 128-char cap), skips the
  General topic, swallows API errors at DEBUG, and keeps the local
  ``_dm_topics`` cache aligned so ``/resume``-style lookups by name
  still find the renamed topic.
- ``title_generator`` — adds an ``on_title_set`` callback that fires
  *after* the new title is persisted to SQLite.  Callback exceptions
  are swallowed so a flaky platform call can't crash the worker thread.
- ``GatewayRunner._sync_topic_title_to_platform`` and
  ``_make_topic_title_sync_callback`` bridge the auto-title daemon
  thread back to the gateway event loop via
  ``run_coroutine_threadsafe``.  Wired into both auto-title and the
  ``/title`` command so manual renames sync immediately.

Closes NousResearch#16255.
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the Telegram topic-title synchronization work. The member duplicate note linking #9921 was correct: current main now provides the requested behavior through a more guarded, current gateway implementation.

Automated hermes-sweeper review evidence:

  • agent/title_generator.py:154 persists an auto-generated title before invoking title_callback; gateway/run.py:19015 wires that callback for Telegram topic lanes.
  • gateway/run.py:13612 performs the guarded best-effort rename, including topic/session binding validation, operator-topic preservation, and disable_topic_auto_rename support; gateway/run.py:13720 schedules it safely from the title worker.
  • gateway/slash_commands.py:3487 sends successful manual /title updates through the same scheduler. This shipped in 38f1a923af6e77cad16a4a270c74f79847311c2b (v2026.7.1).
  • Regression coverage is present in tests/gateway/test_telegram_topic_mode.py:889 and tests/gateway/test_title_command.py:173.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/gateway Gateway runner, session dispatch, delivery duplicate This issue or pull request already exists P3 Low — cosmetic, nice to have platform/telegram Telegram bot adapter sweeper:implemented-on-main Sweeper: behavior already present on current main type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Sync auto-generated session titles to Telegram forum topic names via editForumTopic

3 participants