Skip to content

Commit 71a83af

Browse files
waleedlatif1claude
andcommitted
fix(mothership): clear edit value on nav, stop queue drain on send failure
- 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>
1 parent af7a2a8 commit 71a83af

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

apps/sim/app/workspace/[workspaceId]/home/home.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ export function Home({ chatId }: HomeProps = {}) {
202202
[editQueuedMessage]
203203
)
204204

205+
useEffect(() => {
206+
setEditingInputValue('')
207+
}, [chatId])
208+
205209
useEffect(() => {
206210
wasSendingRef.current = false
207211
if (resolvedChatId) markRead(resolvedChatId)

apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -726,22 +726,30 @@ export function useChat(
726726
queryClient.invalidateQueries({ queryKey: taskKeys.list(workspaceId) })
727727
}, [workspaceId, queryClient])
728728

729-
const finalize = useCallback(() => {
730-
sendingRef.current = false
731-
setIsSending(false)
732-
abortControllerRef.current = null
733-
invalidateChatQueries()
729+
const finalize = useCallback(
730+
(options?: { error?: boolean }) => {
731+
sendingRef.current = false
732+
setIsSending(false)
733+
abortControllerRef.current = null
734+
invalidateChatQueries()
734735

735-
const next = messageQueueRef.current[0]
736-
if (next) {
737-
setMessageQueue((prev) => prev.filter((m) => m.id !== next.id))
738-
const gen = streamGenRef.current
739-
queueMicrotask(() => {
740-
if (streamGenRef.current !== gen) return
741-
sendMessageRef.current(next.content, next.fileAttachments, next.contexts)
742-
})
743-
}
744-
}, [invalidateChatQueries])
736+
if (options?.error) {
737+
setMessageQueue([])
738+
return
739+
}
740+
741+
const next = messageQueueRef.current[0]
742+
if (next) {
743+
setMessageQueue((prev) => prev.filter((m) => m.id !== next.id))
744+
const gen = streamGenRef.current
745+
queueMicrotask(() => {
746+
if (streamGenRef.current !== gen) return
747+
sendMessageRef.current(next.content, next.fileAttachments, next.contexts)
748+
})
749+
}
750+
},
751+
[invalidateChatQueries]
752+
)
745753

746754
useEffect(() => {
747755
const activeStreamId = chatHistory?.activeStreamId
@@ -907,10 +915,13 @@ export function useChat(
907915
} catch (err) {
908916
if (err instanceof Error && err.name === 'AbortError') return
909917
setError(err instanceof Error ? err.message : 'Failed to send message')
910-
} finally {
911918
if (streamGenRef.current === gen) {
912-
finalize()
919+
finalize({ error: true })
913920
}
921+
return
922+
}
923+
if (streamGenRef.current === gen) {
924+
finalize()
914925
}
915926
},
916927
[workspaceId, queryClient, processSSEStream, finalize]

0 commit comments

Comments
 (0)