From 135b2c89bee451544a475e6c9b0d3c532039c269 Mon Sep 17 00:00:00 2001 From: Bohdan Triapitsyn Date: Thu, 19 Feb 2026 11:55:42 +0200 Subject: [PATCH] fix: auto-send queue to check session status before sending (#447) --- packages/ui/src/components/chat/ChatInput.tsx | 11 ++++++++++- packages/ui/src/hooks/useEventStream.ts | 1 - 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/ui/src/components/chat/ChatInput.tsx b/packages/ui/src/components/chat/ChatInput.tsx index 1b3af3fe..cfca554b 100644 --- a/packages/ui/src/components/chat/ChatInput.tsx +++ b/packages/ui/src/components/chat/ChatInput.tsx @@ -666,9 +666,18 @@ export const ChatInput: React.FC = ({ onOpenSettings, scrollToBo // Prevent double-triggering autoSendTriggeredRef.current = true; + const targetSessionId = currentSessionId; + // Use setTimeout to avoid calling during render setTimeout(() => { - if (currentSessionId && currentProviderId && currentModelId) { + const activeSessionId = useSessionStore.getState().currentSessionId; + const currentStatus = targetSessionId + ? useSessionStore.getState().sessionStatus?.get(targetSessionId) + : null; + const stillIdle = currentStatus?.type === 'idle'; + const sessionUnchanged = Boolean(targetSessionId) && activeSessionId === targetSessionId; + + if (sessionUnchanged && stillIdle && targetSessionId && currentProviderId && currentModelId) { void handleSubmitRef.current({ queuedOnly: true }); } autoSendTriggeredRef.current = false; diff --git a/packages/ui/src/hooks/useEventStream.ts b/packages/ui/src/hooks/useEventStream.ts index c11da62d..c9329585 100644 --- a/packages/ui/src/hooks/useEventStream.ts +++ b/packages/ui/src/hooks/useEventStream.ts @@ -1382,7 +1382,6 @@ export const useEventStream = () => { } completeStreamingMessage(sessionId, messageId); - updateSessionStatus(sessionId, { type: 'idle' }, 'sse:message.updated.completed'); // Removed: void refreshSessionStatus(); const rawMessageSessionId = (message as { sessionID?: string }).sessionID;