diff --git a/packages/core/src/core/geminiChat.ts b/packages/core/src/core/geminiChat.ts index 1670f99508..bfe8d2e1ba 100644 --- a/packages/core/src/core/geminiChat.ts +++ b/packages/core/src/core/geminiChat.ts @@ -379,11 +379,6 @@ export class GeminiChat { return; // Stop the generator } - if (isConnectionPhase) { - // Remove failed user content so it doesn't break subsequent requests - this.history.pop(); - throw error; - } lastError = error; const isContentError = error instanceof InvalidStreamError; const isRetryable = isRetryableError( @@ -391,6 +386,12 @@ export class GeminiChat { this.config.getRetryFetchErrors(), ); + // For non-retryable connection errors, pop history and throw immediately + if (isConnectionPhase && !isRetryable) { + this.history.pop(); + throw error; + } + if ( (isContentError && isGemini2Model(model)) || (isRetryable && !signal.aborted)