Skip to content

fix(gateway): flush undelivered tail before segment reset (#8124)#12414

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-a845df96
Apr 19, 2026
Merged

fix(gateway): flush undelivered tail before segment reset (#8124)#12414
teknium1 merged 1 commit into
mainfrom
hermes/hermes-a845df96

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Text generated between a mid-stream edit failure and a tool boundary is no longer silently dropped. Root cause: _reset_segment_state() on a tool boundary wiped _accumulated even when the most recent edit had failed, discarding un-delivered content.

The fix flushes the undelivered tail as a continuation message before the segment reset, computed relative to the last successfully-delivered prefix so it doesn't duplicate what the user already saw. Best-effort cursor strip on the partial message is also attempted when fallback mode hasn't already done so.

Changes

  • gateway/stream_consumer.py — new _flush_segment_tail_on_edit_failure() helper called before _reset_segment_state() on segment breaks, guarded on _accumulated and not current_update_visible and _message_id and _message_id != "__no_edit__".
  • tests/gateway/test_stream_consumer.py — new test_segment_break_after_mid_stream_edit_failure_preserves_tail (matches austinmw's repro script verbatim) + updated existing test_segment_break_clears_failed_edit_fallback_state which had inadvertently codified the drop-the-tail behavior.

Validation

Before After
tests/gateway/test_stream_consumer.py 63 passing 64 passing (1 new)
austinmw's #8124 repro User received: 'Hello world ▉ Here is the tool result.' (" more" dropped) User received: 'Hello world ▉ more Here is the tool result.' (all text delivered)

Closes

Credit

… streamed text (#8124)

When a streaming edit fails mid-stream (flood control, transport error)
and a tool boundary arrives before the fallback threshold is reached,
the pre-boundary tail in `_accumulated` was silently discarded by
`_reset_segment_state`. The user saw a frozen partial message and
missing words on the other side of the tool call.

Flush the undelivered tail as a continuation message before the reset,
computed relative to the last successfully-delivered prefix so we don't
duplicate content the user already saw.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants