Repository navigation
feat(core): classify retryable transport/provider failures vs deterministic request errors #3798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4606f56
42ae93c
ddb74f0
88d4b3a
54ece25
1701569
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,11 @@ import type { | |
| GenerateContentResponseUsageMetadata, | ||
| } from '@google/genai'; | ||
| import { createUserContent, FinishReason } from '@google/genai'; | ||
| import { retryWithBackoff, isUnattendedMode } from '../utils/retry.js'; | ||
| import { | ||
| retryWithBackoff, | ||
| isUnattendedMode, | ||
| classifyError, | ||
| } from '../utils/retry.js'; | ||
| import { getErrorStatus } from '../utils/errors.js'; | ||
| import { createDebugLogger } from '../utils/debugLogger.js'; | ||
| import { parseAndFormatApiError } from '../utils/errorParsing.js'; | ||
|
|
@@ -713,17 +717,21 @@ export class GeminiChat { | |
| ); | ||
| const streamResponse = await retryWithBackoff(apiCall, { | ||
| shouldRetryOnError: (error: unknown) => { | ||
| // Never retry deterministic client errors regardless of classification | ||
| if (error instanceof Error) { | ||
| if (isSchemaDepthError(error.message)) return false; | ||
| if (isInvalidArgumentError(error.message)) return false; | ||
| } | ||
|
|
||
| const status = getErrorStatus(error); | ||
| if (status === 400) return false; | ||
| if (status === 429) return true; | ||
| if (status && status >= 500 && status < 600) return true; | ||
|
|
||
| return false; | ||
| // Delegate to classifyError for all other cases. Explicitly accepted | ||
| // retryable categories for Gemini streaming: 408 (timeout), 409 (transient | ||
| // lock/contention only), 429 (rate limit), 5xx (server errors), network | ||
| // transport errors. Deterministic errors (400, 401, 403, 404, 422) are | ||
| // handled by classifyError and return retryable=false. | ||
| return classifyError(error).retryable; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] The Consider adding an allowlist assertion after — deepseek-v4-pro via Qwen Code /review |
||
| }, | ||
| authType: this.config.getContentGeneratorConfig()?.authType, | ||
| persistentMode: isUnattendedMode(), | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Suggestion] The explicit
if (status === 400) return false;check before delegating toclassifyErroris redundant —classifyErroralready classifies 400 as non-retryable. It creates an asymmetry: 400 is double-checked while 401/403/404/422 are only handled byclassifyError. If a maintainer sees the explicit 400 check and removes the 400 handling fromclassifyError, callers ofdefaultShouldRetrywould lose 400 protection.Consider removing this explicit check and fully delegating to
classifyError. Alternatively, move the message checks (isSchemaDepthError/isInvalidArgumentError) intoclassifyErroras well, making the callback a clean delegation.