Merge pull request #2420 from huww98/fix/ctrl-y-retry-rate-limit

feat: allow Ctrl+Y to skip rate-limit retry delay immediately
This commit is contained in:
tanzhenxin 2026-04-05 14:47:59 +08:00 committed by GitHub
commit 0776627e0f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 234 additions and 15 deletions

View file

@ -9,6 +9,7 @@ import type {
Config,
EditorType,
GeminiClient,
RetryInfo,
ServerGeminiChatCompressedEvent,
ServerGeminiContentEvent as ContentEvent,
ServerGeminiFinishedEvent,
@ -272,6 +273,7 @@ export const useGeminiStream = (
*/
const clearRetryCountdown = useCallback(() => {
stopRetryCountdownTimer();
skipRetryDelayRef.current = null;
setPendingRetryErrorItem(null);
setPendingRetryCountdownItem(null);
}, [
@ -280,14 +282,14 @@ export const useGeminiStream = (
stopRetryCountdownTimer,
]);
// Holds the skipDelay callback from the current rate-limit RetryInfo.
// Managed symmetrically: set in startRetryCountdown, cleared in clearRetryCountdown.
const skipRetryDelayRef = useRef<(() => void) | null>(null);
const startRetryCountdown = useCallback(
(retryInfo: {
message?: string;
attempt: number;
maxRetries: number;
delayMs: number;
}) => {
(retryInfo: RetryInfo) => {
stopRetryCountdownTimer();
skipRetryDelayRef.current = retryInfo.skipDelay;
const startTime = Date.now();
const { message, attempt, maxRetries, delayMs } = retryInfo;
const retryReasonText =
@ -1391,6 +1393,15 @@ export const useGeminiStream = (
* when the user presses Ctrl+Y (bound to Command.RETRY_LAST in keyBindings.ts).
*/
const retryLastPrompt = useCallback(async () => {
// During a rate-limit retry countdown, skip the delay so the generator
// retries immediately — no abort/re-submit needed.
if (skipRetryDelayRef.current) {
skipRetryDelayRef.current();
skipRetryDelayRef.current = null;
clearRetryCountdown();
return;
}
if (
streamingState === StreamingState.Responding ||
streamingState === StreamingState.WaitingForConfirmation