Typing indicators lingering or sticking after replies (Discord, Telegram, Teams)
Cluster 2831 · gateway · Bug. Data as of
5 open items. Fix merged in #44836 on 12 Jun 2026. Check it covers your case.
The short answer
- Known?
- Yes. 31 related items grouped here, 11 issues already closed.
- Fix event
- A fix was merged to main in PR #44836. Check it covers your case. No release data is tracked. Fix link checked: 10 Nov 2026.
Most members concern typing indicators that continue after a response is sent, often linked to a suspected race or orphaned _keep_typing task in gateway code. They span Discord, Telegram, and Teams, and include both bug reports and proposed fixes such as lifetime caps, cancellation ordering, and skipping typing for internal events.
Open issues0
Open PRs5
- PR#21688fix(telegram): stop typing refresh before response
- PR#29172fix(gateway): stop typing indicator before final response delivery
- PR#33631fix(telegram): stop typing after final reply
- PR#41258fix(telegram): pause notify typing during flood-control sends (#41168)
- PR#42129fix(gateway): skip typing indicator for internal/synth events
Fixes on record
-
#3003 fix(discord): stop phantom typing indicator after agent turn completes
files:
gateway/platforms/base.pyShow the diff
-
gateway/platforms/base.py@@ -819,6 +819,16 @@ async def _keep_typing(self, chat_id: str, interval: float = 2.0, metadata=None) await asyncio.sleep(interval) except asyncio.CancelledError: pass # Normal cancellation when handler completes + finally: + # Ensure the underlying platform typing loop is stopped. + # _keep_typing may have called send_typing() after an outer + # stop_typing() cleared the task dict, recreating the loop. + # Cancelling _keep_typing alone won't clean that up. + if hasattr(self, "stop_typing"): + try: + await self.stop_typing(chat_id) + except Exception: + pass async def handle_message(self, event: MessageEvent) -> None: """ @@ -1130,6 +1140,13 @@ async def _process_message_background(self, event: MessageEvent, session_key: st await typing_task except asyncio.CancelledError: pass + # Also cancel any platform-level persistent typing tasks (e.g. Discord) + # that may have been recreated by _keep_typing after the last stop_typing() + try: + if hasattr(self, "stop_typing"): + await self.stop_typing(event.source.chat_id) + except Exception: + pass # Clean up session tracking if session_key in self._active_sessions: del self._active_sessions[session_key]
-
-
#44836 fix: stop Discord typing after replies
files:
gateway/platforms/base.py,scripts/release.py,tests/gateway/test_keep_typing_timeout.py,tests/gateway/test_run_progress_topics.pyShow the diff
-
gateway/platforms/base.py@@ -3163,6 +3163,38 @@ async def _keep_typing( pass self._typing_paused.discard(chat_id) + async def _stop_typing_refresh( + self, + chat_id: str, + typing_task: asyncio.Task | None = None, + *, + timeout: float = 0.5, + stop_attempts: int = 2, + ) -> None: + """Stop the refresh task and platform typing state as one operation.""" + self._typing_paused.add(chat_id) + try: + if typing_task is not None and not typing_task.done(): + typing_task.cancel() + try: + await asyncio.wait_for(asyncio.shield(typing_task), timeout=timeout) + except (asyncio.CancelledError, asyncio.TimeoutError): + # The task is cancelled; don't let a slow adapter-specific + # cleanup block response delivery or shutdown. + pass + if not hasattr(self, "stop_typing"): + return + attempts = max(1, stop_attempts) + for attempt in range(attempts): + try: + await self.stop_typing(chat_id) + except Exception: + pass + if attempt < attempts - 1: + await asyncio.sleep(0) + finally: + self._typing_paused.discard(chat_id) + def pause_typing_for_chat(self, chat_id: str) -> None: """Pause typing indicator for a chat (e.g. during approval waits). @@ -4092,14 +4124,10 @@ def _record_delivery(result): ) async def _stop_typing_task() -> None: - typing_task.cancel() - try: - await asyncio.wait_for(asyncio.shield(typing_task), timeout=0.5) - except (asyncio.CancelledError, asyncio.TimeoutError): - # Cancellation cleanup must not block adapter shutdown. The - # typing task is already cancelled; if the parent task is also - # cancelling, let this message-processing task unwind now. - pass + await self._stop_typing_refresh( + event.source.chat_id, + typing_task, + ) try: await self._run_processing_hook("on_processing_start", event) @@ -4486,11 +4514,6 @@ async def _stop_typing_task() -> None: # callbacks may perform platform I/O; a stuck callback must not # leave the typing refresh task running indefinitely. await _stop_typing_task() - try: - if hasattr(self, "stop_typing"): - await self.stop_typing(event.source.chat_id) - except Exception: - pass # Fire any one-shot post-delivery callback registered for this # session (e.g. deferred background-review notifications). # @@ -4524,13 +4547,14 @@ async def _stop_typing_task() -> None: ) except (asyncio.TimeoutError, Exception): pass - # Also cancel any platform-level persistent typing tasks (e.g. Discord) - # that may have been recreated by _keep_typing after the last stop_typing() - try: - if hasattr(self, "stop_typing"): - await self.stop_typing(event.source.chat_id) - except Exception: - pass + # Some adapters keep platform-level typing tasks. If callback + # work or a late refresh recreated one, make one final bounded stop + # before releasing the session guard. + await self._stop_typing_refresh( + event.source.chat_id, + None, + stop_attempts=1, + ) # Final drain/release boundary: force-flush any timer that missed # the in-band drain before deciding whether the guard can clear. await self._flush_text_debounce_now(session_key) -
scripts/release.py@@ -75,6 +75,7 @@ "[redacted:email]": "harjothkhara", "[email protected]": "HeLLGURD", "[email protected]": "synapsesx", + "[email protected]": "itsflownium", "[email protected]": "dirtyren", "[redacted:email]": "kdunn926", "[redacted:email]": "mvanhorn", -
tests/gateway/test_keep_typing_timeout.py@@ -198,3 +198,39 @@ async def recording_send_typing(chat_id, metadata=None): assert calls == [], ( f"send_typing was called on a paused chat: {calls}" ) + + @pytest.mark.asyncio + async def test_stop_typing_refresh_blocks_late_cancel_tick(self, monkeypatch): + """Final cleanup must not let a cancelled refresh loop send typing again.""" + adapter = _StubAdapter() + late_sends = [] + stop_calls = [] + + async def send_typing(chat_id, metadata=None): + late_sends.append(chat_id) + + async def stop_typing(chat_id): + stop_calls.append((chat_id, chat_id in adapter._typing_paused)) + + monkeypatch.setattr(adapter, "send_typing", send_typing) + monkeypatch.setattr(adapter, "stop_typing", stop_typing) + + async def late_refresh_after_cancel(): + try: + await asyncio.sleep(10) + except asyncio.CancelledError: + if "discord-chat" not in adapter._typing_paused: + await adapter.send_typing("discord-chat") + raise + + task = asyncio.create_task(late_refresh_after_cancel()) + await asyncio.sleep(0) + + await adapter._stop_typing_refresh("discord-chat", task, timeout=1.0) + + assert late_sends == [] + assert stop_calls == [ + ("discord-chat", True), + ("discord-chat", True), + ] + assert "discord-chat" not in adapter._typing_paused -
tests/gateway/test_run_progress_topics.py@@ -1121,7 +1121,15 @@ async def _stop_typing(chat_id): ) assert [call["content"] for call in adapter.sent] == ["done"] - assert events[:2] == ["typing-stopped", "callback-start"] + # Invariant: typing must stop before the (hung) post-delivery callback + # starts. Don't pin the exact stop_typing call count — the shared + # cleanup path may make more than one bounded stop attempt. + assert "typing-stopped" in events + assert "callback-start" in events + assert events.index("typing-stopped") < events.index("callback-start") + assert events[: events.index("callback-start")] == ( + ["typing-stopped"] * events.index("callback-start") + ) assert any(call["metadata"] == {"stopped": True} for call in adapter.typing)
-
-
#151854 fix(gateway): drain keeps inbound, keepalive=0 works, session chat 409s, typing loop stops (#143122, #126052, #150153, #62394, #89615)
files:
contributors/emails/[email protected],gateway/platforms/_http_client_limits.py,gateway/platforms/api_server.py,gateway/platforms/base.py,gateway/run_runtime.py,plugins/platforms/slack/adapter.py,plugins/platforms/slack/adapter_socket_lifecycle.py,plugins/platforms/telegram/telegram_held_inbound.py,tests/gateway/test_api_session_chat_store_error.py,tests/gateway/test_keep_typing_timeout.py,tests/gateway/test_platform_http_client_limits.py,tests/gateway/test_runtime_bootstrap_lifecycle.py,tests/gateway/test_slack_socket_reconnect_heal.py,tests/plugins/platforms/telegram/test_stop_inbound.py
12 PRs closed without merging
From the close comments: done elsewhere 6 · merged via another change 2 · superseded by another PR 2 · other 2
-
#2832 fix(discord): cancel platform-level typing tasks in base.py finally block · merged via another change →
#3003,#2945 -
#26838 fix(discord): cap typing indicator loop lifetime · done elsewhere →
331cb38 -
#26857 fix(discord): single-shot send_typing to kill stuck typing indicator race (closes #26854) · done elsewhere →
331cb38 -
#30732 fix(telegram): stop typing indicator from lingering after response delivery · superseded by another PR →
#29595 -
#33606 fix(gateway): stop typing before final delivery · done elsewhere →
09a96ba,565b7c8,6a30cfc
Show 7 more
-
#41240 fix(gateway): cap typing indicator lifetime (#41168) · done elsewhere →
565b7c8,#41168 - #41306 fix(gateway): set stop_event before cancelling typing task (#41168) · other
-
#41308 fix(telegram): don't re-trigger typing indicator after last chunk · done elsewhere →
565b7c8,#41491 -
#42131 fix(gateway): suppress ghost typing indicator after final response on Telegram · done elsewhere →
565b7c8 -
#43691 fix(gateway): prevent orphaned Discord typing loops · superseded by another PR →
#44836 -
#44740 fix: stop Discord typing after replies · merged via another change →
331cb38,#44836 -
#54544 fix(telegram): override stop_typing to clear stuck typing indicator (Fixes #28004) · other →
565b7c8,09a96ba
Closed issues · 11
- Closed#2831Discord typing indicator lingers after response due to race between base.py _keep_typing and _typing_tasks
- Closed#26728[Bug]: Discord typing indicator can get stuck forever during/after long replies
- Closed#26854Discord typing indicator stuck indefinitely due to race condition in _keep_typing cleanup
- Closed#28004Telegram typing indicator stuck indefinitely after response (_keep_typing race condition)
- Closed#29175[Bug]: Typing indicator lingers ~5s after streamed reply finishes
- Closed#41168Telegram typing indicator persists after background process notification under flood control
- Closed#42087Bug: Ghost typing indicator on Telegram after background process / synth_event delivery
- Closed#44677Bug: Typing indicator persists after response is sent (Discord)
- Closed#47539Telegram typing indicator stuck infinitely (orphaned _keep_typing task)
- Closed#50991Orphaned _keep_typing task persists Telegram typing indicator after agent cache idle-eviction
- Closed#62394Teams: typing indicator animates forever after responses complete — suspected leaked _keep_typing task
How this cluster was grouped
-
Link evidence (
partly structural links): some members are connected by structural evidence (shared changed files, or a closing/superseded reference); the rest are joined by an automated relevance judgement over their text. - Members outside that structural core may belong to a different underlying problem.
-
Pairwise link density
0.06: the share of item pairs that carry a link, counting a structural link in full and a relevance-only link at 0.36.1.00means every pair is linked.