-
Notifications
You must be signed in to change notification settings - Fork 3.5k
fix(stream) handle task switching #3609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -87,7 +87,10 @@ export async function executeDeployChat( | |||||||||||||||||||||||||||
| return { success: false, error: 'Unauthorized chat access' } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| await db.delete(chat).where(eq(chat.id, existing[0].id)) | ||||||||||||||||||||||||||||
| return { success: true, output: { success: true, action: 'undeploy', isDeployed: false } } | ||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||
| success: true, | ||||||||||||||||||||||||||||
| output: { workflowId, success: true, action: 'undeploy', isChatDeployed: false }, | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
Comment on lines
88
to
+93
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The deploy path returns This is arguably correct behaviour (undeploying a chat does not remove the workflow's API deployment), but the asymmetry between the deploy and undeploy output shapes makes intent harder to follow. A comment explaining why
Suggested change
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const { hasAccess } = await checkWorkflowAccessForChatCreation(workflowId, context.userId) | ||||||||||||||||||||||||||||
|
|
@@ -199,9 +202,11 @@ export async function executeDeployChat( | |||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||
| success: true, | ||||||||||||||||||||||||||||
| output: { | ||||||||||||||||||||||||||||
| workflowId, | ||||||||||||||||||||||||||||
| success: true, | ||||||||||||||||||||||||||||
| action: 'deploy', | ||||||||||||||||||||||||||||
| isDeployed: true, | ||||||||||||||||||||||||||||
| isChatDeployed: true, | ||||||||||||||||||||||||||||
| identifier, | ||||||||||||||||||||||||||||
| chatUrl: `${baseUrl}/chat/${identifier}`, | ||||||||||||||||||||||||||||
| apiEndpoint: `${baseUrl}/api/workflows/${workflowId}/run`, | ||||||||||||||||||||||||||||
|
|
@@ -355,6 +360,7 @@ export async function executeRedeploy( | |||||||||||||||||||||||||||
| success: true, | ||||||||||||||||||||||||||||
| output: { | ||||||||||||||||||||||||||||
| workflowId, | ||||||||||||||||||||||||||||
| isDeployed: true, | ||||||||||||||||||||||||||||
| deployedAt: result.deployedAt || null, | ||||||||||||||||||||||||||||
| version: result.version, | ||||||||||||||||||||||||||||
| apiEndpoint: `${baseUrl}/api/workflows/${workflowId}/run`, | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed abort means stream continues processing after unmount
The previous cleanup explicitly called
abortControllerRef.current?.abort()to cancel the in-flight SSE fetch when the component unmounts. That line was intentionally removed here to allow the backend stream to stay alive across task switches, but it has a side effect: theReadableStreamDefaultReaderinsideprocessSSEStream'swhile (true) { reader.read() }loop keeps running after unmount.streamGenRef.current++preventsfinalizeRef.current()from being called with a stale generation, but the innerflush()calls — which callsetMessages,setIsSending,setIsReconnectingetc. — are not gated by the generation counter. If the stream is still in flight when the user switches tasks, state setters are called on the now-stale React fiber, which can cause React warnings and ghost state.Consider aborting the reader without aborting the server-side stream — i.e., abort the client
fetchconnection while keeping the Go-side stream alive. The server-side stream can remain open without the client holding a reader: