GeezerVison is showing github.com — fix(core): keep room for the summary's reply when the compaction buffer is small by 2SinceJuly · Pull Request #59226 · anomalyco/opencode
Conversation
2SinceJuly
commented
Oct 26, 2026
•
edited by opencode-agent
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Issue for this PR
Closes #59110
Type of change
- Bug fix
- New feature
- Refactor / code improvement
- Documentation
What does this PR do?
compaction.buffer was doing two jobs: reserving headroom before compaction and capping the summary's completion tokens. With a small buffer (2048 in the report) and a reasoning model, the model spends the whole budget thinking, so compaction fails with finish_reason: length and "Compaction summary reached the output token limit" even though the conversation fits the window.
The summary request now also keeps the default reserve free (15% of the window, or 16k) and aims the transcript at the rest, so the reply has room to reason before it writes the summary. buffer keeps its documented job of deciding when compaction triggers. Native compaction is untouched, and a buffer at or above the default reserve behaves exactly as before.
How did you verify your code works?
- Added a regression test in
packages/core/test/session-compaction.test.ts: with buffer: 2000 on a 200k window the summary request now asks for 30k output tokens instead of 2k. It fails on dev and passes with the change.
- The four compaction suites in
packages/core pass: 38 tests.
- The same four suites pass in a Linux container (
oven/bun:1.4.4, arm64): 38 tests.
bun typecheck in packages/core reports no type errors.
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
Added by the opencode bot (AI-generated).
Related: #56862, #58463
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I reproduced #59110 with the issue's opencode-drive script (128k/16k simulated model, compaction.buffer: 2048). On the base, the summary request goes out with max_tokens=2048 and fails with "Compaction summary reached the output token limit". With this change, it goes out with max_tokens=16000 and the summary is saved. The compaction test suites in packages/core pass, the new test fails on the base as expected, and tsc -b is clean.
The change only affects summary requests. When to compact and native compaction still use the buffer alone, and a buffer at or above the default reserve behaves as before. With a small buffer, the summary transcript now aims at about 85% of the window instead of the window minus the buffer, so more of the oldest history is shortened. That is the trade-off you'd expect for giving the reply room, and it matches the default.
Heads-up: #58492 also changes calculateCeiling. The two should combine cleanly, since summaryCeiling would then also reserve the model's output, but expect a textual conflict.
Public API: unchanged.
Related: #56862, #58463


Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
`compaction.buffer` was used both as headroom before compacting and as the
summary's output limit, so a small buffer left a reasoning model no tokens to
write the summary and `/compact` failed with a misleading output-limit error.
The summary request now also keeps the default reserve (15% of the window, or
16k) free and aims the transcript at the rest. Native compaction and buffers
at or above the default reserve are unchanged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still looks good after the rebase. The fix is unchanged. Updating the two tests from #59441 that pinned the summary's maxTokens to the buffer is the right call, and the change fits #59441's new sizing: a larger output limit lowers the size up to which the conversation is sent unchanged. I re-ran the #59110 reproduction on the new base and on this head: the summary request goes from max_tokens=2048 with "Compaction summary reached the output token limit" to max_tokens=16000 with the summary saved. The compaction suites in packages/core pass (44 tests) and tsc -b is clean.
Public API: unchanged.


Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Oct 30, 2026
|
Parking this temporarily to free one of the repo's 3 open-PR slots: #59528 fixes a user-reported broken auth logout and is waiting on maintainers. Nothing is wrong with this change — I'll reopen it as soon as a slot frees.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|