You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug: context overflow errors from non-OpenAI providers not detected, causing retry loops #35918
When a provider rejects a request because the input exceeds the model's context window, the error message format varies by provider:
OpenAI: maximum context length
GLM/Z.AI: tokens in request more than max tokens allowed
Moonshot: request too large
OpenCode's error classifier only recognizes the OpenAI phrasing. Errors from other providers are classified as generic API errors, which triggers retry logic instead of context compaction. The agent enters a retry loop, repeatedly sending the same oversized request.
Additionally, broad substring matching on max_tokens causes false positives — output-token-limit errors (e.g., max_tokens output exceeded) are misclassified as context overflow, triggering unnecessary compaction.
To reproduce
Use a GLM model (e.g., zai-coding-plan/glm-5.1) with a 200K context window
Fill the context to ~190K tokens
Send a message
Observe: the provider returns a context overflow error, but OpenCode retries instead of compacting
Expected behavior
All provider context overflow error variants should be detected and trigger compaction, not retries. Output-token-limit errors should NOT trigger compaction.
If your issue is specifically about the max_tokens false positive (output-token-limit errors triggering compaction), that aspect may be novel — please verify whether the linked issues cover that case.
Activity
github-actions commentedon Jul 8, 2026
This issue might be a duplicate of existing issues. Please check:
tokens in request more than max tokens allowed) not classified as context overflow inOVERFLOW_PATTERNS, causing compaction to not trigger. Same provider, same error message, same root cause.UnknownError/"Network connection lost", preventing compaction — same class of issue with a broader analysis and suggested fix.If your issue is specifically about the
max_tokensfalse positive (output-token-limit errors triggering compaction), that aspect may be novel — please verify whether the linked issues cover that case.rekram1-node commentedon Jul 8, 2026
are u sure u read the code correctly, we already have this, ur pr is duplicating code we already have
EZotoff commentedon Jul 8, 2026
Closing as duplicate — upstream
isContextOverflowinpackages/llm/src/provider-error.tsalready covers all the patterns described here.