From 0bf5dc2629a3dc8282248eb0ecc2838c57ad22fe Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Wed, 8 Apr 2026 13:24:14 +0900 Subject: [PATCH] fix(token-limit): normalize detection across providers Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- .../token-limit-detection.ts | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/hooks/todo-continuation-enforcer/token-limit-detection.ts b/src/hooks/todo-continuation-enforcer/token-limit-detection.ts index 25a2fad3d..366ac245f 100644 --- a/src/hooks/todo-continuation-enforcer/token-limit-detection.ts +++ b/src/hooks/todo-continuation-enforcer/token-limit-detection.ts @@ -1,8 +1,6 @@ -const TOKEN_LIMIT_ERROR_NAMES = new Set([ - "contextlengtherror", -]) +import { isRetryableModelError } from "../../shared/model-error-classifier" -const TOKEN_LIMIT_KEYWORDS = [ +const TOKEN_LIMIT_FALLBACK_PATTERNS = [ "prompt is too long", "is too long", "context_length_exceeded", @@ -11,16 +9,29 @@ const TOKEN_LIMIT_KEYWORDS = [ "too many tokens", ] +const TOKEN_LIMIT_ERROR_NAMES = new Set([ + "contextlengtherror", + "context_length_exceeded", +]) + 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 + const isRetryable = isRetryableModelError({ + name: error.name, + message: error.message, + }) + + if (!isRetryable && error.name) { + const errorNameLower = error.name.toLowerCase() + if (TOKEN_LIMIT_ERROR_NAMES.has(errorNameLower)) { + return true + } } if (error.message) { const lower = error.message.toLowerCase() - return TOKEN_LIMIT_KEYWORDS.some((keyword) => lower.includes(keyword)) + return TOKEN_LIMIT_FALLBACK_PATTERNS.some((pattern) => lower.includes(pattern)) } return false