fix: skip preemptive compaction when model context limit is unknown (#2356)
This commit is contained in:
@@ -92,12 +92,25 @@ export function createPreemptiveCompactionHook(
|
|||||||
const cached = tokenCache.get(sessionID)
|
const cached = tokenCache.get(sessionID)
|
||||||
if (!cached) return
|
if (!cached) return
|
||||||
|
|
||||||
const modelSpecificLimit = !isAnthropicProvider(cached.providerID)
|
const isAnthropic = isAnthropicProvider(cached.providerID)
|
||||||
|
const modelSpecificLimit = !isAnthropic
|
||||||
? modelCacheState?.modelContextLimitsCache?.get(`${cached.providerID}/${cached.modelID}`)
|
? modelCacheState?.modelContextLimitsCache?.get(`${cached.providerID}/${cached.modelID}`)
|
||||||
: undefined
|
: undefined
|
||||||
const actualLimit = isAnthropicProvider(cached.providerID)
|
|
||||||
? getAnthropicActualLimit(modelCacheState)
|
let actualLimit: number
|
||||||
: modelSpecificLimit ?? DEFAULT_ACTUAL_LIMIT
|
if (isAnthropic) {
|
||||||
|
actualLimit = getAnthropicActualLimit(modelCacheState)
|
||||||
|
} else {
|
||||||
|
if (modelSpecificLimit === undefined) {
|
||||||
|
log("[preemptive-compaction] Skipping preemptive compaction: unknown context limit for model", {
|
||||||
|
providerID: cached.providerID,
|
||||||
|
modelID: cached.modelID,
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
actualLimit = modelSpecificLimit
|
||||||
|
}
|
||||||
|
|
||||||
const lastTokens = cached.tokens
|
const lastTokens = cached.tokens
|
||||||
const totalInputTokens = (lastTokens?.input ?? 0) + (lastTokens?.cache?.read ?? 0)
|
const totalInputTokens = (lastTokens?.input ?? 0) + (lastTokens?.cache?.read ?? 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user