fix(provider): port upstream LiteLLM context overflow detection (anomalyco/opencode#60692)
Issue for this PR
Closes #1843
Type of change
- Bug fix
- New feature
- Refactor / code improvement
- Documentation
What does this PR do?
Ports upstream https://github.com/anomalyco/opencode/pull/60692.
User-visible failure: LiteLLM rejects an oversized prompt with litellm.ContextWindowExceededError: ... Context Window exceeded for given call. No pattern in OVERFLOW_PATTERNS matched that text (the closest, MiniMax's context window exceeds limit, does not), so ProviderError.parseAPICallError returned a generic API error. Users routing models through a LiteLLM proxy saw the session stop with that error at the end of a long session instead of getting auto-compaction and a retry.
Change: add /context window exceeded/i to OVERFLOW_PATTERNS in packages/opencode/src/provider/error.ts, same as upstream, so the error is classified as context_overflow and the existing compaction path runs. Wrapped in altimate_change start — upstream_fix: markers. The upstream PR also added a v2 session-runner test for an unrelated MiMo empty-reply case; that is not part of this port.
How did you verify your code works?
- New test in
packages/opencode/test/provider/error.test.tsusing LiteLLM's real error text. It fails onmain(41 pass, 1 fail) and passes with the fix (42 pass). tsgo --noEmitinpackages/opencode: pass (run with--singleThreadedto avoid OOM on the 8 GB VM).bun run script/upstream/analyze.ts --markers --base origin/main --strict: ok.bun script/check-tracker-leaks.ts: ok.
Cost side effects
None. An overflow that already failed now triggers the existing compaction (one summary call per overflow, as for every other provider); nothing scales with user data.
Screenshots / recordings
Not a UI change.
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
- I checked for cost side effects (model calls, queries or cloud resources that grow with user data) and described them, or wrote "none"
Summary by cubic
Classifies LiteLLM's ContextWindowExceededError as a context overflow so sessions routed through a LiteLLM proxy trigger the existing auto-compaction and retry instead of stopping with a generic API error. The port adds the missing /context window exceeded/i pattern to OVERFLOW_PATTERNS in packages/opencode/src/provider/error.ts and a regression test using LiteLLM's real error text.