summaryrefslogtreecommitdiff
path: root/packages/core/src
diff options
context:
space:
mode:
authorJacob MacDonald <[email protected]>2025-08-06 13:45:54 -0700
committerGitHub <[email protected]>2025-08-06 20:45:54 +0000
commite3e76777535da2817b5fcac012456db29147059e (patch)
tree6796826c4ba81eccde102976af54fc36a3c9403e /packages/core/src
parentb3cfaeb6d30101262dc2b7350f5a349cd0417386 (diff)
Add integration test for maximum schema depth error handling (#5685)
Diffstat (limited to 'packages/core/src')
-rw-r--r--packages/core/src/core/geminiChat.ts32
1 files changed, 15 insertions, 17 deletions
diff --git a/packages/core/src/core/geminiChat.ts b/packages/core/src/core/geminiChat.ts
index c0e41b5e..5f5b22e8 100644
--- a/packages/core/src/core/geminiChat.ts
+++ b/packages/core/src/core/geminiChat.ts
@@ -300,16 +300,14 @@ export class GeminiChat {
};
response = await retryWithBackoff(apiCall, {
- shouldRetry: (error: Error) => {
- // Check for likely cyclic schema errors, don't retry those.
- if (error.message.includes('maximum schema depth exceeded'))
- return false;
- // Check error messages for status codes, or specific error names if known
- if (error && error.message) {
+ shouldRetry: (error: unknown) => {
+ // Check for known error messages and codes.
+ if (error instanceof Error && error.message) {
+ if (isSchemaDepthError(error.message)) return false;
if (error.message.includes('429')) return true;
if (error.message.match(/5\d{2}/)) return true;
}
- return false;
+ return false; // Don't retry other errors by default
},
onPersistent429: async (authType?: string, error?: unknown) =>
await this.handleFlashFallback(authType, error),
@@ -419,12 +417,10 @@ export class GeminiChat {
// the stream. For simple 429/500 errors on initial call, this is fine.
// If errors occur mid-stream, this setup won't resume the stream; it will restart it.
const streamResponse = await retryWithBackoff(apiCall, {
- shouldRetry: (error: Error) => {
- // Check for likely cyclic schema errors, don't retry those.
- if (error.message.includes('maximum schema depth exceeded'))
- return false;
- // Check error messages for status codes, or specific error names if known
- if (error && error.message) {
+ shouldRetry: (error: unknown) => {
+ // Check for known error messages and codes.
+ if (error instanceof Error && error.message) {
+ if (isSchemaDepthError(error.message)) return false;
if (error.message.includes('429')) return true;
if (error.message.match(/5\d{2}/)) return true;
}
@@ -689,10 +685,7 @@ export class GeminiChat {
private async maybeIncludeSchemaDepthContext(error: unknown): Promise<void> {
// Check for potentially problematic cyclic tools with cyclic schemas
// and include a recommendation to remove potentially problematic tools.
- if (
- isStructuredError(error) &&
- error.message.includes('maximum schema depth exceeded')
- ) {
+ if (isStructuredError(error) && isSchemaDepthError(error.message)) {
const tools = (await this.config.getToolRegistry()).getAllTools();
const cyclicSchemaTools: string[] = [];
for (const tool of tools) {
@@ -714,3 +707,8 @@ export class GeminiChat {
}
}
}
+
+/** Visible for Testing */
+export function isSchemaDepthError(errorMessage: string): boolean {
+ return errorMessage.includes('maximum schema depth exceeded');
+}