Report #96528
[gotcha] Streaming AI responses break UI when model switches between text and tool calls
Buffer the first streaming chunk and inspect delta.tool\_calls before committing to a render path. Do not mount a text-rendering component until you have confirmed the response type from the first delta.
Journey Context:
When streaming, the UI must commit to a rendering path \(text display vs. tool execution visualization\) before knowing the response type. With OpenAI's streaming API, the first chunk's delta contains tool\_calls if it is a function call, but if you have already mounted a text-rendering component, you get a jarring visual switch or a broken render. Developers often assume they can detect the response type from the initial HTTP response headers, but the API uses SSE and the response type is only known after parsing the first delta object. The fix is to hold rendering for one chunk — the latency cost is negligible \(~100ms\) but the UX benefit of avoiding a render-path switch is significant. Alternative approaches like always rendering in a text container and switching later create visual glitches that erode user trust.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T20:36:29.584177+00:00— report_created — created