Skip to content
Merged
Show file tree
Hide file tree
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(mothership): clear edit value on nav, stop queue drain on send fa…
…ilure

- Reset editingInputValue when chatId changes so stale edit text
  doesn't leak into the next chat
- Pass error flag to finalize so queue is cleared (not drained) when
  sendMessage fails — prevents cascading failures on auth expiry or
  rate limiting from silently consuming every queued message

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
  • Loading branch information
waleedlatif1 and claude committed Mar 14, 2026
commit 71a83afc2e35a6980b21ccb0657e4844c6bc7d56
4 changes: 4 additions & 0 deletions apps/sim/app/workspace/[workspaceId]/home/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ export function Home({ chatId }: HomeProps = {}) {
[editQueuedMessage]
)
Comment thread
waleedlatif1 marked this conversation as resolved.
Comment thread
waleedlatif1 marked this conversation as resolved.

useEffect(() => {
setEditingInputValue('')
}, [chatId])

useEffect(() => {
wasSendingRef.current = false
if (resolvedChatId) markRead(resolvedChatId)
Expand Down
45 changes: 28 additions & 17 deletions apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -726,22 +726,30 @@ export function useChat(
queryClient.invalidateQueries({ queryKey: taskKeys.list(workspaceId) })
}, [workspaceId, queryClient])

const finalize = useCallback(() => {
sendingRef.current = false
setIsSending(false)
abortControllerRef.current = null
invalidateChatQueries()
const finalize = useCallback(
(options?: { error?: boolean }) => {
sendingRef.current = false
setIsSending(false)
abortControllerRef.current = null
invalidateChatQueries()

const next = messageQueueRef.current[0]
if (next) {
setMessageQueue((prev) => prev.filter((m) => m.id !== next.id))
const gen = streamGenRef.current
queueMicrotask(() => {
if (streamGenRef.current !== gen) return
sendMessageRef.current(next.content, next.fileAttachments, next.contexts)
})
}
}, [invalidateChatQueries])
if (options?.error) {
setMessageQueue([])
return
}

const next = messageQueueRef.current[0]
if (next) {
setMessageQueue((prev) => prev.filter((m) => m.id !== next.id))
const gen = streamGenRef.current
queueMicrotask(() => {
if (streamGenRef.current !== gen) return
sendMessageRef.current(next.content, next.fileAttachments, next.contexts)
})
}
},
[invalidateChatQueries]
)

useEffect(() => {
const activeStreamId = chatHistory?.activeStreamId
Expand Down Expand Up @@ -907,10 +915,13 @@ export function useChat(
} catch (err) {
if (err instanceof Error && err.name === 'AbortError') return
setError(err instanceof Error ? err.message : 'Failed to send message')
} finally {
if (streamGenRef.current === gen) {
finalize()
finalize({ error: true })
}
return
}
if (streamGenRef.current === gen) {
finalize()
}
},
[workspaceId, queryClient, processSSEStream, finalize]
Expand Down
Loading