mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-17 17:41:24 -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 {
|
||||
/** Total number of attempts to make (1 initial + N retries). */
|
||||
maxAttempts: number;
|
||||
/** The base delay in milliseconds for linear backoff. */
|
||||
/** The base delay in milliseconds for backoff. */
|
||||
initialDelayMs: number;
|
||||
/** Whether to use exponential backoff instead of linear. */
|
||||
useExponentialBackoff: boolean;
|
||||
}
|
||||
|
||||
const MID_STREAM_RETRY_OPTIONS: MidStreamRetryOptions = {
|
||||
maxAttempts: 4, // 1 initial call + 3 retries mid-stream
|
||||
initialDelayMs: 500,
|
||||
initialDelayMs: 1000,
|
||||
useExponentialBackoff: true,
|
||||
};
|
||||
|
||||
export const SYNTHETIC_THOUGHT_SIGNATURE = 'skip_thought_signature_validator';
|
||||
@@ -433,7 +436,10 @@ export class GeminiChat {
|
||||
attempt < maxAttempts - 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) {
|
||||
logContentRetry(
|
||||
@@ -447,7 +453,7 @@ export class GeminiChat {
|
||||
attempt + 1,
|
||||
maxAttempts,
|
||||
errorType,
|
||||
delayMs * (attempt + 1),
|
||||
delayMs,
|
||||
model,
|
||||
),
|
||||
);
|
||||
@@ -455,13 +461,11 @@ export class GeminiChat {
|
||||
coreEvents.emitRetryAttempt({
|
||||
attempt: attempt + 1,
|
||||
maxAttempts: Math.min(maxAttempts, maxMidStreamAttempts),
|
||||
delayMs: delayMs * (attempt + 1),
|
||||
delayMs,
|
||||
error: errorType,
|
||||
model,
|
||||
});
|
||||
await new Promise((res) =>
|
||||
setTimeout(res, delayMs * (attempt + 1)),
|
||||
);
|
||||
await new Promise((res) => setTimeout(res, delayMs));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user