fix(gateway): clear typing indicator when cancel_session_processing gives up - #20696
Closed
vincent-wen789 wants to merge 1 commit into
Closed
fix(gateway): clear typing indicator when cancel_session_processing gives up#20696vincent-wen789 wants to merge 1 commit into
vincent-wen789 wants to merge 1 commit into
Conversation
…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.
2 tasks
Contributor
|
Thanks for tracing the orphaned typing-loop failure mode. The timeout cleanup gap still exists on current main ( Problems
Suggested changes
Automated hermes-sweeper review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When an agent processing task gets stuck in blocking I/O (e.g. a hung
web_extractcall lasting 961s), the inactivity watchdog fires,cancel_session_processingcancels the task, waits 5s, then unblocks dispatch — but the_keep_typingrefresh loop keeps running. The user sees an infinite "typing…" indicator in Telegram with no way to stop it short of restarting the gateway.Root cause: the cancelled task's finally block (which normally calls
_stop_typing_task) may never run when the task is wedged in C-level blocking I/O. The_keep_typingasyncio task continues its 2-second refresh cycle forever.Fix
In
cancel_session_processing, when the task refuses to unwind within the 5s window, proactively callinterrupt_session_activity(session_key, chat_id). This does two things:_keep_typingchecksstop_event.is_set()on each tick, so it exits within 2 secondsstop_typingon the adapter — platform-level cleanup (relevant for platforms with persistent typing loops like Discord/Slack)Also passes
chat_idthrough the existing call site in_handle_slash_commandso command-initiated session cancels (/new,/reset, etc.) get this cleanup too.Changes
gateway/platforms/base.py—cancel_session_processing: +21 lineschat_idparameter (backward compatible, defaults toNone)interrupt_session_activityifchat_idis provided_handle_slash_commandpassesevent.source.chat_idTesting
chat_idbehave identically