-
Notifications
You must be signed in to change notification settings - Fork 11.3k
Open
Labels
coreAnything pertaining to core functionality of the application (opencode server stuff)Anything pertaining to core functionality of the application (opencode server stuff)
Description
Description
In packages/opencode/src/session/compaction.ts, the isOverflow function calculates usable tokens:
const usable = input.model.limit.input
? input.model.limit.input - reserved
: context - ProviderTransform.maxOutputTokens(input.model)The problem is that many models (like claude-opus-4.6) do not have an explicit input limit defined in their model definition (only context and output). In this case, the code takes the else branch:
: context - ProviderTransform.maxOutputTokens(input.model)This calculation completely ignores the reserved variable (which respects config.compaction.reserved). As a result, users cannot tune the compaction threshold to avoid context overflow crashes.
Expected Behavior
The reserved buffer (e.g. 60000 tokens) should be subtracted from the total context in the else branch as well.
Proposed Fix
const usable = input.model.limit.input
? input.model.limit.input - reserved
: context - reserved // (assuming reserved includes maxOutput safety buffer)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
coreAnything pertaining to core functionality of the application (opencode server stuff)Anything pertaining to core functionality of the application (opencode server stuff)