Skip to content

bug: infinite loop when provider returns finishReason "unknown" #19339

Closed as not planned

Description

@okuyam2y

Description

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

  1. Configure an OpenAI-compatible provider that returns finishReason: "unknown" (e.g. ZhipuAI GLM-5 Turbo)
  2. Send any message
  3. 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":

!["tool-calls", "unknown"].includes(processor.message.finish)

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Mar 26, 2026
  2. github-actions commented on Mar 26, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    If your issue is distinct from these, please clarify the difference. Otherwise, consider adding a reaction or comment to the existing issue instead.

  3. okuyam2y commented on Mar 26, 2026

    @okuyam2y
    Author

    This is the same root cause as #18813. Fix PR: #19342

  4. heimoshuiyu commented on Mar 27, 2026

    @heimoshuiyu
    Contributor

    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

  5. okuyam2y commented on Mar 27, 2026

    @okuyam2y
    Author

    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.

  6. removed
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  7. github-actions commented on Jul 5, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions