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
- Session context fills past 200K threshold (common with many MCP tools)
- opencode attempts compaction
- Z.AI returns:
"tokens in request more than max tokens allowed"
- opencode classifies this as generic error (not overflow)
- No compaction occurs → session retries → same error → infinite loop
- 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
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_PATTERNSinpackages/opencode/src/provider/error.ts. This causes the error to be classified as a genericAPICallErrorinstead ofContextOverflowError, preventing auto-compaction and resulting in an unrecoverable chain compaction loop.Observed Behavior
"tokens in request more than max tokens allowed"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 allowedRoot Cause
OVERFLOW_PATTERNSinpackages/opencode/src/provider/error.tsdoes not include a pattern matching Z.AI GLM's overflow error message.Proposed Fix
Add the following pattern to
OVERFLOW_PATTERNS:Related Issues
Environment