diff --git a/gui/src/redux/thunks/streamNormalInput.ts b/gui/src/redux/thunks/streamNormalInput.ts index fbff48d23..97d6bade6 100644 --- a/gui/src/redux/thunks/streamNormalInput.ts +++ b/gui/src/redux/thunks/streamNormalInput.ts @@ -276,7 +276,20 @@ export const streamNormalInput = createAsyncThunk< console.error("Failed to send dev data interaction log", e); } } - dispatch(setInactive()); + + // Check if we have any tool calls that were just generated + const newState = getState(); + const allToolCallStates = selectCurrentToolCalls(newState); + const generatingToolCalls = allToolCallStates.filter( + (toolCallState) => toolCallState.status === "generating", + ); + + // Only set inactive if there are no tool calls to process + // This prevents UI flashing when tool calls are about to be executed + if (generatingToolCalls.length === 0) { + dispatch(setInactive()); + } + await handleToolCallExecution(dispatch, getState); }, ); diff --git a/gui/src/redux/thunks/streamResponse_toolCalls.test.ts b/gui/src/redux/thunks/streamResponse_toolCalls.test.ts index 70b153863..53828b365 100644 --- a/gui/src/redux/thunks/streamResponse_toolCalls.test.ts +++ b/gui/src/redux/thunks/streamResponse_toolCalls.test.ts @@ -366,8 +366,8 @@ describe("streamResponseThunk - tool calls", () => { unsubscribe(); // Verify no UI flashing during auto-approved tool execution - // DESIRED: Should show: [true, false] - stream starts, then stops after everything is done - // This prevents the UI from switching between StreamingToolbar and PendingToolCallToolbar + // DESIRED: Should stay true throughout tool execution, only becoming false at the very end + // We expect [true, false] - streaming starts true, stays true during tool execution, then false when all done expect(streamingStateChanges).toEqual([true, false]); // Verify key actions are dispatched (tool calls trigger a complex cascade, so we verify key actions exist) @@ -392,7 +392,6 @@ describe("streamResponseThunk - tool calls", () => { "session/streamUpdate", "session/streamUpdate", "session/addPromptCompletionPair", - "session/setInactive", "session/setToolGenerated", "chat/callTool/pending", "session/setToolCallCalling",