Merge pull request #9511 from continuedev/dallin/context-length-fixes

fix: context length error detection
This commit is contained in:
Dallin Romney 2026-01-13 16:46:40 -08:00 • committed by GitHub
commit 8f088dc2d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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) =>