fix: false positives for token markers (#8942)

This commit is contained in:
cthomas
2026-01-19 16:20:03 -08:00
committed by Caren Thomas
parent 7544027cd9
commit 5f58819bbf
2 changed files with 6 additions and 6 deletions

View File

@@ -239,11 +239,11 @@ async def create_background_stream_processor(
if isinstance(chunk, tuple):
chunk = chunk[0]
# Track terminal events
# Track terminal events (check at line start to avoid false positives in message content)
if isinstance(chunk, str):
if "data: [DONE]" in chunk:
if "\ndata: [DONE]" in chunk or chunk.startswith("data: [DONE]"):
saw_done = True
if "event: error" in chunk:
if "\nevent: error" in chunk or chunk.startswith("event: error"):
saw_error = True
# Best-effort extraction of the error payload so we can persist it on the run.

View File

@@ -351,11 +351,11 @@ class StreamingService:
)
async for chunk in stream:
# Track terminal events
# Track terminal events (check at line start to avoid false positives in message content)
if isinstance(chunk, str):
if "data: [DONE]" in chunk:
if "\ndata: [DONE]" in chunk or chunk.startswith("data: [DONE]"):
saw_done = True
if "event: error" in chunk:
if "\nevent: error" in chunk or chunk.startswith("event: error"):
saw_error = True
yield chunk