Skip to content

fix(telegram): preserve auto-titled sessions and bind chat on switch (#121)#122

Closed
leshchenko1979 wants to merge 6 commits into
adolfousier:mainfrom
leshchenko1979:fix/telegram-session-121
Closed

fix(telegram): preserve auto-titled sessions and bind chat on switch (#121)#122
leshchenko1979 wants to merge 6 commits into
adolfousier:mainfrom
leshchenko1979:fix/telegram-session-121

Conversation

@leshchenko1979
Copy link
Copy Markdown
Contributor

@leshchenko1979 leshchenko1979 commented May 26, 2026

Summary

Fixes #121: Telegram DM sessions kept the default Telegram: DM … [chat:ID] title after auto-title ran, /sessions looked like duplicate rows, and switching felt broken.

Root cause: Label drift compared the full stored title to the default DM template on every message reuse. Auto-titled names were overwritten on message 2+; auto_title_attempted stayed true, so rename never retried.

Fix:

  • session_resolve::should_refresh_label — never clobber auto-titled / custom DM titles
  • handle_messagechat_sessions map first, then suffix fallback; idle timeout on bound path too
  • /new uses session_resolve::build_session_title
  • extra_sessions removed — see below

extra_sessions (guest switching)

Previously, guest /sessions switch wrote to a separate extra_sessions: HashMap<user_id, …> in agent.rs that was never read in handle_message. Owner and guest both already call register_session_chat(session_id, chat_id) on switch, which is what ingest uses.

This PR: remove the dead extra_sessions map; guest switching relies on chat_sessions only (same as owner). Test: register_session_chat_binds_guest_dm.


choose_resolve_source vs nested if let

Does not require a large refactor. Full replacement would mean: prefetch chat_session + bound row + suffix row, then match choose_resolve_source(…), moving ~80–120 lines in the session_id block — behavior-neutral, optional cleanup.

This PR keeps the existing structure and adds matches!(choose_resolve_source(…), ChatBound) on the bound branch so policy is checked at runtime and in unit tests. Suffix/create paths still use the same else block; policy is choose_resolve_source with suffix_match set (tests: archived_chat_map_entry_uses_suffix_not_bound, suffix_path_when_chat_map_empty).

A full match-based rewrite can be a follow-up PR if desired.


Test plan

cargo test telegram_session_resolve session_resolve::tests

Coverage includes: label drift, chat-bound idle archive+create, session_idle_expired boundaries, choose_resolve_source matrix, guest register_session_chat, suffix switch race.

Manual: /new → message → wait for auto-title → second message (title in /sessions must stay non-default) → /sessions switch to an older session → send a message and confirm that session’s context is used.

Label drift compared the full title to the default DM template on every
message, reverting auto-titled names after the second message (issue adolfousier#121).
Introduce session_resolve::should_refresh_label and prefer chat_sessions
map on ingest after /sessions switch.

Adds Rust tests, a Python TDD simulator (pytest -k production shows red),
and validate-hermes.sh for post-deploy checks.

Fixes adolfousier#121
…p Python sim

- Apply session_idle_expired to chat-bound path (parity with suffix resolve)
- Use session_resolve::build_session_title for /new
- Add choose_resolve_source + TelegramState policy tests
- Remove tools/telegram_session_sim from upstream (lives in vds/servers repo)
Document resolve policy in handler. Add chat_bound_idle integration test
and session_idle_expired boundary tests per review.
Guest session switch used register_session_chat only; extra_sessions map
was never read on ingest. Document choose_resolve_source on bound branch.
Sibling module was declared in mod.rs but not in scope for handler.rs.
@leshchenko1979
Copy link
Copy Markdown
Contributor Author

Superseded by a fresh PR from a squashed branch (clean history, same fix).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram session not auto-renaming on 0.3.28

2 participants