Skip to content

Commit 42a8288

Browse files
committed
fix(client): keep final delta when a chunk sets done in one envelope
chat_stream broke out of its read loop on the first chunk carrying done=True, before yielding that chunk's delta. A publisher that flags its last content chunk with done (delta + done in a single envelope) had its final text silently dropped on the Python client — while the HTTP SSE consumer, which emits content before honoring the finish, kept it. Yield any non-empty delta before honoring done so both consumers agree.
1 parent d3c5d82 commit 42a8288

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

zhub/client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,15 @@ async def chat_stream(self, messages: list[dict[str, Any]],
400400
break
401401
if item is None:
402402
break
403+
# Yield any content on this chunk BEFORE honoring `done`, so a
404+
# publisher that flags its final content chunk with done=True
405+
# (delta + done in one envelope) doesn't lose that last delta.
406+
# Matches the HTTP SSE path, which emits text before the finish.
407+
delta = item.get("delta", "")
408+
if delta:
409+
yield delta
403410
if item.get("done"):
404411
break
405-
yield item.get("delta", "")
406412
finally:
407413
self._streams.pop(env.request_id, None)
408414

0 commit comments

Comments
 (0)