Skip to content

fix(ai): detect litellm context window exceeded error - #54608

Closed
fabian33-ops wants to merge 1 commit into
anomalyco:devfrom
fabian33-ops:litellm-overflow-dev
Closed

fabian33-ops wants to merge 1 commit into
anomalyco:devfrom
fabian33-ops:litellm-overflow-dev

Conversation

@fabian33-ops

@fabian33-ops fabian33-ops commented Oct 11, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #44888

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When LiteLLM rejects a chat completion request for being too large context, it shows a special error message. Because it is special for LiteLLM, opencode simply aborts, and does not detect the error as being max context size reached.

How did you verify your code works?

Trying it locally, running the whole testsuite, using the patch every day.

Screenshots / recordings

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Related: #46564

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Oct 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix works. I ran opencode run against a local OpenAI-compatible server that returns LiteLLM's ContextWindowExceededError with HTTP 400. On the base branch the session stops with the error and makes no compaction attempt. With this PR the error is classified as a context overflow and opencode sends the compaction request. packages/ai tests and the type check pass.

The new pattern is specific enough not to catch unrelated errors, and rate-limit messages are still excluded. The public API is unchanged.

No concerns.

Related: #46564

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Oct 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] litellm ContextWindowExceededError not detected as context overflow

1 participant