Skip to content

bug: context overflow errors from non-OpenAI providers not detected, causing retry loops #35918

Closed as not planned

Description

@EZotoff

Describe the bug

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

  1. Use a GLM model (e.g., zai-coding-plan/glm-5.1) with a 200K context window
  2. Fill the context to ~190K tokens
  3. Send a message
  4. 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.

Environment

  • OpenCode 1.17.9
  • Providers: GLM, Moonshot, DeepSeek

Activity

  1. github-actions commented on Jul 8, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    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.

  2. rekram1-node commented on Jul 8, 2026

    @rekram1-node
    Collaborator

    are u sure u read the code correctly, we already have this, ur pr is duplicating code we already have

  3. EZotoff commented on Jul 8, 2026

    @EZotoff
    Author

    Closing as duplicate — upstream isContextOverflow in packages/llm/src/provider-error.ts already covers all the patterns described here.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions