mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-18 04:41:56 +00:00
fix(gateway): delete partial message after fallback send on flood control
When Telegram flood control triggers 3+ consecutive edit failures, the stream consumer enters fallback mode and sends the complete response as a new message. This leaves the user seeing two messages: a frozen partial (with cursor) and the full duplicate. After the fallback chunks are sent successfully, delete the original partial message so the user only sees one complete response. The delete is best-effort — if it fails (e.g. flood still active, missing permissions), the full answer is still delivered. Fixes #16668
This commit is contained in:
parent
cdb6e5e52a
commit
4eb8479ebd
1 changed files with 11 additions and 0 deletions
|
|
@ -640,6 +640,7 @@ class GatewayStreamConsumer:
|
|||
safe_limit = max(500, raw_limit - 100)
|
||||
chunks = self._split_text_chunks(continuation, safe_limit)
|
||||
|
||||
stale_message_id = self._message_id # partial message to clean up
|
||||
last_message_id: Optional[str] = None
|
||||
last_successful_chunk = ""
|
||||
sent_any_chunk = False
|
||||
|
|
@ -687,6 +688,16 @@ class GatewayStreamConsumer:
|
|||
# so any stale tool-progress bubble gets closed off.
|
||||
self._notify_new_message()
|
||||
|
||||
# Remove the frozen partial message so the user only sees the
|
||||
# complete fallback response. Best-effort — if the delete fails
|
||||
# (e.g. flood control still active, or bot lacks permission), the
|
||||
# partial message remains but at least the full answer was delivered.
|
||||
if stale_message_id and stale_message_id != last_message_id:
|
||||
try:
|
||||
await self.adapter.delete_message(self.chat_id, stale_message_id)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
self._message_id = last_message_id
|
||||
self._already_sent = True
|
||||
self._final_response_sent = True
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue