Skip to content

fix(provider): Z.AI GLM overflow error not classified as context overflow, causing chain compaction #27629

Closed as not planned

Description

@darkhipo

Description

When Z.AI GLM models (glm-5-turbo, glm-5, glm-5.1) exceed their 200K context window, they return an error that is not recognized by opencode's OVERFLOW_PATTERNS in packages/opencode/src/provider/error.ts. This causes the error to be classified as a generic APICallError instead of ContextOverflowError, preventing auto-compaction and resulting in an unrecoverable chain compaction loop.

Observed Behavior

  1. Session context fills past 200K threshold (common with many MCP tools)
  2. opencode attempts compaction
  3. Z.AI returns: "tokens in request more than max tokens allowed"
  4. opencode classifies this as generic error (not overflow)
  5. No compaction occurs → session retries → same error → infinite loop
  6. Session becomes permanently unusable without DB intervention

Expected Behavior

The error message "tokens in request more than max tokens allowed" should be classified as context overflow, triggering auto-compaction.

Error Text

tokens in request more than max tokens allowed

Root Cause

OVERFLOW_PATTERNS in packages/opencode/src/provider/error.ts does not include a pattern matching Z.AI GLM's overflow error message.

Proposed Fix

Add the following pattern to OVERFLOW_PATTERNS:

/tokens in request more than max tokens allowed/i,

Related Issues

Environment

  • OpenCode version: 1.14.48
  • Provider: zai-coding-plan (GLM-5-Turbo)
  • The GLM-5 family (glm-5, glm-5-turbo, glm-5.1) all share 200K context documentation

Activity

  1. github-actions commented on May 14, 2026

    @github-actions
    Contributor

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

    Please check whether your issue is already covered by #27519 before proceeding. If the fix in #27519 also resolves the Z.AI GLM case, consider adding a comment there with the Z.AI-specific context rather than tracking it separately.

  2. github-actions commented on Jul 14, 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