GLM-4.6 model gets stuck in infinite loop, repeating same actions #2280

Closed
opened 2026-02-16 17:34:57 -05:00 by yindo · 5 comments
Owner

Originally created by @ElecTwix on GitHub (Oct 25, 2025).

When using the GLM-4.6 model with opencode, the agent sometimes gets stuck in an infinite loop where it performs the same actions repeatedly instead of progressing through the task. This behavior doesn't occur with Claude Code or other models.

Steps to reproduce:

  1. Use opencode with GLM-4.6 model (via z.ai plan provider)
  2. Give a moderately complex task that requires multiple steps
  3. Observe that the agent starts repeating the same tool calls or actions
  4. The agent continues this loop indefinitely without completing the task

Expected behavior:

The agent should progress through the task logically, completing each step and moving to the next one, similar to how Claude Code behaves.

Actual behavior:

The GLM-4.6 model gets stuck repeating the same actions in a loop, never progressing to complete the task.

Environment:

  • Model: GLM-4.6 (z.ai plan provider)
  • Other models work fine (Claude Code, etc.)

Additional context:

This appears to be specific to the GLM-4.6 model's behavior or how it processes the opencode tool system. The issue doesn't occur with other models, suggesting it's not a general opencode bug but rather a model-specific interaction problem.

Image Image
Originally created by @ElecTwix on GitHub (Oct 25, 2025). When using the GLM-4.6 model with opencode, the agent sometimes gets stuck in an infinite loop where it performs the same actions repeatedly instead of progressing through the task. This behavior doesn't occur with Claude Code or other models. ## Steps to reproduce: 1. Use opencode with GLM-4.6 model (via z.ai plan provider) 2. Give a moderately complex task that requires multiple steps 3. Observe that the agent starts repeating the same tool calls or actions 4. The agent continues this loop indefinitely without completing the task ## Expected behavior: The agent should progress through the task logically, completing each step and moving to the next one, similar to how Claude Code behaves. ## Actual behavior: The GLM-4.6 model gets stuck repeating the same actions in a loop, never progressing to complete the task. ## Environment: - Model: GLM-4.6 (z.ai plan provider) - Other models work fine (Claude Code, etc.) ## Additional context: This appears to be specific to the GLM-4.6 model's behavior or how it processes the opencode tool system. The issue doesn't occur with other models, suggesting it's not a general opencode bug but rather a model-specific interaction problem. <img width="598" height="876" alt="Image" src="https://github.com/user-attachments/assets/07f8ecb2-1c66-40d3-be89-6727ce183ec6" /> <img width="1817" height="801" alt="Image" src="https://github.com/user-attachments/assets/b76925b9-d7d3-4588-832c-937951bbf75c" />
yindo closed this issue 2026-02-16 17:34:57 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Oct 25, 2025):

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

  • #2052: Subagents often getting stuck into tool usage loops (describes similar repetitive tool calling behavior)
  • #3038: The model loops attempting to edit files in PLAN mode (model repeatedly tries same actions instead of progressing)
  • #3209: Issue with automatic migrations and infinite loop (gets stuck in endless loop when operations fail)
  • #262: gemini "i'm finished" loop (model-specific infinite loop behavior)
  • #1682: BUG: dumps system prompt in an infinite loop for absolutely no reason (infinite repetition of system prompts)

While these issues involve different models or specific scenarios, they all share the common pattern of models getting stuck in repetitive loops instead of progressing through tasks. The GLM-4.6 specific behavior you're experiencing may be related to how this model handles tool calling or task progression in the opencode environment.

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Oct 25, 2025): This issue might be a duplicate of existing issues. Please check: - #2052: Subagents often getting stuck into tool usage loops (describes similar repetitive tool calling behavior) - #3038: The model loops attempting to edit files in PLAN mode (model repeatedly tries same actions instead of progressing) - #3209: Issue with automatic migrations and infinite loop (gets stuck in endless loop when operations fail) - #262: gemini "i'm finished" loop (model-specific infinite loop behavior) - #1682: BUG: dumps system prompt in an infinite loop for absolutely no reason (infinite repetition of system prompts) While these issues involve different models or specific scenarios, they all share the common pattern of models getting stuck in repetitive loops instead of progressing through tasks. The GLM-4.6 specific behavior you're experiencing may be related to how this model handles tool calling or task progression in the opencode environment. Feel free to ignore if none of these address your specific case.
Author
Owner

@rekram1-node commented on GitHub (Oct 25, 2025):

@ElecTwix yeah some models like glm 4.6 and grok code get into these doom loops, I heard things like kilo code have loop detection to help prevent this, I think we may wanna add something similar to be more defensive for the user

This is just the model being dumb, it can happen regardless of harness but we should yeah detect and try to prevent if we can

@rekram1-node commented on GitHub (Oct 25, 2025): @ElecTwix yeah some models like glm 4.6 and grok code get into these doom loops, I heard things like kilo code have loop detection to help prevent this, I think we may wanna add something similar to be more defensive for the user This is just the model being dumb, it can happen regardless of harness but we should yeah detect and try to prevent if we can
Author
Owner

@rekram1-node commented on GitHub (Oct 30, 2025):

Note for future, if anyone sees this behavior again just provide the example and we can improve the doom loop detection to try to handle more cases, right now we made a dumb but useful detection but it can be a bit smarter in the future if need be

@rekram1-node commented on GitHub (Oct 30, 2025): Note for future, if anyone sees this behavior again just provide the example and we can improve the doom loop detection to try to handle more cases, right now we made a dumb but useful detection but it can be a bit smarter in the future if need be
Author
Owner

@betolink commented on GitHub (Dec 22, 2025):

I just ran into this with GLM 4.7, I read that there is a PR that got merged to detect this infinite loops but at least in this case it didn't work. Is this a model or an opencode issue?

@betolink commented on GitHub (Dec 22, 2025): I just ran into this with GLM 4.7, I read that there is a PR that got merged to detect this infinite loops but at least in this case it didn't work. Is this a model or an opencode issue?
Author
Owner

@TrentBrown commented on GitHub (Jan 6, 2026):

This just happened to me twice today. The model was endlessly executing git commands in one case.

@TrentBrown commented on GitHub (Jan 6, 2026): This just happened to me twice today. The model was endlessly executing git commands in one case.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#2280