Loop in certain models #2478

Open
opened 2026-02-16 17:35:50 -05:00 by yindo · 12 comments
Owner

Originally created by @salavatkhafizov on GitHub (Nov 2, 2025).

Originally assigned to: @rekram1-node on GitHub.

Description

OC 1.0.10. I get loops with certain models (model keep trying the same tool calling/operation) for extended period of time.

  1. KIMI K2 0905, MiniMax 2 - via chutes.ai
  2. GLM 4.6 via Z.ai coding plan.

sometimes remedy comes from /compact operation, sometimes model needs to be stopped (via Esc, abort request operation).

It would be nice if you can introduce setting for OC to invoke autocompact operation at certain context level (like in CC) - circa 80 % and above

OpenCode version

No response

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Originally created by @salavatkhafizov on GitHub (Nov 2, 2025). Originally assigned to: @rekram1-node on GitHub. ### Description OC 1.0.10. I get loops with certain models (model keep trying the same tool calling/operation) for extended period of time. 1) KIMI K2 0905, MiniMax 2 - via chutes.ai 2) GLM 4.6 via Z.ai coding plan. sometimes remedy comes from /compact operation, sometimes model needs to be stopped (via Esc, abort request operation). It would be nice if you can introduce setting for OC to invoke autocompact operation at certain context level (like in CC) - circa 80 % and above ### OpenCode version _No response_ ### Steps to reproduce _No response_ ### Screenshot and/or share link _No response_ ### Operating System _No response_ ### Terminal _No response_
yindo added the model-problemhelp-wantedbug labels 2026-02-16 17:35:50 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Nov 2, 2025):

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

  • #3444: GLM-4.6 model gets stuck in infinite loop, repeating same actions - describes the exact same GLM model behavior with infinite loops
  • #3458: Duplicate Executions in Kimi K2 Model - reports similar repetitive behavior with KIMI K2 model
  • #3561: Tool calls not parsing correctly mid conversation - mentions issues with both KIMI K2 and GLM models

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

@github-actions[bot] commented on GitHub (Nov 2, 2025): This issue might be a duplicate of existing issues. Please check: - #3444: GLM-4.6 model gets stuck in infinite loop, repeating same actions - describes the exact same GLM model behavior with infinite loops - #3458: Duplicate Executions in Kimi K2 Model - reports similar repetitive behavior with KIMI K2 model - #3561: Tool calls not parsing correctly mid conversation - mentions issues with both KIMI K2 and GLM models Feel free to ignore if none of these address your specific case.
Author
Owner

@ravshansbox commented on GitHub (Nov 2, 2025):

I had the same with glm-4.6

@ravshansbox commented on GitHub (Nov 2, 2025): I had the same with glm-4.6
Author
Owner

@zenyr commented on GitHub (Nov 2, 2025):

Under certain circumstances grok-code (grok code fast 1) rarely gets stuck in a thinking loop.
However I am not sure if this is something OC could completely prevent / detect reliably.

So-called doom-loops do exist in many models, maaaybe excluding Claude/GPT models (correct me if I'm wrong). I saw this happening with Gemini 2.5 flash(severely), grok-code-fast-1, kimi-k2, GLM-4.6 across different agentic coding tools. Including but not limited to: Roo code, opencode.

Radically simplified examples:

  • Stuck logically
# thinking
- I should check A. let's try that.
- Wait, maybe I did B? That is more important.
- But I should check A first.
- To do that I need to make sure I did B right.
(and so on and on)
  • Ever increasing tool calls
I need to find A's implementation. let's do that.
tool-call: read-file A.ts offset=1 
let's increase that
tool-call: read-file A.ts offset=1, count=10
let's increase that
tool-call: read-file A.ts offset=1, count=20
let's increase that
tool-call: read-file A.ts offset=1, count=#0
let's increase that
...
  • Ping-pong tool calls
tool-call: Edit A to B
Oh i broke something lets fix that
tool-call: Edit B to A
Now again.
tool-call: Edit A to B
Oh i broke something lets fix that
Let's implement it again.
tool-call: Edit A to B
I made a mistake. reverting.
...
@zenyr commented on GitHub (Nov 2, 2025): Under certain circumstances grok-code (grok code fast 1) rarely gets stuck in a thinking loop. However I am not sure if this is something OC could completely prevent / detect reliably. So-called `doom-loops` do exist in many models, maaaybe excluding Claude/GPT models (correct me if I'm wrong). I saw this happening with Gemini 2.5 flash(severely), grok-code-fast-1, kimi-k2, GLM-4.6 across different agentic coding tools. Including but not limited to: `Roo code`, `opencode`. ### Radically simplified examples: - Stuck logically ``` # thinking - I should check A. let's try that. - Wait, maybe I did B? That is more important. - But I should check A first. - To do that I need to make sure I did B right. (and so on and on) ``` - Ever increasing tool calls ``` I need to find A's implementation. let's do that. tool-call: read-file A.ts offset=1 let's increase that tool-call: read-file A.ts offset=1, count=10 let's increase that tool-call: read-file A.ts offset=1, count=20 let's increase that tool-call: read-file A.ts offset=1, count=#0 let's increase that ... ``` - Ping-pong tool calls ``` tool-call: Edit A to B Oh i broke something lets fix that tool-call: Edit B to A Now again. tool-call: Edit A to B Oh i broke something lets fix that Let's implement it again. tool-call: Edit A to B I made a mistake. reverting. ... ```
Author
Owner

@rekram1-node commented on GitHub (Nov 2, 2025):

We did add some loop detection but as @zenyr points out, there are still some circumstances that it won't quite work

@rekram1-node commented on GitHub (Nov 2, 2025): We did add some loop detection but as @zenyr points out, there are still some circumstances that it won't quite work
Author
Owner

@Nindaleth commented on GitHub (Dec 16, 2025):

I can see mentions of doom_loop in other completed issues and in codebase, I also found the docs for it, but either it's still unclear to me how it works, or it doesn't work.

I asked a local model to

Run four sequential instances of Bash tool, each doing the same "ls ../questionable"
which doesn't exist and fails.

I verified in the local server logs that all the arriving tool calls are exactly the same, 12 tool calls in total (tried multiple times) and no doom loop prevention. Does the tool call itself have to fail, somehow, instead of the actual command running and resulting in a failure exit code?

@Nindaleth commented on GitHub (Dec 16, 2025): I can see mentions of doom_loop in other completed issues and in codebase, I also found the [docs](https://opencode.ai/docs/permissions/#doom_loop) for it, but either it's still unclear to me how it works, or it doesn't work. I asked a local model to > Run four sequential instances of Bash tool, each doing the same "ls ../questionable" which doesn't exist and fails. I verified in the local server logs that all the arriving tool calls are exactly the same, 12 tool calls in total (tried multiple times) and no doom loop prevention. Does the tool call itself have to fail, somehow, instead of the actual command running and resulting in a failure exit code?
Author
Owner

@rekram1-node commented on GitHub (Dec 16, 2025):

can u share the session?

opencode export > session.json

@rekram1-node commented on GitHub (Dec 16, 2025): can u share the session? `opencode export > session.json`
Author
Owner

@Nindaleth commented on GitHub (Dec 16, 2025):

Sure, here's a clean session with the same result (running just the 4 tool calls in this case): session.json

@Nindaleth commented on GitHub (Dec 16, 2025): Sure, here's a clean session with the same result (running just the 4 tool calls in this case): [session.json](https://github.com/user-attachments/files/24201760/session.json)
Author
Owner

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

Same with GLM 4.7 and opencode 1.0.142

@betolink commented on GitHub (Dec 22, 2025): Same with GLM 4.7 and opencode `1.0.142`
Author
Owner

@palekiwi commented on GitHub (Jan 12, 2026):

google/gemini-3-pro-preview frequently ends up in a loop such as:

I'll execute.
I will write the response.
I'll execute.
I will write the response.
I'll execute.
I will write the response.
...
@palekiwi commented on GitHub (Jan 12, 2026): `google/gemini-3-pro-preview` frequently ends up in a loop such as: ``` I'll execute. I will write the response. I'll execute. I will write the response. I'll execute. I will write the response. ... ```
Author
Owner

@gcc-master commented on GitHub (Jan 12, 2026):

Same with GLM 4.7 and opencode 1.0.142

Same situation with GLM 4.7 on cerebras.ai

session.json

Running session from cli "run" like that

        cmd = [
            "opencode",
            "run",
            section,
            "--agent",
            args.agent,
            "--format",
            "default",
            "--file",
            file_arg,
            "--variant",
            "max"
        ]

        result = subprocess.run(cmd, capture_output=True, text=True)
@gcc-master commented on GitHub (Jan 12, 2026): > Same with GLM 4.7 and opencode `1.0.142` Same situation with GLM 4.7 on cerebras.ai [session.json](https://github.com/user-attachments/files/24562587/session.json) Running session from cli "run" like that ``` cmd = [ "opencode", "run", section, "--agent", args.agent, "--format", "default", "--file", file_arg, "--variant", "max" ] result = subprocess.run(cmd, capture_output=True, text=True) ````
Author
Owner

@Nindaleth commented on GitHub (Feb 14, 2026):

doom_loop — triggered when the same tool call repeats 3 times with identical input

(ref)

@palekiwi @gcc-master I don't see any looped tool calls in your attachments, doom_loop is not intended to handle looped text.

On some more experiments, I think the doom loop detector actually works when the model does the tool calls a certain way. On frontier cloud models this works, on local Qwen3 Coder Next 80B this works. Local Devstral 2 Small 24B does something slightly differently and doom loop detection does not trigger for it.

I don't have any API subscription that offers Devstral 2 Small 24B so that I could check that.

@Nindaleth commented on GitHub (Feb 14, 2026): > `doom_loop` — triggered when the same tool call repeats 3 times with identical input ([ref](https://opencode.ai/docs/permissions/#available-permissions)) @palekiwi @gcc-master I don't see any looped tool calls in your attachments, doom_loop is not intended to handle looped **text**. On some more experiments, I think the doom loop detector actually works when the model does the tool calls a certain way. On frontier cloud models this works, on local Qwen3 Coder Next 80B this works. Local Devstral 2 Small 24B does something slightly differently and doom loop detection does not trigger for it. I don't have any API subscription that offers Devstral 2 Small 24B so that I could check that.
Author
Owner

@jurij commented on GitHub (Feb 15, 2026):

same with Kimi K2.5

@jurij commented on GitHub (Feb 15, 2026): same with Kimi K2.5
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#2478