Skip to content

GLM / Vertex overflow errors with INVALID_ARGUMENT are not classified as context overflow #23713

Closed as not planned

Description

@karabil

Description

opencode does not seem to classify Google / GLM-style INVALID_ARGUMENT context-limit failures as context overflow, which prevents the normal overflow / compaction path from running.

Version

Observed against local installed opencode --version:

  • 1.14.19

Actual error shape

Bad Request: [{
  "error": {
    "code": 400,
    "message": "Requested token count exceeds the model's maximum context length of 202752 tokens. You requested a total of 211266 tokens: 179266 tokens from the input messages and 32000 tokens for the completion. Please reduce the number of tokens in the input messages or the completion to fit within the limit.",
    "status": "INVALID_ARGUMENT"
  }
}]

Expected behavior

This should be classified as a context overflow / prompt-too-large condition, the same way other provider-specific context-limit messages are handled.

Why I think this is the miss

Current overflow detection in packages/opencode/src/provider/error.ts appears to include patterns like:

  • input token count.*exceeds the maximum
  • maximum context length is \d+ tokens
  • model_context_window_exceeded
  • context_length_exceeded

But not the GLM / Vertex phrasing:

  • Requested token count exceeds the model's maximum context length ...

So this error is likely falling through as a generic API error instead of context_overflow.

Suggested fix

Add an overflow matcher for this message shape, for example:

/requested token count exceeds the model'?s maximum context length/i

Notes

I also validated this locally with a regression test using an APICallError whose responseBody contains the exact JSON body above.

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 21, 2026
  2. github-actions commented on Apr 21, 2026

    @github-actions
    Contributor

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

    If your issue is distinct (e.g., the specific INVALID_ARGUMENT error shape from Vertex/GLM that isn't matched by existing patterns), feel free to clarify that distinction so this can be tracked separately.

  3. karabil commented on Apr 21, 2026

    @karabil
    Author

    This looks distinct from the generic GLM overflow issues because the provider response here is a Vertex/GLM INVALID_ARGUMENT body rather than a finish-reason style overflow signal.

    Observed error shape:

    Bad Request: [{
      "error": {
        "code": 400,
        "message": "Requested token count exceeds the model's maximum context length of 202752 tokens. You requested a total of 211266 tokens: 179266 tokens from the input messages and 32000 tokens for the completion. Please reduce the number of tokens in the input messages or the completion to fit within the limit.",
        "status": "INVALID_ARGUMENT"
      }
    }]
    

    In a local source check, the narrow fix shape was simply to treat this message pattern as a context overflow alongside the existing matchers:

    • Requested token count exceeds the model's maximum context length ...

    Once classified as overflow, the existing compaction path can continue instead of surfacing a generic API error.

  4. removed
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  5. github-actions commented on Jul 4, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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