From ad217937a3bdf2217afb2849103a612f55539fed Mon Sep 17 00:00:00 2001 From: MK Fain Date: Wed, 3 Dec 2025 21:14:45 -0600 Subject: [PATCH] Fix GlobalChatPane input delay after AI response completes Release the loading state immediately when finish_reason is received, but don't break from the for-await loop. Breaking triggers async iterator cleanup which can cause a multi-second delay before the input becomes available again. Instead, let the stream drain naturally while the UI is already unlocked for user input. --- src/components/GlobalChatProvider.tsx | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/components/GlobalChatProvider.tsx b/src/components/GlobalChatProvider.tsx index e86db2ac..0058f039 100644 --- a/src/components/GlobalChatProvider.tsx +++ b/src/components/GlobalChatProvider.tsx @@ -143,15 +143,12 @@ export function GlobalChatProvider({ children }: GlobalChatProviderProps) { return updated; }); - // Check if the stream is finished (finish_reason is set) - // Only release once to avoid multiple state updates + // Release loading as soon as finish_reason is received + // Don't break - let the stream drain naturally to avoid async iterator cleanup delays const finishReason = chunk.choices[0]?.finish_reason; if (finishReason && !loadingReleased) { loadingReleased = true; - // Response is complete, release the input immediately setIsLoading(false); - // Break out of the loop - we don't need any more chunks - break; } }