fix(cli): clear stale retry/loading state after cancellation (#21096) (#21960)

Co-authored-by: Aashir Javed <Aaxhirrr@users.noreply.github.com>
Co-authored-by: Dev Randalpura <devrandalpura@google.com>
This commit is contained in:
Aashir Javed
2026-04-02 12:44:39 -07:00
committed by GitHub
parent c0dfa1aec3
commit 77027dff82
8 changed files with 194 additions and 35 deletions
+8 -10
View File
@@ -247,15 +247,8 @@ export const useGeminiStream = (
const previousApprovalModeRef = useRef<ApprovalMode>(
config.getApprovalMode(),
);
const [isResponding, setIsRespondingState] = useState<boolean>(false);
const isRespondingRef = useRef<boolean>(false);
const setIsResponding = useCallback(
(value: boolean) => {
setIsRespondingState(value);
isRespondingRef.current = value;
},
[setIsRespondingState],
);
const [isResponding, isRespondingRef, setIsResponding] =
useStateAndRef<boolean>(false);
const [thought, thoughtRef, setThought] =
useStateAndRef<ThoughtSummary | null>(null);
const [pendingHistoryItem, pendingHistoryItemRef, setPendingHistoryItem] =
@@ -280,13 +273,16 @@ export const useGeminiStream = (
useEffect(() => {
const handleRetryAttempt = (payload: RetryAttemptPayload) => {
if (turnCancelledRef.current || !isRespondingRef.current) {
return;
}
setRetryStatus(payload);
};
coreEvents.on(CoreEvent.RetryAttempt, handleRetryAttempt);
return () => {
coreEvents.off(CoreEvent.RetryAttempt, handleRetryAttempt);
};
}, []);
}, [isRespondingRef]);
const [
toolCalls,
@@ -839,6 +835,7 @@ export const useGeminiStream = (
return;
}
turnCancelledRef.current = true;
setRetryStatus(null);
// A full cancellation means no tools have produced a final result yet.
// This determines if we show a generic "Request cancelled" message.
@@ -1765,6 +1762,7 @@ export const useGeminiStream = (
setThought,
maybeAddSuppressedToolErrorNote,
maybeAddLowVerbosityFailureNote,
isRespondingRef,
settings.merged.billing?.overageStrategy,
setIsResponding,
],