Stale-Stream Protection: Only the Latest Request Updates the UI
Explore techniques to protect your UI from stale streaming data by assigning ownership to each request. Learn to use turn identifiers to ensure only the latest request updates the interface, preventing overlapping or residual data issues in chat applications.
Stopping a stream is one way a request goes stale. A second, sneakier way happens when the user doesn’t stop anything, they just move on to a new message. You click Send on Prompt A, the assistant starts streaming, and then you quickly send Prompt B. The UI clears and shows a new assistant message for B, but a second later text from A keeps appending into B’s message. You end up with a single assistant bubble that contains the beginning of B and then random mid sentence fragments from A.
Nothing crashed. That was the problem.
The symptom points to a specific class of bug. The old async stream is still producing events, and the event handler is still dispatching them into the same reducer that now owns the new message. The debugging target is simple. Prove which request owns UI mutations, and reject ...