Skip to content

[Bug]: Malformed reasoning output can leak into user-visible and persisted assistant text when reply contains trailing </think> without a valid opening tag #67092

Description

@AnildoSilva

Bug type

Regression (worked before, now fails)

Beta release blocker

No

Summary

I observed a reasoning-leak issue in an OpenClaw + Ollama environment where internal reasoning text was not only shown in the UI, but also persisted into session .jsonl history.

The affected reply shape looked like:

[reasoning prose] </think> [final answer]

In this malformed case, the reasoning text survived visible-text sanitization and was treated as normal assistant content.

Workaround

A local workaround that worked for us was to add a sanitizer fallback with this behavior:

  • find the last </think> in assistant text
  • if there is non-empty text before and after it
  • keep only the text after </think>

In other words, for malformed replies shaped like:

[reasoning prose] </think> [final answer]

the sanitizer returns only:

[final answer]

Suggested Fix

Strengthen assistant visible-text sanitization so malformed reasoning output is safely removed even when:

  • there is only a trailing </think>
  • reasoning prose appears outside a valid tagged block
  • upstream output is partially malformed or mixed into a normal text block

During the same investigation, we also encountered separate Ollama memory-pressure/timeouts under concurrent multi-user use of a large model. That appeared to be an operational capacity issue, not the root cause of the reasoning leak itself.

Steps to reproduce

Run OpenClaw with an Ollama-backed reasoning-capable model.
2. Start a new assistant session.
3. Send a simple message such as:

  • Hi Neo! How are you today?
  • or trigger a startup/session greeting flow
  1. Observe cases where the upstream assistant output becomes malformed and contains:
    • reasoning prose
    • a trailing </think>
    • then the final answer
  2. Inspect:
    • the visible reply in the UI
    • the corresponding session .jsonl file

Expected behavior

  • Internal reasoning should not be shown to the user.
  • Internal reasoning should not be persisted as normal assistant-visible content.
  • Sanitization should remain safe even when upstream output is malformed or only partially tagged.

Actual behavior

  • Internal reasoning text is shown to the user.
  • The leaked reasoning is also persisted into session history as assistant text.
  • Config-level settings intended to keep thinking/reasoning off are not sufficient in the affected malformed-output path.

OpenClaw version

2026.4.8

Operating system

Ubuntu

Install method

docker

Model

Local Ollama

Provider / routing chain

Openclaw -> Ollama

Additional provider/model setup details

Environment

  • OpenClaw runtime
  • Ollama backend
  • Reasoning-capable model path
  • Observed during embedded assistant runs
  • Affected channels in our case included web chat, and related persisted session history

Logs, screenshots, and evidence

Impact and severity

This issue is more serious than a cosmetic UI leak because the reasoning text may also be written into persisted session history.

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingregressionBehavior that previously worked and now fails

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions