From cd2049c296182671d771c90bc048cfe8852e36a9 Mon Sep 17 00:00:00 2001 From: Moonibus <764371130@qq.com> Date: Sun, 13 Sep 2026 21:44:44 +0800 Subject: [PATCH] fix(session): honor compaction.reserved without limit.input --- packages/opencode/src/session/overflow.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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: {