Skip to content

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

Closed
konsisumer wants to merge 1 commit into
NousResearch:mainfrom
konsisumer:fix/stream-consumer-segment-break-tail-drop-8124
Closed

fix(gateway): flush undelivered tail before segment reset (#8124)#11974
konsisumer wants to merge 1 commit into
NousResearch:mainfrom
konsisumer:fix/stream-consumer-segment-break-tail-drop-8124

Conversation

@konsisumer

Copy link
Copy Markdown
Contributor

Summary

Fixes #8124.

When a streaming edit fails mid-stream (e.g. Telegram flood control) and a tool boundary arrives before the fallback-strike threshold promotes the consumer to fallback mode, the pre-boundary tail in _accumulated was silently discarded by _reset_segment_state. The user saw a frozen partial message with a stuck cursor and missing words on the other side of the tool call.

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 content the user already saw. Best-effort cursor strip on the partial message is also attempted when fallback mode hasn't already done so.

Test plan

  • Reproduced the bug with the reporter's exact script (validated under Docker via ghcr.io/astral-sh/uv:python3.11-trixie).
  • After the fix, the reporter's script prints NOT REPRODUCED"more" is delivered as a continuation message.
  • Added regression test test_segment_break_after_mid_stream_edit_failure_preserves_tail that asserts the pre-boundary tail reaches the user.
  • Updated the existing test_segment_break_clears_failed_edit_fallback_state which inadvertently codified the drop-the-tail behavior; it now also asserts the tail flush without prefix duplication.
  • All 65 tests/gateway/test_stream_consumer.py cases pass in Docker.

… streamed text (NousResearch#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.
@teknium1

Copy link
Copy Markdown
Contributor

Your implementation is landed in #12414 — commit 1d1e1277 is attributed to you in git log, cherry-picked straight from this PR onto current main. The new _flush_segment_tail_on_edit_failure() helper + the test_segment_break_after_mid_stream_edit_failure_preserves_tail regression test are in verbatim, plus your update to test_segment_break_clears_failed_edit_fallback_state. Also live-tested with a real agent on OpenRouter streaming through the patched consumer — three scenarios (no flood / flood@1 / flood@2), no content drop in any of them. Thanks for the clean fix and the thorough repro-matching test.

#12414

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.

[Bug]: Streaming text silently dropped when tool boundary arrives during fallback mode

2 participants