Uh oh!
There was an error while loading. Please reload this page.
feat(opencode): support per-model compaction config - #43713
Open
joserdf wants to merge 1 commit into
Open
Conversation
Allow overriding the global compaction block per model via provider.<id>.models.<model>.compaction. Model-level fields (auto, prune, tail_turns, preserve_recent_tokens, reserved) are merged over the global config, so models with different context windows can use different compaction thresholds. - Extract the compaction schema into ConfigProviderV1.Compaction and reuse it for both the global config and per-model overrides - Carry the resolved compaction config on the runtime Provider.Model - Resolve compaction settings through compactionConfig() in overflow and session compaction (reserved, auto, tail_turns, preserve_recent_tokens) - Resolve auto-compaction flag per model at the create call sites - Add tests for per-model auto, reserved, and tail_turns overrides
Enough1122
commented
Aug 22, 2026
|
6 tasks
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 freeto 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#43703
Type of change
What does this PR do?
Adds per-model compaction configuration so models with different context
windows can use different compaction thresholds.
Before: the top-level
compactionblock (auto,prune,tail_turns,preserve_recent_tokens,reserved) was global — onevalue applied to every model. The only per-model lever was
limit.context, which shifts the trigger point but cannot set anindependent buffer per model.
After: each model can override any compaction field via
provider.<id>.models.<model>.compaction. Model-level fields are mergedover the global config (model wins per-field), so a 32k local model can
compact early while a 128k frontier model keeps a larger usable window.
Example:
{ "provider": { "my-provider": { "models": { "small-model": { "limit": { "context": 32000, "output": 4096 }, "compaction": { "reserved": 4000 } }, "big-model": { "limit": { "context": 128000, "output": 8192 }, "compaction": { "reserved": 24000 } } } } } }Implementation:
ConfigProviderV1.Compactionandreused it for both the global config and the per-model
Modelschema(single source of truth, no behavior change for existing configs).
Provider.Modelso the session layer can read it.compactionConfig()insession/overflow.tsthat mergesmodel-level fields over the global block;
usable(),isOverflow(),select()(tail_turns / preserve_recent_tokens) and the auto-compactcall sites in
session/prompt.tsnow resolve through it.pruneintentionally stays on the global config: it is a backgroundcleanup task keyed only by sessionID, and the model is not readily
available at that call site.
How did you verify your code works?
tsgo --noEmitpasses inpackages/coreandpackages/opencode.bun test test/session/compaction.test.ts— 59 pass, 1 skip, 0 fail(added 4 tests: per-model
auto, per-modelreserved, per-modeltail_turns, and a regression check that models without an overridekeep using the global config).
bun test test/provider/— 557 pass, 0 fail.bun test test/config/(core) — 50 pass, 0 fail.test/session/run are pre-existinginotify_add_watch: No space left on deviceenvironment failures —they fail identically on the base
devbranch without these changes.Screenshots / recordings
N/A (not a UI change)
Checklist