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:
@@ -26,6 +26,7 @@ import {
|
||||
} from "./constants"
|
||||
import { isCompactionGuardActive } from "./compaction-guard"
|
||||
import { getMessageDir } from "./message-directory"
|
||||
import { isTokenLimitError } from "./token-limit-detection"
|
||||
import { getIncompleteCount } from "./todo"
|
||||
import type { ResolvedMessageInfo, Todo } from "./types"
|
||||
import type { SessionStateStore } from "./session-state"
|
||||
@@ -204,6 +205,14 @@ ${todoList}`
|
||||
injectionState.inFlight = false
|
||||
injectionState.lastInjectedAt = Date.now()
|
||||
injectionState.consecutiveFailures = (injectionState.consecutiveFailures ?? 0) + 1
|
||||
|
||||
const errorObj = error instanceof Error
|
||||
? { name: error.name, message: error.message }
|
||||
: { message: String(error) }
|
||||
if (isTokenLimitError(errorObj)) {
|
||||
injectionState.tokenLimitDetected = true
|
||||
log(`[${HOOK_NAME}] Token limit error detected during injection, stopping continuation`, { sessionID })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user