Skip to content

Commit 66dbf4e

Browse files
committed
refactor(chat): drop redundant flushChunks on the SSE error path
On an error 'final' event the reader stops via return true, so the post-loop flush is the single flush point. Defer the error append to after that flush (single flush, correct ordering) instead of flushing inside onEvent and again post-loop. No behavior change.
1 parent 8f4ac36 commit 66dbf4e

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

  • apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/chat

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/chat/chat.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ export function Chat() {
561561
}
562562
}
563563

564+
let finalError: string | null = null
564565
try {
565566
await readSSEEvents<{ event?: string; data?: ExecutionResult; chunk?: string }>(reader, {
566567
onParseError: (_data, e) => {
@@ -571,12 +572,7 @@ export function Chat() {
571572

572573
if (event === 'final' && eventData) {
573574
if ('success' in eventData && !eventData.success) {
574-
const errorMessage = eventData.error || 'Workflow execution failed'
575-
flushChunks()
576-
appendMessageContent(
577-
responseMessageId,
578-
`${accumulatedContent ? '\n\n' : ''}Error: ${errorMessage}`
579-
)
575+
finalError = eventData.error || 'Workflow execution failed'
580576
}
581577
return true
582578
}
@@ -589,6 +585,12 @@ export function Chat() {
589585
},
590586
})
591587
flushChunks()
588+
if (finalError) {
589+
appendMessageContent(
590+
responseMessageId,
591+
`${accumulatedContent ? '\n\n' : ''}Error: ${finalError}`
592+
)
593+
}
592594
finalizeMessageStream(responseMessageId)
593595
} catch (error) {
594596
if ((error as Error)?.name !== 'AbortError') {

0 commit comments

Comments
 (0)