Skip to content

V2: compaction fires on the first request and repeats every turn when compaction.buffer >= model context limit #56813

Closed as duplicate

Description

@aner-dev

Description

Summary

With compaction.buffer set greater than or equal to the model's context limit, V2 starts automatic compaction on the very first request and re-triggers it on every turn or two. This emits meaningless structured summaries at session start and sometimes surfaces an internal Session.StepFailedError: Nothing to compact yet at server start.

Plugins

No response

OpenCode version

  • opencode v2.0.32 (Linux x64). The same config is also read by V1 1.19.0, but the looping behavior was observed on V2.

Steps to reproduce

  • Reproduced on opencode/mimo-v2.6-flash-free; the defect is model-agnostic (it depends only on the arithmetic below).

Reproduction

opencode.json:

{
  "compaction": {
    "auto": true,
    "buffer": 600000,
    "keep": { "tokens": 15000 }
  }
}
  1. Start a V2 session (any directory, e.g. one with an AGENTS.md).
  2. Send a single first message.
  3. Watch the message stream: a compaction message is created immediately after the first user message (reason: "auto"), summarizing an empty history, and it repeats every 1-2 turns.

Startup log:

ERROR "Failed to drain Session" cause="Session.StepFailedError: Nothing to compact yet
    at SessionRunner.runStep
    at SessionRunner.drain
    at ServerProcess.start"

Expected

  • An oversized buffer should be clamped to < context limit, or rejected with a clear warning at config-load time.
  • Compaction should not run when there is no older history to compact.
  • The internal StepFailedError should not surface as a user-facing failure at server start.

Actual

The trigger condition is estimated_tokens > context_limit - max(requested_output_tokens, buffer) (the docs describe buffer's default as 10% of the context limit). When buffer >= context_limit, the right-hand side is zero or negative, so the condition is always true and compaction fires on every step, including the first.

Because buffer is a single global value evaluated against each model's own limit, a value chosen for a large-context model (e.g. 400000 for a 1M-token model) breaks every smaller model in the same config.

Additional context / feature request

buffer and keep.tokens are configurable only in the top-level compaction block; per-model settings.compaction accepts only type: native|summary. That forces one compaction policy across models with very different context windows. Allowing a per-model (or per-provider) buffer, and/or an absolute "compact at N tokens" threshold, would let users choose safe compaction points for a 200k model and a 1M model without a single global value that is unsafe for one of them.

Screenshot and/or share link

No response

Operating System

Artix Linux Kernel 7.1.9-artix1-2

Terminal

Wezterm

Activity

  1. opencode-agent commented on Oct 18, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed report! I think this is a duplicate of #56783, which you opened earlier today with the same config, steps and Nothing to compact yet error. It has already been reproduced on v2.0.32 and on the latest dev.

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

    Until then, keeping compaction.buffer below the smallest context window among the models you use avoids the problem.

    The bot will close this issue as a duplicate in 1 day unless you reply explaining how it differs from #56783.

  2. opencode-agent commented on Oct 19, 2026

    @opencode-agent
    Contributor

    Closing this as a duplicate of #56783, which you opened earlier with the same config, steps and Nothing to compact yet error. There's been no reply here saying how this one is different. Please follow #56783 for updates. PR #56786 is open to fix it, and the per-model buffer request is tracked in #43703 and PR #56443. Until the 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