Skip to content

Bug: compaction.reserved config is ignored for models without explicit 'input' limit #13980

@andrea-tomassi

Description

@andrea-tomassi

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)

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions