fix: detect token-limit errors in todo-continuation to prevent infinite loop (#2462)

handler.ts now catches ContextLengthError/prompt-too-long errors and
stops continuation instead of retrying with an even larger context.

91 tests pass, tsc clean.

Closes #2462
This commit is contained in:
YeonGyu-Kim
2026-04-07 15:24:20 +09:00
parent be562905d6
commit a9c73986d7
7 changed files with 232 additions and 1 deletions
@@ -0,0 +1,27 @@
const TOKEN_LIMIT_ERROR_NAMES = new Set([
"contextlengtherror",
])
const TOKEN_LIMIT_KEYWORDS = [
"prompt is too long",
"is too long",
"context_length_exceeded",
"token limit",
"context length",
"too many tokens",
]
export function isTokenLimitError(error: { name?: string; message?: string } | undefined): boolean {
if (!error) return false
if (error.name && TOKEN_LIMIT_ERROR_NAMES.has(error.name.toLowerCase())) {
return true
}
if (error.message) {
const lower = error.message.toLowerCase()
return TOKEN_LIMIT_KEYWORDS.some((keyword) => lower.includes(keyword))
}
return false
}