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.
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.