fix: skip preemptive compaction when model context limit is unknown (#2356)

This commit is contained in:
YeonGyu-Kim
2026-03-12 01:24:16 +09:00
parent 1c09b9869c
commit 26091b2f48

View File

@@ -92,12 +92,25 @@ export function createPreemptiveCompactionHook(
const cached = tokenCache.get(sessionID)
if (!cached) return
const modelSpecificLimit = !isAnthropicProvider(cached.providerID)
const isAnthropic = isAnthropicProvider(cached.providerID)
const modelSpecificLimit = !isAnthropic
? modelCacheState?.modelContextLimitsCache?.get(`${cached.providerID}/${cached.modelID}`)
: undefined
const actualLimit = isAnthropicProvider(cached.providerID)
? getAnthropicActualLimit(modelCacheState)
: modelSpecificLimit ?? DEFAULT_ACTUAL_LIMIT
let actualLimit: number
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 totalInputTokens = (lastTokens?.input ?? 0) + (lastTokens?.cache?.read ?? 0)