fix: streamed reply no longer repeats a word when edits fall back to a new message

_continuation_text backed the cut up to the previous space even when the visible
preview already ended on a whole word, so the continuation re-sent that word at
the seam ("the answer" + "answer to your question."). Back up only when the cut
lands inside a word (#116312 behaviour kept).

Found by the platforms E2E suite (#121409).
This commit is contained in:
teknium1
2026-09-24 05:36:51 -07:00
committed by Teknium
parent ded12f3ce1
commit 78b8032301
2 changed files with 9 additions and 1 deletions

View File

@@ -58,7 +58,9 @@ class StreamFallbackMixin:
# the continuation re-sends the broken word's tail and reads as an
# ordinary continuation. A prefix with no boundary (one very long
# token) keeps the original cut rather than re-sending the whole reply.
if cut < len(final_text):
# A prefix that already ends on a whole word needs no back-up: doing it
# re-sent that word at the seam.
if cut < len(final_text) and not final_text[cut].isspace() and not final_text[cut - 1].isspace():
boundary = max(
final_text.rfind(" ", 0, cut),
final_text.rfind("\n", 0, cut),