Files
b649e72819 A Responses stream ends when the answer does, not when [DONE] arrives (#113)
Hanzo's provider ends its stream without [DONE], and nothing else finished
the response. Every delta reached the client and none of the terminal
events did — no response.output_text.done, .content_part.done,
.output_item.done or .completed — so a client reading the stream to spec
waited for a completion that never came, retried, and reported the stream
as truncated. Observed against api.hanzo.ai: 63 deltas carrying the whole
answer, then the connection simply closed.

Finishing on finish_reason alone was already tried and reverted, for a
real reason: the usage-only chunk commonly arrives after the terminal
choice chunk, and finishing early published response.completed with zero
usage and made that accounting chunk impossible to apply.

Both signals are now required, in whichever order they arrive: whichever
of finish_reason and usage is second finishes the response. The stream
closes on time and the usage is in it. [DONE] still finishes when a
provider sends one, and the bridge Close stays the backstop for a stream
that sends neither.

Two tests, one per arrival order. The first fails without this change with
the exact production symptom — the wire stops at output_text.delta.

Co-authored-by: Hanzo <[email protected]>

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-07 21:56:59 -07:00
..