diff --git a/extensions/cli/src/util/exponentialBackoff.ts b/extensions/cli/src/util/exponentialBackoff.ts index c44aee6e8..8f3004ae9 100644 --- a/extensions/cli/src/util/exponentialBackoff.ts +++ b/extensions/cli/src/util/exponentialBackoff.ts @@ -80,8 +80,18 @@ function isConnectionError(errorMessage: string): boolean { /** * Checks if the error indicates a context length issue (non-retryable) */ -export function isContextLengthError(error: any): boolean { +export function isContextLengthError(error: unknown): boolean { + if (!(error instanceof Error)) { + return false; + } const errorMessage = error.message?.toLowerCase() || ""; + + if (errorMessage.includes("invalid_request_error")) { + if (errorMessage.includes("context")) { + return true; + } + } + const contextLengthPatterns = [ // Anthropic Claude "input length and max_tokens exceed context limit", @@ -94,7 +104,6 @@ export function isContextLengthError(error: any): boolean { "use a shorter prompt", // Generic patterns "context_length_exceeded", - "invalid_request_error", ]; return contextLengthPatterns.some((pattern) =>