Skip to content

fix(core): give compaction summaries the same output limit as normal turns - #57564

Merged
rekram1-node merged 2 commits into
devfrom
summary-output-cap
Oct 21, 2026
Merged

rekram1-node merged 2 commits into
devfrom
summary-output-cap

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Compaction summaries were capped at 32k output tokens, and thinking counts against that cap. On reasoning models at high effort the summary can spend the whole 32k thinking and fail with "Compaction summary reached the output token limit", even when the window has plenty of room left.

Example from #56766: Claude Haiku 5.5 at max effort, 1M window, 305k in, 32.0k out, failed. About 700k of the window was still free. Only the cap stopped it.

Change

Summaries now get the model's output limit (up to 256k), like a normal turn, sized to the room the request leaves in the window. Since the summary request is usually most of the window, it also keeps the same 15% margin for a low token estimate that normal turns use, and never gets less than before.

summary output = larger of:
    min(32k, window - request)        what it got before
    window - request x 1.15           room after the estimate margin
capped at the model's output limit
Case Before After
Haiku 5.5, 1M window, 305k in 32k 128k
400k window, 265k in 32k 60k
1M window, auto compaction at 850k 32k 32k
200k window, 175k in 25k 25k

max_tokens is still always sent, so providers that need it explicitly (#42448) are unaffected, and the OpenAI plugin still strips it for openai.

Tradeoff

When the catalog lists a bigger window than the provider actually accepts, a summary with lots of apparent room can ask for more output than shrinking the input can make room for. Normal turns already behave this way. The fix for that is correcting those catalog limits.

Out of scope

  • Recovering when a summary still stops on length. Separate PR.
  • Summary request reusing the session's tools and reasoning effort.

Added by the opencode bot (AI-generated).

Fixes #56766

Related: #54797, #44609

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the PR, summaries get the model's own output limit (up to 256k), still fitted to the room left in the window. I checked this with a temporary runner scenario: a 1M-context model with a 128k output limit, compacting at about 860k tokens, asked for a 32k summary on the base and a 128k summary with the PR. Windows of 200k and below keep the same limits, as described. The core session, compaction and model-request tests pass, and so does typecheck in packages/core.

Public API: unchanged. SessionModelRequest.outputLimit lost its kind parameter, but it's only used inside packages/core.

One concern, not blocking (inline): on large windows the summary now has very little margin for the token estimate running low.

Fixes #56766
Related: #54797, #44609

Comment thread packages/core/src/session/compaction.ts Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] opencode compaction issues

1 participant