anomalyco / anomalyco/opencode

"Session too large to compact" — the summarization request itself has no size budget

Open
#48,844 1 comment 0 reactions 1 assignee View on GitHub

@nexxeln is already working on this.

Since Sep 13, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

"Session too large to compact" — the summarization request itself has no size budget

Summary

Follow-up to #48827 (auto-compaction ping-pong). Even with the loop guard in place, compaction of a genuinely large session fails outright with:

Session too large to compact - context exceeds model limit even after stripping media

Three compounding causes in session/compaction.ts:

  1. The head has no budget. select() caps only the retained tail (preserveRecentBudget, 25% of the usable window). Everything older — the head — is serialized and sent to the summarizer as a single request. A 60k-token session on a 64k-context model, or a 900k-token session on a 1M-context model, produces a summarization request that doesn't fit the model — so compaction (the mechanism whose entire job is shrinking oversized sessions) fails precisely when it is most needed.

  2. The tail budget derives from the wrong model. When a dedicated compaction model is configured (agent.compaction.model, e.g. a cheap 1M model), select() sizes the retained tail from the compaction model's window. The compacted session must fit the session model's window — with a 1M compactor and a 64k session model, the retained tail alone (15k tokens) plus system prompt permanently overflows the session model.

  3. No escalation. If the post-compaction context still overflows, the next auto-compaction retains the same-sized tail and fails identically, until the loop guard from #48827 stops the session.

Proposed fix

PR linked below:

  • Chunked (map-reduce) summarization. The serialized head is packed into chunks capped at half the compaction model's usable window; each chunk is summarized; partial summaries that still exceed the budget are packed and re-summarized until the final request fits. Sessions whose head fits take the previous single-request path unchanged, byte for byte.
  • Tail budget from the session model, escalating full → half → none on each consecutive failed auto-compaction (tracked by the #48827 streak machinery), so a session whose floor exceeds the window sheds retained context before the loop guard stops it. The guard's limit becomes the ladder length (3).

With both, compaction succeeds by construction for any session size on any (working) model pair, and the session loop still stops cleanly when even a summary-only context fits no better.

Environment

  • OpenCode desktop v1.18.30 (macOS), session model cerebras/qwen-3.8-27b (64k context), compaction model deepseek/deepseek-v4-flash (1M context), ~60k-token session.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.