Skip to content

fix(telegram): stop typing indicator from lingering after response delivery - #30732

Closed
mpesce wants to merge 1 commit into
NousResearch:mainfrom
mpesce:fix/telegram-typing-linger
Closed

fix(telegram): stop typing indicator from lingering after response delivery#30732
mpesce wants to merge 1 commit into
NousResearch:mainfrom
mpesce:fix/telegram-typing-linger

Conversation

@mpesce

@mpesce mpesce commented May 23, 2026

Copy link
Copy Markdown

Problem

Telegram shows a "typing..." indicator that persists for ~5 seconds after the agent response has already been delivered. This happens because:

  1. Telegram has no native "stop typing" API — the indicator self-expires after ~5s
  2. The gateway's _keep_typing() loop (in base.py) fires send_typing() every ~2s to keep the bubble alive during processing
  3. When the agent finishes and the response is delivered, the gateway calls adapter.stop_typing(chat_id) at gateway/run.py:8441
  4. For Telegram, this is a no-opTelegramAdapter inherits the base class's empty stop_typing()
  5. The _keep_typing background task is still alive — cancellation hasn't propagated yet
  6. One last send_typing() fires, resetting Telegram's 5s timer

Platforms with native stop-typing APIs (Slack, Signal, Matrix) override stop_typing() to actively clear the indicator. Telegram can't, but it can suppress the next refresh.

Fix

Add stop_typing() to TelegramAdapter that pauses the typing refresh loop using the existing _typing_paused mechanism from BasePlatformAdapter. No new infrastructure needed — _typing_paused already exists (line 1350), _keep_typing already checks it (line 2304), and the finally block already cleans it up (line 2349).

async def stop_typing(self, chat_id: str) -> None:
    self._typing_paused.add(chat_id)

Testing

Tested on systemd 259 (Ubuntu) with Telegram Bot API. After the fix, the typing indicator fades naturally within ~5s of the final send_typing() call rather than getting a late refresh after the response is already visible.

…livery

Telegram has no native 'stop typing' API — the indicator self-expires
after ~5s. The gateway's _keep_typing() loop fires send_typing() every
~2s, and a race condition causes one final refresh after the response
is already delivered, keeping the indicator alive for another 5s.

Add stop_typing() to TelegramAdapter using the existing _typing_paused
mechanism from the base adapter. The gateway already calls stop_typing()
at the right moment — this just gives Telegram an implementation that
pauses the refresh loop's last tick instead of inheriting the no-op.

The _typing_paused set and the _keep_typing check/finally cleanup are
already in BasePlatformAdapter — no new infrastructure needed.
@alt-glitch alt-glitch added type/bug Something isn't working platform/telegram Telegram bot adapter comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists labels May 23, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Competing with #29172 (comprehensive, all delivery paths + stream consumer) and #29595 (lightweight, reuses notify flag) — all three fix #29175. This approach is Telegram-specific using the existing _typing_paused mechanism.

@mpesce

mpesce commented May 23, 2026

Copy link
Copy Markdown
Author

Closing in favor of #29595 — the notify-flag approach is strictly better for Telegram: it prevents the re-arm before it happens rather than racing to suppress it after, avoids new infrastructure, and has regression tests. Three well-considered approaches for the same bug is a good sign for the project. Thanks for the review.

@mpesce

mpesce commented May 23, 2026

Copy link
Copy Markdown
Author

Closed in favor of #29595.

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.

2 participants