anomalyco / anomalyco/opencode

[Bug] litellm ContextWindowExceededError not detected as context overflow

Open
#44,888 1 comment 0 reactions 1 assignee View on GitHub

@nexxeln is already working on this.

Since Aug 25, 2026.

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

Description

Description

litellm wraps provider context-overflow errors as ContextWindowExceededError: litellm.BadRequestError: Context Window exceeded for given call. No models have context window large enough for this call.

The shared overflow matcher in packages/llm/src/provider-error.ts doesn't recognize the phrase "context window exceeded", so these errors are classified as a generic API error instead of context overflow. This means compaction is never triggered and the session dead-ends.

Plugins
OpenCode version

0.0.0-dev-202608241310

Steps to reproduce
  1. Use a model behind litellm
  2. Set the model max_input_tokens below the serving engines' max contect window, so we see the error from litellm, instead of the error message from the serving engine, being automaticall detected by opencode.
  3. Send enough messages to exceed the litellm context window
  4. Observe the error is treated as a generic API failure rather than triggering automatic compaction
Screenshot and/or share link
Image
Operating System

15.7.9 (24G830)

Terminal

zsh

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.