mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-24 05:41:40 +00:00
fix(gateway): align fallback delete with sibling style + add regression tests
Follow-up to HuangYuChuh's #17384 cherry-pick: - Use defensive getattr+logger.debug for delete_message lookup, mirroring the sibling _try_send_fresh_final cleanup pattern at L820+. Platforms that don't implement delete_message no longer raise AttributeError; the failure path now logs at debug for diagnosability instead of silently swallowing. - Add three regression tests in tests/gateway/test_stream_consumer.py: - delete_message awaited on happy-path exit with stale id - delete_message NOT awaited when no fallback chunks reached the user - no crash on adapters that lack delete_message (spec-restricted mock)
This commit is contained in:
parent
4eb8479ebd
commit
ec1fad3449
2 changed files with 86 additions and 7 deletions
|
|
@ -689,14 +689,20 @@ class GatewayStreamConsumer:
|
|||
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.
|
||||
# complete fallback response. Best-effort — if the platform doesn't
|
||||
# implement ``delete_message``, the delete fails (flood control still
|
||||
# active, bot lacks permission, message too old to delete), the
|
||||
# partial 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
|
||||
delete_fn = getattr(self.adapter, "delete_message", None)
|
||||
if delete_fn is not None:
|
||||
try:
|
||||
await delete_fn(self.chat_id, stale_message_id)
|
||||
except Exception as e:
|
||||
logger.debug(
|
||||
"Fallback partial cleanup failed (%s): %s",
|
||||
stale_message_id, e,
|
||||
)
|
||||
|
||||
self._message_id = last_message_id
|
||||
self._already_sent = True
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue