diff --git a/packages/opencode/src/session/overflow.ts b/packages/opencode/src/session/overflow.ts index 3374d1c9f8d4..c8ea09f8f940 100644 --- a/packages/opencode/src/session/overflow.ts +++ b/packages/opencode/src/session/overflow.ts @@ -1,4 +1,4 @@ -import type { Config } from "@/config/config" +import type { Config } from "@/config/config" import { ConfigV1 } from "@opencode-ai/core/v1/config/config" import { SessionV1 } from "@opencode-ai/core/v1/session" import type { Provider } from "@/provider/provider" @@ -11,12 +11,11 @@ export function usable(input: { cfg: ConfigV1.Info; model: Provider.Model; outpu const context = input.model.limit.context if (context === 0) return 0 - const reserved = - input.cfg.compaction?.reserved ?? - Math.min(COMPACTION_BUFFER, ProviderTransform.maxOutputTokens(input.model, input.outputTokenMax)) + const reserved = input.cfg.compaction?.reserved + const output = ProviderTransform.maxOutputTokens(input.model, input.outputTokenMax) return input.model.limit.input - ? Math.max(0, input.model.limit.input - reserved) - : Math.max(0, context - ProviderTransform.maxOutputTokens(input.model, input.outputTokenMax)) + ? Math.max(0, input.model.limit.input - (reserved ?? Math.min(COMPACTION_BUFFER, output))) + : Math.max(0, context - (reserved ?? output)) } export function isOverflow(input: {