Skip to content

Thinking mode gets stuck in infinite repetition loop (!!!!!!!!!!) #25129

Closed as not planned

Description

@hholst80

Bug Description

When using opencode with thinking mode, the Qwen 3.6 Pro model gets stuck in a repetitive thinking loop where it outputs repeated characters like !!!!!!!!!!!!!!!!!!... or ... indefinitely instead of producing useful reasoning. I had to switch to a different model (DeepSeek v4 Pro) just to be able to write this bug report, because the Qwen model had become completely unusable.

This manifests as a hanging/corrupted response that the user eventually has to interrupt, and opencode may then produce malformed tool calls (JSON parse errors, truncated function arguments).

Steps to Reproduce

  1. Use opencode with Qwen 3.6 Pro (thinking mode)
  2. Execute a moderate-length session with multiple tool calls
  3. Eventually the thinking blocks start containing infinite repetition of characters like !!!!!!!!! or ...
  4. This corrupts subsequent tool calls (JSON parse errors like JSON Parse error: Expected '}')
  5. At this point the model becomes unusable — even basic commands start producing corrupted output

Expected Behavior

opencode should detect repetitive character patterns in thinking blocks and either:

  • Discard the thinking output and abort the current request
  • Restart the request without the corrupted thinking context

Suggested Fix

Add a guard in the thinking block processing that checks for repeated characters. If any character repeats more than N times consecutively (e.g. 10), discard the thinking output and retry the request. This prevents the repetition from consuming tokens and corrupting the subsequent tool call generation.

Pseudocode:

if re.search(r'(.)\1{10,}', thinking_text):
    # Thinking is in a repetition loop, abort and retry
    raise RepetitiveThinkingError

Environment

  • opencode CLI
  • Model: Qwen 3.6 Pro (via Fireworks AI) — the model that exhibits the bug
  • Switched to: DeepSeek v4 Pro — had to switch models to even write this bug report
  • Workspace filter: /root/capture/classify

Impact

This causes session degradation in long conversations, requiring the user to manually interrupt and restart (or even switch models entirely). Tool calls after the thinking loop are often malformed (truncated JSON), leading to "Invalid input" errors.

Activity

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

    @github-actions
    Contributor

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

    If your issue is distinct (e.g., different root cause or reproduction steps), please clarify how it differs from the above.

  3. removed
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  4. PierrunoYT commented on May 12, 2026

    @PierrunoYT

    I'm experiencing the same issue on Windows (PowerShell). Claude Sonnet 4.6 with medium thinking enabled is essentially unusable in OpenCode — the model gets stuck planning in the thinking trace and never executes the actual tool calls.

  5. eznix86 commented on May 14, 2026

    @eznix86

    same with opencode go (qwen 3.6 plus)

  6. Long-Trinh-Tien commented on May 16, 2026

    @Long-Trinh-Tien

    I'm facing same issue while using qwen 3.6 plus (opencode go sub)

  7. dontcrash commented on Jul 3, 2026

    @dontcrash

    If you use LM Studio:

    lmstudio-ai/lmstudio-bug-tracker#1974 (comment)

    There is a workaround:

    * set env then start lm studio
      ✔️ [BETA] Enable LM Studio Engine Protocol
    
    export LLAMA_ARG_THINK_BUDGET=128
    export LLAMA_ARG_THINK_BUDGET_MESSAGE="... thinking budget exceeded, let's answer now."
    
  8. carstenSpraener commented on Aug 5, 2026

    @carstenSpraener

    Same here: opencode lm-studio qwen36-27B on M5Max.

    My fix: Stop using opencode and switched to hermes. That works perfect.

  9. ekoleszar commented on Aug 15, 2026

    @ekoleszar

    Same class of bug here, but with DeepSeek V4 Flash Free (opencode/deepseek-v4-flash-free) — so it's not Qwen-specific.

    During thinking, the model starts escalating exclamation marks and then gets stuck repeating them indefinitely:

    ¡INTERESANTE!
    ¡¡¡AHORA LO VEO!!!
    ¡¡¡ESPERA!!! ¡¡AHORA LO TENGO!!!
    ¡¡¡AH!!! ¡¡¡AHORA SÍ!!! ¡¡¡YA LO TENGO!!!
    ¡¡¡¿¿¿EL ECHO???!!!
    

    After that it keeps outputting those signs non-stop and never produces a usable response.

    Environment:

    • Model: opencode/deepseek-v4-flash-free
    • OpenCode: 1.18.18
    • OS: Linux x86_64

    When: happened during a long session with multiple tool calls.

    Recovery: the session does not recover after this — the response has to be interrupted manually.

    The escalating ! → !!! → ¡¡¡ pattern is the same degeneration loop described here. A repetition guard in thinking-block processing (abort + retry when a repeated-character pattern is detected, e.g. (.)\1{10,}) would cover this case too, since it's clearly not model-specific.

  10. thdxr commented on Oct 11, 2026

    @thdxr
    Member

    Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.

    — from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

  11. hholst80 commented on Oct 13, 2026

    @hholst80
    Author

    Note to any internet visitor: if you are on an older version you need to upgrade first within the minor before you can upgrade the major (to v2)

    opencode upgrade
    opencode upgrade --major
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