You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
z.ai/zhipuai finish_reason: "model_context_window_exceeded" is treated as unknown, causing loop instead of stopping #18813
Some providers appear to return a non-standard finish reason:
finish_reason: "model_context_window_exceeded"
Based on internet search, this was introduced on Anthropic side, and z.ai seems to follow the same behavior when context is too long.
In OpenCode, this finish reason is currently treated as unknown (instead of length), which can cause the session loop to continue rather than stop/compact, resulting in repeated/infinite loops sending request.
This is one of the repeated assistant message exported from session:
Treat model_context_window_exceeded as length (or equivalent overflow handling).
Stop current generation and trigger normal overflow/compaction flow, instead of continuing with unknown.
changed the title [-]Anthropic/z.ai finish_reason: "model_context_window_exceeded" is treated as unknown, causing loop instead of stopping[/-][+]z.ai/zhipuai finish_reason: "model_context_window_exceeded" is treated as unknown, causing loop instead of stopping[/+]on Mar 24, 2026
The z.ai development team stated that model_context_window_exceeded means that the validation exceeded the allowed length before the model start processing, resulting in an error. length means that the output was incomplete. They believe their approach is correct.
Activity
github-actions commentedon Mar 23, 2026
This issue might be a duplicate of existing issues. Please check:
heimoshuiyu commentedon Mar 23, 2026
I think this is a problem of
vercel ai sdkor z.ai not follow the standard value.[-]Anthropic/z.ai finish_reason: "model_context_window_exceeded" is treated as unknown, causing loop instead of stopping[/-][+]z.ai/zhipuai finish_reason: "model_context_window_exceeded" is treated as unknown, causing loop instead of stopping[/+]heimoshuiyu commentedon Mar 24, 2026
The z.ai development team stated that
model_context_window_exceededmeans that the validation exceeded the allowed length before the model start processing, resulting in an error.lengthmeans that the output was incomplete. They believe their approach is correct.fix(provider): map model_context_window_exceeded to length finish reason
okuyam2y commentedon Mar 26, 2026
Fix PR: #19342 — removes
"unknown"from the non-terminal finish reason list so the prompt loop exits correctly.github-actions commentedon Jul 3, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.