Skip to content

[Bug]: mXXXX</parameter> hallucinated at end of responses — not stripped, creates feedback loop #555

@jwhandy3

Description

@jwhandy3

Bug Description

In sessions with substantial context, the model occasionally appends mXXXX as a trailing line (where XXXX is the current message number). I confirmed this is LLM-generated by patching createTextCompleteHandler to log output.text before stripHallucinationsFromString runs — the artifact is present in the pre-strip text.
stripHallucinationsFromString only matches `` opening tags, so this passes through, gets stored, and is fed back into subsequent context. Once it's in history the model reproduces it consistently — feedback loop.
This is a different root cause than #488, which theorized XML renderer garbling. This is hallucination.

Expected Behavior

No trailing mXXXX in stored or rendered responses.

Debug Context Logs

{
  "role": "assistant",
  "parts": [
    {
      "type": "text",
      "text": "...Total: maybe 20 lines changed. Clean and reviewable.\n\nm0340</parameter>\n\n"
    }
  ]
}

Tool Call Details

No response

DCP Version

3.1.12

Opencode Version

1.15.12

Model

Claude Sonnet 4

Additional Context

Suggested fix in stripHallucinationsFromString:
text.replace(/\nm\d+</parameter>\s*$/, '')
Pattern is anchored to end-of-string with a required leading newline — can only ever remove the very last line, not mid-text content.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions