anomalyco / anomalyco/opencode

Manual /compact sends the full history to the compaction model without a context-fit check

Open
#46,164 1 comment 0 reactions 1 assignee View on GitHub

@nexxeln is already working on this.

Since Aug 29, 2026.

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

Description

Description

Manual /compact builds its summary prompt from the serialized conversation head and streams it to the configured compaction model without checking that the prompt fits that model's context window. When the compaction model's context is smaller than the session, the upstream request stalls with no output and no error. Every attempt only ends when the user cancels, and the summary message is recorded as MessageAbortedError: Aborted with zero tokens.

Observed on v1.18.25: a session at ~250k tokens (session model context 200k), agent.compaction.model set to a smaller-context model. Four manual /compact attempts streamed for 20s to ~7m, produced nothing, and were cancelled. No stream error was ever logged.

Root cause, manual path:

  • processCompaction in packages/opencode/src/session/compaction.ts (L319) resolves the compaction agent model (L358-361), serializes the whole selected head into nextPrompt via buildPrompt (L381-392), then streams it (L425). There is no comparison of the prompt size against model.route.defaults.limits.context.
  • The auto path has this guard: compactAfterOverflow in packages/core/src/session/compaction.ts (L179-190) returns false when Token.estimate(summaryPrompt) > context - summaryOutput. Manual compaction never runs it.

Two consequences:

  1. Manual compaction with a small-context compaction model hangs instead of failing fast.
  2. The auto guard fails silently (return false), so the same misconfiguration shows up as "auto compaction never fires" with no log line.

Suggested fix: reuse the L190 estimate in the manual path, fail fast with a visible error (or fall back to the session model), and log when the guard trips.

Debug info:

  • Version: 1.18.25 (latest)
  • Date: 2026-08-29T15:49:02.497Z
  • OS: macOS 25.6.0 (arm64)
  • Terminal: zed 1.15.1+stable.341.b962c0ab00b3d368503d8cd4000a6de2895b535c
  • Session ID: ses_fbcc45a67ffeSOwMRngxALOg5s
  • Model: openai/gpt-5.6-sol-fast
Compaction settings

from ~/.config/opencode/opencode.json:

  "compaction": {
    "auto": true,
    "prune": true
  },
  "agent": {
    "compaction": {
      "model": "openrouter/z-ai/glm-5.3-flash",
      "options": {
        "reasoningEffort": "low"
      }
    }
  },

Is this fixed in v2?

Checked the 2.0 branch (as of 2026-08-29): not fully fixed.

  • processCompaction is now the single path for manual and auto compaction (packages/opencode/src/session/compaction.ts:141), and it still streams the serialized history to the compaction model with no estimate against that model's limits.context (stream call at line 256). The old auto-path guard in packages/core/src/session/compaction.ts is gone.
  • What did change: a provider rejection now maps to ContextOverflowError (message-v2.ts:1007) and compaction records a clear "Session too large to compact" error (compaction.ts:272-283). So the hang is fixed for providers that reject oversized requests.
  • It still hangs for providers that accept the request and stream nothing, which is the exact behavior seen here with openrouter/z-ai/glm-5.3-flash on OpenRouter. A client-side pre-flight estimate (fail fast with a visible error, or fall back to the session model) would cover both cases.

Related open issues:

  • #41801: same manual-compact symptom with DeepSeek V4 Flash (repetition loop, cancelled, Aborted, no stream error logged)
  • #30806: aborted compaction leaves a dangling partial summary message
  • #46137 / #45168 / #45249: auto-compaction overflow detection gaps (different trigger, same "never compacts" outcome)
Plugins

No response

OpenCode version

1.18.25

Steps to reproduce
  1. Set agent.compaction.model to a model whose context window is smaller than the session model's.
  2. Grow a session past the compaction model's context window.
  3. Run /compact.
  4. The compaction stream produces nothing. Cancel it: the assistant summary message stays behind with MessageAbortedError, and the session is not compacted.
Screenshot and/or share link

No response

Operating System

macOS 25.6.0 (arm64)

Terminal

zed 1.15.1

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.