Skip to content

fix(llm): detect litellm context window exceeded error - #44889

Open
fabian33-ops wants to merge 2 commits into
anomalyco:devfrom
fabian33-ops:litellm-overflow-pattern
Open

fix(llm): detect litellm context window exceeded error#44889
fabian33-ops wants to merge 2 commits into
anomalyco:devfrom
fabian33-ops:litellm-overflow-pattern

Conversation

@fabian33-ops

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?

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

The phrase "context window exceeded" wasn't matched by the existing overflow patterns, so it fell through as a generic API error instead of triggering compaction.

This adds /context window exceeded/i to the shared matcher in provider-error.ts so litellm-wrapped errors are classified as context overflow, same approach as #35671 and #37840.

How did you verify your code works?

Built a standalone binary with ./packages/opencode/script/build.ts --single and ran it via packages/opencode/dist/opencode-darwin-arm64/bin/opencode. Pasted ~40k blocks into chat until the error appeared. The error still surfaces but compaction is now triggered automatically instead of leaving it as a dead-end API error.

Screenshots / recordings

Not a UI change.

Checklist

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

Sign up for freeto 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

@fabian33-ops