Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix more review comments
  • Loading branch information
icecrasher321 committed Mar 25, 2026
commit 8182d8419d9b6fae02f96a69ac832ee5929968d3
18 changes: 16 additions & 2 deletions apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,8 @@ export function useChat(
setIsSending(false)
setIsReconnecting(false)
lastEventIdRef.current = 0
pendingRecoveryMessageRef.current = null
setPendingRecoveryMessage(null)
if (abandonedChatId) {
queryClient.invalidateQueries({ queryKey: taskKeys.detail(abandonedChatId) })
}
Expand All @@ -530,6 +532,8 @@ export function useChat(
setMessageQueue([])
lastEventIdRef.current = 0
clientExecutionStartedRef.current.clear()
pendingRecoveryMessageRef.current = null
setPendingRecoveryMessage(null)
}, [initialChatId, queryClient])

useEffect(() => {
Expand All @@ -552,6 +556,8 @@ export function useChat(
setMessageQueue([])
lastEventIdRef.current = 0
clientExecutionStartedRef.current.clear()
pendingRecoveryMessageRef.current = null
setPendingRecoveryMessage(null)
}, [isHomePage])

const fetchStreamBatch = useCallback(
Expand Down Expand Up @@ -704,7 +710,7 @@ export function useChat(
attempt: attachAttempt,
})

if (batch.events.length === 0 && batch.status === 'unknown') {
if (batch.events.length === 0 && !isTerminalStreamStatus(batch.status)) {
throw new Error(RECONNECT_TAIL_ERROR)
}
}
Comment thread
icecrasher321 marked this conversation as resolved.
Expand Down Expand Up @@ -1803,9 +1809,15 @@ export function useChat(
pendingRecovery.snapshot?.events?.[pendingRecovery.snapshot.events.length - 1]
?.eventId ?? 0

const rehydratedMessages = messagesRef.current
const lastAssistantMsg = [...rehydratedMessages]
.reverse()
.find((m) => m.role === 'assistant')
const recoveryAssistantId = lastAssistantMsg?.id ?? assistantId

const reconnectResult = await attachToExistingStream({
streamId: pendingRecovery.streamId,
assistantId,
assistantId: recoveryAssistantId,
expectedGen: gen,
snapshot: pendingRecovery.snapshot,
initialLastEventId: lastEventIdRef.current,
Expand Down Expand Up @@ -1858,6 +1870,8 @@ export function useChat(
setIsSending(false)
setIsReconnecting(false)
lastEventIdRef.current = 0
pendingRecoveryMessageRef.current = null
setPendingRecoveryMessage(null)

setMessages((prev) =>
prev.map((msg) => {
Expand Down
Loading