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
bug: infinite loop when provider returns finishReason "unknown" #19339
When using OpenAI-compatible providers (e.g. GLM-5 Turbo via gateway), the model returns finishReason: "unknown" instead of "stop" or "end_turn". The prompt loop in prompt.ts treats "unknown" as non-terminal (same as "tool-calls"), causing an infinite loop when no tool calls are present.
Steps to reproduce
Configure an OpenAI-compatible provider that returns finishReason: "unknown" (e.g. ZhipuAI GLM-5 Turbo)
Send any message
The session loops indefinitely — each step has finishReason: "unknown" and hasToolCalls: false
Expected behavior
The prompt loop should treat "unknown" as a terminal finish reason (like "stop") when no tool calls are detected, and exit the loop.
Relevant code
packages/opencode/src/session/prompt.ts L324 and L720 — "unknown" is excluded from terminal reasons alongside "tool-calls":
Thanks for the clarification. You're right — #18415 is a different issue (GLM-5 repeating the same actions due to a model-side infra bug), while #19339 and #18813 share the same root cause (non-standard finish reasons being treated as unknown and keeping the prompt loop running). PR #19342 addresses #18813 and #19339 but would not fix #18415.
Activity
github-actions commentedon Mar 26, 2026
This issue might be a duplicate of existing issues. Please check:
finish_reason(treated asunknown), causing the prompt loop to not terminateIf your issue is distinct from these, please clarify the difference. Otherwise, consider adding a reaction or comment to the existing issue instead.
okuyam2y commentedon Mar 26, 2026
This is the same root cause as #18813. Fix PR: #19342
heimoshuiyu commentedon Mar 27, 2026
same root cause as #18813 but not #18415 . In #18813 model stop with unknow/something_their_defined_stop_reason. in #18415 model just response the repeated message. That is their glm-5 infra bug. https://zhipu-ai.feishu.cn/share/base/form/shrcnfiAPrQ3o9CewRdCtXXJwBd
okuyam2y commentedon Mar 27, 2026
Thanks for the clarification. You're right — #18415 is a different issue (GLM-5 repeating the same actions due to a model-side infra bug), while #19339 and #18813 share the same root cause (non-standard finish reasons being treated as
unknownand keeping the prompt loop running). PR #19342 addresses #18813 and #19339 but would not fix #18415.github-actions commentedon Jul 5, 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.