Fix task switch causing duplicate text renderings#3624
Fix task switch causing duplicate text renderings#3624TheodoreSpeaks merged 3 commits intostagingfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview
Written by Cursor Bugbot for commit ece64dc. This will update automatically on new commits. Configure here. |
Greptile SummaryThis PR re-introduces Key changes:
Issue: Confidence Score: 3/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A([Task Switch - chatHistory changes]) --> B{appliedChatIdRef equals chatHistory.id?}
B -- yes --> Z([return - no-op])
B -- no --> C{activeStreamId AND no snapshot AND sendingRef=false?}
C -- yes --> D[invalidateQueries and return]
C -- no --> E[setMessages to new chat messages]
E --> F{activeStreamId AND sendingRef=false?}
F -- yes --> G[abortControllerRef.abort - NEW in this PR]
G --> H[Increment streamGenRef, new AbortController, sendingRef=true]
H --> I[processSSEStreamRef called with reader, assistantId, gen - gen passed OK]
I --> J{isStale? streamGenRef not equal expectedGen}
J -- yes --> K[reader.cancel and break - no stale state update]
J -- no --> L[flush updates to setMessages]
F -- "no - sendingRef=true" --> M[No abort called]
M --> N[sendMessage processSSEStream called with reader and assistantId only - gen NOT passed]
N --> O{isStale check?}
O -- "always false - expectedGen is undefined" --> P[setMessages appends stale reply to new chat - DUPLICATE BUG remains]
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Summary
Previous changes to not abort any sse processors caused issues with duplicate processing. Use abort to clean up tasks now.
Decided to revert back processing all sse streams that are open - dev server is limited to 6 concurrent connections and i didn't want to introduce divergent behavior in prod. Think the correct long-term approach is to migrate sse streams to a single stream to handle this, but this only causes issues if a task is being ran in the background.
Type of Change
Testing
Tested switching mothership tasks and validating no errors in duplicate text occurred.
Checklist
Screenshots/Videos