Skip to content

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

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions