ContextWindowExceededError during compaction (litellm & claude-opus-4.5) #8132

Open
opened 2026-02-16 18:09:14 -05:00 by yindo · 1 comment
Owner

Originally created by @Hexecu on GitHub (Jan 31, 2026).

Originally assigned to: @rekram1-node on GitHub.

Description

Describe the bug

Context compaction fails with litellm.ContextWindowExceededError when the conversation history exceeds the model's context window, even when compaction is triggered manually.

This happens because the compaction process attempts to send the entire message history to the model for summarization, causing the input itself to exceed the context limit.

To reproduce

  1. Start a session with a model having a limited context window (e.g., claude-opus-4.5).
  2. Have a long conversation until the token usage exceeds the context window.
  3. Wait for auto-compaction trigger or run /compact.

Expected behavior

Compaction should summarize and shorten the history, allowing the session to continue.

Environment

  • Model: claude-opus-4.5
  • Error:
litellm.ContextWindowExceededError: litellm.BadRequestError: BedrockException: Context Window Error - {"message":"The model returned the following errors: Input is too long for requested model."}
model=claude-opus-4.5. context_window_fallbacks=None. fallbacks=None.
Set 'context_window_fallback' - https://docs.litellm.ai/docs/routing#fallbacks. Received Model Group=claude-opus-4.5
Available Model Group Fallbacks=None

Additional context

The issue is located in packages/opencode/src/session/compaction.ts. The process function passes input.messages directly to MessageV2.toModelMessages without any truncation, leading to the overflow during the compaction request itself.

Plugins

Context7

OpenCode version

v1.1.47

Steps to reproduce

Steps to reproduce:

Configure model: Set active model to claude-opus-4.5 (or any model with strict context limits) connected via LiteLLM.
Fill context window: Engage in a long conversation or paste large files until the token usage exceeds the model's context limit (generating >200k tokens).
Trigger compaction: Either wait for auto-compaction to trigger, or manually run the /compact command.
Observe error: The process crashes with litellm.ContextWindowExceededError instead of summarizing the history.

Screenshot and/or share link

Image

Operating System

macOS 15.7.2

Terminal

Integrated Terminal (VSCode) / Zsh

Originally created by @Hexecu on GitHub (Jan 31, 2026). Originally assigned to: @rekram1-node on GitHub. ### Description ### Describe the bug Context compaction fails with `litellm.ContextWindowExceededError` when the conversation history exceeds the model's context window, even when compaction is triggered manually. This happens because the compaction process attempts to send the **entire message history** to the model for summarization, causing the input itself to exceed the context limit. ### To reproduce 1. Start a session with a model having a limited context window (e.g., `claude-opus-4.5`). 2. Have a long conversation until the token usage exceeds the context window. 3. Wait for auto-compaction trigger or run `/compact`. ### Expected behavior Compaction should summarize and shorten the history, allowing the session to continue. ### Environment - Model: `claude-opus-4.5` - Error: ``` litellm.ContextWindowExceededError: litellm.BadRequestError: BedrockException: Context Window Error - {"message":"The model returned the following errors: Input is too long for requested model."} model=claude-opus-4.5. context_window_fallbacks=None. fallbacks=None. Set 'context_window_fallback' - https://docs.litellm.ai/docs/routing#fallbacks. Received Model Group=claude-opus-4.5 Available Model Group Fallbacks=None ``` ### Additional context The issue is located in `packages/opencode/src/session/compaction.ts`. The `process` function passes `input.messages` directly to `MessageV2.toModelMessages` without any truncation, leading to the overflow during the compaction request itself. ### Plugins Context7 ### OpenCode version v1.1.47 ### Steps to reproduce Steps to reproduce: Configure model: Set active model to claude-opus-4.5 (or any model with strict context limits) connected via LiteLLM. Fill context window: Engage in a long conversation or paste large files until the token usage exceeds the model's context limit (generating >200k tokens). Trigger compaction: Either wait for auto-compaction to trigger, or manually run the /compact command. Observe error: The process crashes with litellm.ContextWindowExceededError instead of summarizing the history. ### Screenshot and/or share link <img width="735" height="435" alt="Image" src="https://github.com/user-attachments/assets/8340606a-912d-40f1-b78c-43170aca095f" /> ### Operating System macOS 15.7.2 ### Terminal Integrated Terminal (VSCode) / Zsh
yindo added the bug label 2026-02-16 18:09:14 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 31, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #6286: Compaction Failing to Run on Time (Opus 4.5 failing to compact in time, context balloons too big)
  • #10385: Compaction bug - prompt token limit (compaction error with opus 4.5)
  • #6068: Auto compaction not triggering reliably with Anthropic models (context window limits being exceeded)
  • #8089: Auto-compaction enabled by default, but context_length_exceeded errors still occur in agent workflows
  • #11301: processing stops after compaction EVERY time (compaction process issues)

These issues relate to compaction failures with context window errors, particularly affecting Anthropic models like Claude Opus 4.5. The core problem appears to be that compaction itself fails when attempting to process oversized history, which is exactly what you're experiencing.

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 31, 2026): This issue might be a duplicate of existing issues. Please check: - #6286: Compaction Failing to Run on Time (Opus 4.5 failing to compact in time, context balloons too big) - #10385: Compaction bug - prompt token limit (compaction error with opus 4.5) - #6068: Auto compaction not triggering reliably with Anthropic models (context window limits being exceeded) - #8089: Auto-compaction enabled by default, but context_length_exceeded errors still occur in agent workflows - #11301: processing stops after compaction EVERY time (compaction process issues) These issues relate to compaction failures with context window errors, particularly affecting Anthropic models like Claude Opus 4.5. The core problem appears to be that compaction itself fails when attempting to process oversized history, which is exactly what you're experiencing. Feel free to ignore if none of these address your specific case.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8132