Skip to content

fix(gateway): stop typing indicator on Telegram after session completion - #20959

Closed
vincent-wen789 wants to merge 2 commits into
NousResearch:mainfrom
vincent-wen789:fix/telegram-typing-stuck
Closed

fix(gateway): stop typing indicator on Telegram after session completion#20959
vincent-wen789 wants to merge 2 commits into
NousResearch:mainfrom
vincent-wen789:fix/telegram-typing-stuck

Conversation

@vincent-wen789

Copy link
Copy Markdown

Summary

Fixes stuck typing indicator on Telegram that persists after normal session completion.

Problem

Two independent issues caused Telegram typing to stay visible indefinitely:

  1. Normal completion: _keep_typing is cancelled, but Telegram adapter had no stop_typing() implementation — the base class no-op left the typing bubble to expire on its own (~5s). Some Telegram clients cache the indicator state and never clear it.

  2. Dead-session timeout: cancel_session_processing gives up after 5s if the task is stuck in blocking I/O. Without the chat_id parameter, the interrupt event was never signaled, so _keep_typing kept refreshing the typing bubble every 2 seconds indefinitely.

Changes

gateway/platforms/telegram.py

  • Add stop_typing() implementation that sends choose_sticker chat action to supersede the typing action (Telegram has no explicit "cancel typing" API)
  • Non-fatal — if the API call fails, the bubble still expires within 5s once _keep_typing stops refreshing

gateway/platforms/base.py

Test Plan

  • Verified typing indicator clears after normal DM session completion (manual test on Telegram)
  • Gateway restart with changes confirmed stable

Related

wjameswen888 added 2 commits May 7, 2026 10:07
…ives up

When a background task is stuck in blocking I/O (e.g. a hung tool call),
cancel_session_processing waits 5s then unblocks dispatch — but the
_keep_typing refresh loop kept running, leaving an infinite 'typing…'
bubble on Telegram and other platforms.

Now, when the task refuses to unwind within the 5s window, proactively
call interrupt_session_activity — which sets the interrupt_event (so
_keep_typing exits on its next tick) and invokes stop_typing on the
adapter.

Also: pass chat_id through the existing call site in
_handle_slash_command to enable this cleanup on command-initiated
session cancels.
- Implement stop_typing() in TelegramAdapter using choose_sticker
  chat action to supersede the persistent typing indicator
- Without this, normal session completion leaves typing visible
  even after _keep_typing is cancelled (Telegram client caching)
- Complements the dead-session typing cleanup in cancel_session_processing
  (chat_id parameter + interrupt_session_activity on timeout)
@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter P2 Medium — degraded but workaround exists labels May 7, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This PR appears to supersede #20696 — the base.py changes are identical, and this PR adds the Telegram-specific stop_typing() implementation on top. Consider closing #20696 if this one is merged.

Related PRs addressing typing indicator issues: #19278, #20780.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for tracing the dead-session typing path. The timeout case still needs a fix, but this patch cannot land unchanged.

Problems

  • The added interrupt_session_activity() call would target the wrong event. _dispatch_active_session_command replaces self._active_sessions[session_key] with command_guard before it calls cancel_session_processing (PR-base gateway/platforms/base.py:2485-2487). interrupt_session_activity resolves its event from that mapping (gateway/platforms/base.py:3910-3913), while _keep_typing retains the original event as stop_event (gateway/platforms/base.py:4825,4841-4846).
  • choose_sticker is a Telegram activity action for an imminent sticker, not a cancellation action; it would show a different activity state rather than clear one.
  • Please add a regression test for a task that survives cancellation past the timeout. Current cleanup coverage only protects the normal refresh-cancellation path (tests/gateway/test_keep_typing_timeout.py:203-236).

Suggested changes

  • Preserve the original session event before installing command_guard, set that event on the timeout path, and use current main's _stop_typing_refresh cleanup rather than a Telegram-specific replacement action.

Automated hermes-sweeper review.

@teknium1 teknium1 added sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform area/sessions Session lifecycle, resume, persistence, history labels Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/sessions Session lifecycle, resume, persistence, history comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/telegram Telegram bot adapter sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants