mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-19 04:52:06 +00:00
fix(stream-consumer): only confirm final delivery on successful best-effort send
The cancellation handler previously promoted any partial send (already_sent=True) to final_response_sent=True unconditionally. This meant if intermediate text (e.g. 'Let me search…') was streamed and the consumer was cancelled before delivering the actual answer, the gateway's suppression check would still prevent the fallback send. Now final_response_sent is only set in the cancellation path when: - The best-effort send of accumulated content actually succeeded, OR - It was already confirmed before cancellation Companion fix for PR #11000's run.py changes — closes the cancellation-path loophole that would otherwise let partial streams suppress final delivery during queued follow-ups.
This commit is contained in:
parent
35bbc6851b
commit
3b5572ded3
1 changed files with 10 additions and 8 deletions
|
|
@ -403,18 +403,20 @@ class GatewayStreamConsumer:
|
||||||
|
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
# Best-effort final edit on cancellation
|
# Best-effort final edit on cancellation
|
||||||
|
_best_effort_ok = False
|
||||||
if self._accumulated and self._message_id:
|
if self._accumulated and self._message_id:
|
||||||
try:
|
try:
|
||||||
await self._send_or_edit(self._accumulated)
|
_best_effort_ok = bool(await self._send_or_edit(self._accumulated))
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
# If we delivered any content before being cancelled, mark the
|
# Only confirm final delivery if the best-effort send above
|
||||||
# final response as sent so the gateway's already_sent check
|
# actually succeeded OR if the final response was already
|
||||||
# doesn't trigger a duplicate message. The 5-second
|
# confirmed before we were cancelled. Previously this
|
||||||
# stream_task timeout (gateway/run.py) can cancel us while
|
# promoted any partial send (already_sent=True) to
|
||||||
# waiting on a slow Telegram API call — without this flag the
|
# final_response_sent — which suppressed the gateway's
|
||||||
# gateway falls through to the normal send path.
|
# fallback send even when only intermediate text (e.g.
|
||||||
if self._already_sent:
|
# "Let me search…") had been delivered, not the real answer.
|
||||||
|
if _best_effort_ok and not self._final_response_sent:
|
||||||
self._final_response_sent = True
|
self._final_response_sent = True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Stream consumer error: %s", e)
|
logger.error("Stream consumer error: %s", e)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue