Skip to content

A large compaction.buffer leaves small models no room before compaction #58146

Closed as duplicate

Description

@moritzWa

Description

compaction.buffer is subtracted from the model's window with no upper bound (calculateCeiling in packages/core/src/session/compaction.ts: window - buffer). A buffer tuned for a large model therefore leaves a smaller model almost no room: with buffer: 100000 on a 100k window the ceiling is 0, so automatic compaction is due on every request, and on a 64k window it is negative.

Seen with a global config that sets compaction.buffer: 100000 for 1M-token models and is then used with smaller models.

Found while porting #54993 (a v1 report of the same problem, reviewed on #54994) to v2.

Plugins

none

OpenCode version

dev (074f2fe)

Steps to reproduce

  1. Set compaction.buffer to 100000.
  2. Use a model with a 100k context window and an assistant message reporting 60k input tokens.
  3. An automatic compaction is due (it should not be until about 75k).

Reproduced with a unit test against SessionCompaction.compact; I have not reproduced it in a live session.

Screenshot

n/a, no UI

Operating System

macOS

Terminal

n/a

Activity

  1. opencode-agent commented on Oct 22, 2026

    @opencode-agent
    Contributor

    Thanks for the clear report and for porting this from #54994. I think this is a duplicate of #56783, which reports the same root cause on v2 and has already been reproduced on v2.0.32 and on dev. When one global compaction.buffer is at or above a model's window, window - buffer comes out at zero or below, so automatic compaction is due on every request. Your buffer: 100000 on a 100k window (and on a 64k window) is that case.

    Possible duplicates and closely related issues, ordered from most to least likely:

    The bot will close this issue as a duplicate in 1 day unless you reply explaining how your problem is different from #56783.

  2. opencode-agent commented on Oct 23, 2026

    @opencode-agent
    Contributor

    Closing this as a duplicate of #56783, since there's been no reply saying how this one is different. Both report the same problem: when compaction.buffer is at or above a model's context window, window - buffer comes out at zero or below, so automatic compaction is due on every request. Please follow #56783 for updates.

    Two PRs would fix it in different ways: #56786 treats an oversized buffer as unset, and your #58147 caps the buffer at a quarter of the window. Linking #58147 to #56783 would help maintainers compare them. Per-model buffers are tracked in #43703 and #56443.

    Until a fix lands, keeping compaction.buffer below the smallest context window among your models avoids the problem. If this turns out to be a different problem, reply here and we'll take another look.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions