Skip to content

[FEATURE]: per-model compaction threshold (reserved/buffer) #43703

Open

Description

@joserdf

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Summary

Allow configuring compaction thresholds per model instead of a single global value.

Currently the top-level compaction block (auto, prune, tail_turns, preserve_recent_tokens, reserved) is global — one value applied to every model/agent. There is no per-model or per-agent compaction field in the schema.

Use case

Users switch between models with very different context windows (e.g. a 32k local model and a 128k+ frontier model). A single reserved token buffer means the effective trigger point scales linearly with the model's context limit, which is not what we want: we want to compact a small model earlier (relative to its window) and a large model later, or vice-versa — independent reserved/buffer per model.

Current workaround (and its limitation)

The effective trigger is approximately model.limit.context − reserved. By setting a per-model limit.context in provider.<name>.models.<id>, the trigger point can be shifted per model. However, reserved (the headroom) stays a single global value, so you cannot set an independent buffer per model.

Proposed API

Something like a per-model override, e.g.:

{
  "provider": {
    "my-provider": {
      "models": {
        "small-model": {
          "limit": { "context": 32000, "output": 4096 },
          "compaction": { "auto": true, "reserved": 4000 }
        },
        "big-model": {
          "limit": { "context": 128000, "output": 8192 },
          "compaction": { "auto": true, "reserved": 24000 }
        }
      }
    }
  }
}

or a hook that receives the model and returns the compaction settings, so plugins can compute a threshold at runtime.

Benefits

  • Predictable, model-aware compaction behavior for multi-model setups.
  • No wasted context on large models or over-aggressive compaction on small models.
  • Enables provider-level defaults with per-model overrides, consistent with how limit already works.

Activity

  1. github-actions commented on Aug 20, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of or closely related to existing issues. Please check:

    If those don't cover your use case, this issue is distinct enough to stand on its own — the specific ask for per-model compaction overrides inside provider.<name>.models.<id> doesn't appear to have an exact match.

  2. zce commented on Aug 30, 2026

    @zce

    Related context from #44094: if per-model compaction thresholds become a thing, the compaction model's own context window needs to participate in the preflight ceiling too — otherwise a smaller-window compaction model overflows exactly when compaction is needed most (see my comment on #44094 and #46164).

  3. PzaThief commented on Oct 17, 2026

    @PzaThief

    Opened #56443 with a V2 implementation.

    It adds an optional buffer to the existing provider/model settings.compaction policy. The effective value is model setting, then provider setting, then the top-level compaction.buffer. buffer stays an absolute token count.

    Feedback on the config shape is welcome.

  4. opencodejr commented on Oct 28, 2026

    @opencodejr
    Contributor

    Thanks for the clear write-up and the example config!

    You're asking for the compaction buffer (reserved in older configs, compaction.buffer in v2) to be set per model or provider, so a small local model and a large frontier model can each have their own headroom instead of sharing one global value. Right now v2 has a single top-level compaction.buffer for every model. The per-model settings.compaction doesn't have a buffer field yet. This can't be done with a plugin today either, because the plugin compaction settings are global and plugins aren't told which model is active.

    The maintainers will consider this. Related items:

  5. pma1999 commented on Nov 5, 2026

    @pma1999

    Real-world case for this: one global buffer: "55%" keeps a 1M model at 450K but forces a 200K model to compact at 90K. Absolute per-model buffers would fix it cleanly: 200K -> 50K buffer (compact at 150K), 628K -> 345K (283K), 1M -> 550K (450K).

    Is the settings.compaction.buffer shape in #56443 (absolute tokens, model -> provider -> global fallback) the one you'd approve? If so, I can help test or refresh that branch.

  6. ksmeltzer commented on Nov 10, 2026

    @ksmeltzer

    We hit the same problem with 1M-context models where inflating buffer hurts smaller models, so I opened #61728 with a complementary approach: a configurable compaction.window (token ceiling for automatic compaction) rather than scaling buffer.

    It can be set globally (compaction.window), per provider/model/variant (settings.compaction.window), or per agent (agents.<id>.compaction.window), with precedence agent -> model/provider -> global (capped at the model's actual limit, while leaving the summary request's own budget at the model's real limit). That lets you set a global ceiling like "window": 180000 with a normal "buffer": 20000, or cap/opt-in specific models and agents directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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