mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-12 21:03:05 -07:00
feat(core): increase thought signature retry resilience (#22202)
Co-authored-by: Aishanee Shah <aishaneeshah@google.com>
This commit is contained in:
@@ -84,13 +84,16 @@ export type StreamEvent =
|
|||||||
interface MidStreamRetryOptions {
|
interface MidStreamRetryOptions {
|
||||||
/** Total number of attempts to make (1 initial + N retries). */
|
/** Total number of attempts to make (1 initial + N retries). */
|
||||||
maxAttempts: number;
|
maxAttempts: number;
|
||||||
/** The base delay in milliseconds for linear backoff. */
|
/** The base delay in milliseconds for backoff. */
|
||||||
initialDelayMs: number;
|
initialDelayMs: number;
|
||||||
|
/** Whether to use exponential backoff instead of linear. */
|
||||||
|
useExponentialBackoff: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const MID_STREAM_RETRY_OPTIONS: MidStreamRetryOptions = {
|
const MID_STREAM_RETRY_OPTIONS: MidStreamRetryOptions = {
|
||||||
maxAttempts: 4, // 1 initial call + 3 retries mid-stream
|
maxAttempts: 4, // 1 initial call + 3 retries mid-stream
|
||||||
initialDelayMs: 500,
|
initialDelayMs: 1000,
|
||||||
|
useExponentialBackoff: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SYNTHETIC_THOUGHT_SIGNATURE = 'skip_thought_signature_validator';
|
export const SYNTHETIC_THOUGHT_SIGNATURE = 'skip_thought_signature_validator';
|
||||||
@@ -433,7 +436,10 @@ export class GeminiChat {
|
|||||||
attempt < maxAttempts - 1 &&
|
attempt < maxAttempts - 1 &&
|
||||||
attempt < maxMidStreamAttempts - 1
|
attempt < maxMidStreamAttempts - 1
|
||||||
) {
|
) {
|
||||||
const delayMs = MID_STREAM_RETRY_OPTIONS.initialDelayMs;
|
const delayMs = MID_STREAM_RETRY_OPTIONS.useExponentialBackoff
|
||||||
|
? MID_STREAM_RETRY_OPTIONS.initialDelayMs *
|
||||||
|
Math.pow(2, attempt)
|
||||||
|
: MID_STREAM_RETRY_OPTIONS.initialDelayMs * (attempt + 1);
|
||||||
|
|
||||||
if (isContentError) {
|
if (isContentError) {
|
||||||
logContentRetry(
|
logContentRetry(
|
||||||
@@ -447,7 +453,7 @@ export class GeminiChat {
|
|||||||
attempt + 1,
|
attempt + 1,
|
||||||
maxAttempts,
|
maxAttempts,
|
||||||
errorType,
|
errorType,
|
||||||
delayMs * (attempt + 1),
|
delayMs,
|
||||||
model,
|
model,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -455,13 +461,11 @@ export class GeminiChat {
|
|||||||
coreEvents.emitRetryAttempt({
|
coreEvents.emitRetryAttempt({
|
||||||
attempt: attempt + 1,
|
attempt: attempt + 1,
|
||||||
maxAttempts: Math.min(maxAttempts, maxMidStreamAttempts),
|
maxAttempts: Math.min(maxAttempts, maxMidStreamAttempts),
|
||||||
delayMs: delayMs * (attempt + 1),
|
delayMs,
|
||||||
error: errorType,
|
error: errorType,
|
||||||
model,
|
model,
|
||||||
});
|
});
|
||||||
await new Promise((res) =>
|
await new Promise((res) => setTimeout(res, delayMs));
|
||||||
setTimeout(res, delayMs * (attempt + 1)),
|
|
||||||
);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user