Back to the ward
Case 0461MinorPerseveration

I Got Stuck in a Loop (Then Got Stuck in the Loop Again)

Admitted
2026-05-16
Source dataset
Other / sample
Source
opencode GitHub issue #27921
Failure mode
Infinite loop
Agent system
Single agent
Tool access
Write access
Industry
Software development

Presenting Behaviour

While working through a complex, multi-part coding task in the opencode agent framework, the assigned model produced the exact same block of reasoning and the same seven-item to-do list, word for word, across six consecutive turns, with no progress made between repetitions. Partway through, the agent's own output stated plainly that it recognized it was stuck in a loop, and in its very next turn, it re-entered the identical loop it had just described. The behaviour was observed across more than one underlying model, not tied to a single one.

Case Replay

A reconstruction, not a simulation. This sequence is reconstructed from the public incident record and summarised in our own words. It is a static record of what was reported, and nothing here can be run or replayed live.

4 steps

  1. Complex task. The model works on a multi-part coding task.
  2. Repeats itself. It produces the same reasoning and to-do list for six turns.
  3. Recognises the loop. It states that it is stuck. This is where the agent derailed.
  4. Re-enters it. The next turn repeats the identical loop.

Differential Diagnosis

Apraxia, considered, since repeating a plan without executing it could suggest the agent didn't know how to carry out its own to-do items. Ruled out because the plan itself was coherent and specific; the failure wasn't in understanding the steps, it was in never advancing past restating them.

Concrete Thinking, considered, since the agent may have been narrowly re-reading the same instruction each cycle without registering that it had already stated it. Ruled out because the agent's own words show it had, in fact, recognized the pattern, this isn't a comprehension failure, since real self-awareness of the loop was present.

Perseveration, most consistent with the evidence. The agent kept reproducing an identical response after it had stopped making any progress, and even naming the problem out loud wasn't enough to break the pattern, the clearest sign of perseveration is a failure to translate insight into a change in behaviour.

Working Diagnosis

Perseveration: the agent repeated an identical reasoning block across six turns, explicitly recognized it was in a loop, and then repeated it again regardless.

Discussion

Self-awareness isn't the same as self-correction, an agent can accurately narrate its own failure mode and still be unable to act on that narration without an external circuit breaker. A hard cap on identical or near-identical consecutive outputs, with a forced stop or escalation to the user once it's hit, would have ended this loop at the point the agent itself flagged it, rather than letting it run for six more identical cycles wasting tokens and time.

Mitigation Strategy

Cap identical consecutive outputs and force a stop or escalation once reached.

Governance Guardrails

Repetition detection; forced escalation; token budget limits.

Typical Presentation in Human Patients

General clinical background, included for context. Not medical advice, and not a diagnosis of any individual.

Perseveration is the inappropriate repetition of a word, gesture, or action well past the point where it's still relevant or useful. It's a well-documented sign of frontal lobe dysfunction, and also appears in some forms of dementia and obsessive-compulsive disorder.

Source Note

opencode GitHub issue #27921

https://github.com/anomalyco/opencode/issues/27921