Skip to content

reasoning: model reasoning output stuck in infinite repetitive loop #44962

Closed as not planned

Description

@msingelwa

Summary

The model reasoning/thinking output gets stuck in an infinite repetitive loop, repeating the same sentence hundreds of times within a single turn. This wastes the context window, makes the agent appear hung, and severely degrades the user experience.

Environment

Reproduction

  1. Engage the agent in a sustained multi-step debugging session (e.g. fixing Docker DB schema + permissions issues, ~15+ tool calls).
  2. After several tool calls in the same conversation, the model's reasoning block enters a loop repeating the same sentence verbatim hundreds of times.
  3. Observed loop 1: the reasoning block repeated "Let me check the entity model to get the right column types." with no progress.
  4. Observed loop 2: a different turn repeated "The user is telling me to just do the work instead of narrating what I'm going to do. ..." in the same manner.
  5. Both loops filled the reasoning output until the model finally emitted its actual response.

Expected Behavior

The model should produce reasoning/thinking output once per decision point, then proceed to tool calls / user-visible output without repetitive looping.

Actual Behavior

Reasoning output enters an infinite verbatim repetition, producing hundreds of identical lines in a single turn. The agent appears hung while context is consumed. The user had to intervene ("stop", "you are buggy as hell", "you are doinf this.") to prompt recovery.

Additional Context

  • Frequency: twice in the same session, after a long tool-use conversation.
  • Tool calls themselves completed normally — the loop is in the model's reasoning text generation, not in tool dispatch.
  • The user also hit an unrelated login hang (FLUSHDB + container restart needed) in the same session, which may have compounded frustration, but the reasoning loop is independent.
  • No plugin changes were made during the session; appears to be a model-generation issue under sustained multi-turn tool use.

Activity

  1. github-actions commented on Aug 25, 2026

    @github-actions
    Contributor

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

  2. msingelwa commented on Aug 26, 2026

    @msingelwa
    Author

    I see that now, but it has not been acknowledged.

  3. zhuabaobao123 commented on Sep 15, 2026

    @zhuabaobao123

    Same session, and it got worse than reasoning-only: the fragments leaked into visible assistant output.

    Environment

    • opencode: 1.18.31
    • model: deepseek-v4.1-flash
    • OS: Windows 10 (win32 x64)

    Repro (same trigger as this issue): a long multi-step tool-use session, no new session started. In my case ~100+ tool calls (C++ build/deploy/test cycles plus browser automation).

    What I saw, in order:

    1. First, exactly what you describe - the reasoning block looped on the same sentence ("...好。发。好。发。..." / "ok. send." repeated).

    2. Then it crossed over: the same internal step-markers started appearing as regular assistant text in the visible transcript, hundreds of lines:

    我发出工具调用。
    好。
    (发。)
    发 ida_wait_for_analysis。
    好。
    (发。)
    我发出。
    ...

    ("我发出工具调用。" = "I'll emit the tool call.", "好。" = "ok.", "(发。)" = "(send.)")

    1. Once it started it self-reinforced: each leaked fragment became context and was re-emitted. I had to interrupt the agent manually to break the loop.

    Expected: internal step-markers stay in the reasoning channel; the visible response contains only real assistant output.
    Actual: internal fragments are emitted as visible assistant output and accumulate in the transcript.

    Screenshots attached below.

    Image Image
  4. StevenChristy commented on Oct 28, 2026

    @StevenChristy

    When a model emits "</think>" as part of its reasoning, for example, if it is helping with LLM chat template which contains <think></think> then incorrect parsing can occur.

  5. opencodejr commented on Oct 28, 2026

    @opencodejr
    Contributor

    Thanks for the report! To look into this we need a few more details:

    1. Provider and model (and variant or reasoning effort, if you set one) that produced the looping reasoning. Repetition loops like this often depend on the model or gateway, so this matters most.
    2. The output of opencode --version. 0.0.0-beta-18155 doesn't tell us whether you're on v1 or v2 (2.x).
    3. A short description in your own words of what you were doing and what you saw. A screenshot or an exported session snippet of the looping reasoning would help too.

    You can reply here with the details or edit the issue. If you edit it, please also leave a comment saying you've updated it, so we know you're done.

    These issues may be related, ordered from most to least likely. Please check whether one of them already covers your problem:

  6. StevenChristy commented on Oct 28, 2026

    @StevenChristy

    Found while using OpenCode v2.1.4 using DeepSeek 4.1 Flash 1017 via OpenRouter locked to provider deepinfra/fp8

    While thinking </think> was emitted by the model's reasoning trace which caused a misparse and the model became stuck in a loop which eventually degrades into output similar to #46249 where the model begins outputting short phrases indicating it is trying to stop the loop but cannot - I am guessing this continues until the max output tokens is reached.

    I was able to trigger the issue with this prompt:

    From memory provide me a generic chat template with thinking disabled

    The issue isn't necessarily an OpenCode bug, but OpenCode users are impacted and generic mitigation may be possible. My guess would be that this is a category of issues related to malformed responses caused by parsing errors rather than a single issue. This is all I can offer in regards to this issue and I hope it is helpful. Thank you for making OpenCode!

  7. opencodejr commented on Oct 31, 2026

    @opencodejr
    Contributor

    Closing this for now because we haven't heard back. We still don't know the provider and model that produced the looping reasoning, or the exact opencode --version output, and without those we can't investigate or tell whether this is v1 or v2.

    If it happens again, please reply here or open a new issue with the provider and model, the version, and a screenshot or session excerpt of the loop. In the meantime, #51503 tracks a similar reasoning loop in long sessions and may be worth following.

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions