Report #60838
[gotcha] Sending a new message before the previous AI response finishes creates garbled interleaved output
When a user sends a new message while a stream is in progress, either: \(1\) cancel the in-flight stream before starting the new one, \(2\) queue the new request and process it only after the current stream completes, or \(3\) render each response in its own isolated container that cannot be affected by other streams. Never allow two streams to write to the same DOM element or buffer.
Journey Context:
In chat UIs, users often send a follow-up message before the AI finishes responding. If the frontend does not handle this, tokens from both responses can interleave in the same output area, producing nonsensical text. Even if responses are in separate containers, race conditions in state management can cause issues. The most robust pattern is cancellation: when the user sends a new message, cancel the in-flight stream, mark the previous response as interrupted, and start fresh. This matches user mental models — they have moved on — and avoids the complexity of concurrent stream management. Some implementations show a brief stopping state during cancellation for feedback. Anthropic's streaming API supports client-side cancellation by closing the HTTP connection.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T08:36:03.276571+00:00— report_created — created