Skip to content

fix(gateway): stop typing before final delivery - #33606

Closed
zhonghui5207 wants to merge 1 commit into
NousResearch:mainfrom
zhonghui5207:codex/fix-typing-final-delivery-stop
Closed

fix(gateway): stop typing before final delivery#33606
zhonghui5207 wants to merge 1 commit into
NousResearch:mainfrom
zhonghui5207:codex/fix-typing-final-delivery-stop

Conversation

@zhonghui5207

@zhonghui5207 zhonghui5207 commented May 28, 2026

Copy link
Copy Markdown

Summary

  • Stop gateway typing refresh loops before final response delivery, so a late platform typing tick cannot outlive the completed reply.
  • Let GatewayStreamConsumer request typing stop as soon as the model stream finishes.
  • Keep a configurable HERMES_TYPING_MAX_SECONDS stale-loop guard as a final fallback.

Why

This salvages the core approach from #29172 onto current main and adds the max-lifetime guard we validated locally. It addresses the Telegram stuck typing family tracked in #28004 / #29175, where the agent has already finished and the reply is delivered but the platform still shows typing.

Local reproduction on current main before this patch:

  • 2026-05-28 10:05:53 agent turn ended with finish_reason=stop
  • 2026-05-28 10:05:54 gateway logged response ready for Telegram
  • user still saw Telegram typing much later, after the turn was no longer active

Changes

  • Add per-chat typing stop events in BasePlatformAdapter.
  • Use the per-chat stop event for _keep_typing instead of the session interrupt event.
  • Stop typing refresh before final text, TTS, images, media, and file delivery.
  • Signal typing stop from GatewayStreamConsumer when the stream receives DONE.
  • Add regression coverage for request_typing_stop and stream-finish typing stop handoff.

Validation

  • ./venv/bin/python -m pytest tests/gateway/test_keep_typing_timeout.py tests/gateway/test_stream_consumer.py -q
  • Result: 96 passed in 11.74s

Related

Fixes #28004.
Addresses #29175.
Supersedes / salvages #29172.
Related: #21688.

@zhonghui5207
zhonghui5207 marked this pull request as ready for review May 28, 2026 02:36
@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists labels May 28, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Salvage of #29172 (same author) onto current main with additional HERMES_TYPING_MAX_SECONDS stale-loop guard. Addresses the saturated typing indicator cluster: #28004, #29175, #25210, #21688, #24983, #20780, #20959.

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Thanks for this. A fix for the post-delivery typing-stop boundary in base.py has landed on main via #37556 (merged as 6a30cfca8): it moves _stop_typing_task() ahead of the post-delivery callback and bounds the callback with a timeout, which also closes the root-cause issue #24971.

This PR overlaps that area but also touches paths #37556 didn't (e.g. the stream-consumer / final-delivery path), so I'm not closing it — could you rebase on current main and let me know if there's still a residual gap your change covers after #37556? Happy to take the remaining delta as a focused follow-up if so.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the focused typing-lifecycle work. This is now implemented on current main; this is an automated hermes-sweeper review.

  • 09a96ba0f6ee68d701bd7c4fc2b2518a83b37c62 wires a one-shot Telegram pause_typing_for_chat() callback into both GatewayStreamConsumer construction paths (gateway/run.py:16745, gateway/run.py:18068) and runs it before finalization (gateway/stream_consumer.py:270). tests/gateway/test_stream_consumer.py:368 verifies the pause precedes the final edit.
  • 565b7c8d9d879c6423c55e9be84596936bc489ba prevents the final Telegram reply from re-arming its typing timer (plugins/platforms/telegram/adapter.py:3839), with regression coverage at tests/gateway/test_telegram_format.py:217.
  • The earlier post-delivery callback boundary noted in the discussion was also fixed by 6a30cfca82409cbf20b915c832a9acfb46551fe5 (gateway/platforms/base.py:5255).

The stream-finalize fix is contained in v2026.7.1.

@teknium1 teknium1 closed this Jul 13, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jul 13, 2026
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 sweeper:implemented-on-main Sweeper: behavior already present on current main type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram typing indicator stuck indefinitely after response (_keep_typing race condition)

4 participants