Skip to content

fix(errors): classify Z.AI GLM token-limit message as context overflow (port opencode#35671) - #61725

Closed
teknium1 wants to merge 1 commit into
mainfrom
opencode-port/zai-overflow-classification
Closed

fix(errors): classify Z.AI GLM token-limit message as context overflow (port opencode#35671)#61725
teknium1 wants to merge 1 commit into
mainfrom
opencode-port/zai-overflow-classification

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Z.AI / Zhipu GLM context-overflow errors now classify as context_overflow and route to compression — previously they classified as unknown/retryable, so the agent retried the same oversized request instead of compressing.

Port of anomalyco/opencode#35671 (classify zai token limit overflow). Root cause: Z.AI's overflow message tokens in request more than max tokens allowed (error code 1210) matched no entry in _CONTEXT_OVERFLOW_PATTERNS.

Changes

  • agent/error_classifier.py: add the Z.AI/GLM pattern to _CONTEXT_OVERFLOW_PATTERNS
  • tests/agent/test_error_classifier.py: regression test with the real error shape (code 1210, provider=zai)

Validation

Before After
classify_api_error() on the exact Z.AI 400 body FailoverReason.unknown FailoverReason.context_overflow
tests/agent/test_error_classifier.py 192 pass 193 pass

Bug was reproduced live on current main before the fix (the exact error string returned unknown).

Infographic

zai-glm-overflow

Port from anomalyco/opencode#35671: Z.AI / Zhipu GLM returns
'tokens in request more than max tokens allowed' (error code 1210) on
context overflow. This matched no pattern in _CONTEXT_OVERFLOW_PATTERNS,
so the error classified as unknown/retryable — the agent would retry the
oversized request instead of triggering context compression.

Proven live on main before the fix: classify_api_error() returned
FailoverReason.unknown for the exact Z.AI error shape; now returns
context_overflow.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/zai ZAI provider labels Jul 10, 2026
@teknium1

Copy link
Copy Markdown
Contributor Author

Superseded by the re-authored branch (attribution-check fix): same change on opencode-port/zai-glm-overflow.

@teknium1 teknium1 closed this Jul 10, 2026
@teknium1
teknium1 deleted the opencode-port/zai-overflow-classification branch July 10, 2026 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists provider/zai ZAI provider type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants