Skip to content

[BUG]: Compaction overflow threshold too low when limit.input is set; compaction LLM overflow causes retry loop #30805

Description

@LifetimeVip

Description Bug in the compaction overflow detection: isOverflow threshold too low when limit.input is set. overflow.ts:14-19 鈥?when model.limit.input is set, usable() uses limit.input - reserved. reserved is min(COMPACTION_BUFFER, maxOutputTokens) where COMPACTION_BUFFER is 20,000. Since max output tokens are typically 32K-128K, reserved stays at 20K even when the model needs more headroom. Compaction triggers with only 20K of reserve, but the next API call may need 32K+ 鈥?causing an actual overflow despite compaction having fired. Note: the compaction retry loop (compaction LLM overflow 鈫?infinite retry) is already tracked in #27924, #15533, #30443. This issue focuses on the distinct threshold calculation bug that causes compaction to fire too late. Focused follow-on to #30376. Suggested fix: use maxOutputTokens as reserve when limit.input is set, instead of min(20K, maxOutputTokens). ### OpenCode version

main

Steps to reproduce 1. Start a session with a model that has limit.input set (e.g., 128K input limit) 2. Fill context to near the limit 3. Compaction fires with only 20K reserve 4. Next API call overflows because output needs more than 20K headroom

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions