Conversation
…nomalyco#45168) Auto-compaction was gated by usable() = context - maxOutputTokens. Because maxOutputTokens is capped at OUTPUT_TOKEN_MAX (32000), the resulting ceiling (224000 for opencode-go/hy3) was unreachable: the provider pins real input at 262144 - 65536 = 196608, so the measured token count plateaus there and isOverflow() never returned true. The session then silently re-sent the full ~196k context as raw (uncached) input on every request. usable() now derives the input ceiling from limit.input ?? (context - output), minus a headroom buffer for the next response. This makes the overflow check fire before the provider caps input, for any model whose real input ceiling sits below context - reserved. Covers both the V1 (processor/prompt) and V2 (SessionCompaction) call paths, which share this function. Adds unit tests reproducing anomalyco#45168 with tencent/hy3 plus anthropic, openai, google, and deepseek models from models.dev. Fixes anomalyco#45168
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue for this PR
Closes #45168
Type of change
What does this PR do?
Auto-compaction was gated by
usable() = context - maxOutputTokens.maxOutputTokensis capped atOUTPUT_TOKEN_MAX(32000), so foropencode-go/hy3(models.dev: context 256000, output 64000, nolimit.input) the threshold came out to 224000. The provider actually pins input at 262144 - 65536 = 196608, so the measured token count plateaus around 198k andisOverflow()never returned true — the session kept re-sending the full ~196k context as raw, uncached input.usable()now derives the input ceiling from the model's effective input ceiling and reserves a 20k buffer for the next response:For
hy3that is 192000 - 20000 = 172000, which the pinned count (198108) exceeds, so compaction fires before the provider caps input. Because this is based on the real input ceiling rather thancontext - maxOutputTokens, it works for any model whose real input cap sits belowcontext - reserved. Both the V1 (processor/prompt) and V2 (SessionCompaction) call paths use this same function, so both are covered.How did you verify your code works?
packages/opencode/test/session/overflow.test.ts(pure unit tests onusable/isOverflow) reproducing compaction: auto-compaction never triggers on hy3 — token count plateaus below the isOverflow threshold, context pinned at 196608 raw input tokens #45168 withtencent/hy3pinned at input 196608, plusanthropic/claude-opus(200k input cap),openai/gpt(400k/128k),google/gemini(1M/64k) anddeepseek(1M/384k).overflow.ts(13 failures) and pass after the fix (22/22).packages/opencode/test/session/compaction.test.tsstill passes (55/55, no regressions).bun typecheckis clean.Screenshots / recordings
N/A — this is a session/compaction logic change, not a UI change.
Checklist