Files
oh-my-opencode/src/hooks/todo-continuation-enforcer/token-limit-detection.ts
T
YeonGyu-Kim a9c73986d7 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
2026-04-07 15:29:13 +09:00

28 lines
625 B
TypeScript

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
}