openclaw - 💡(How to fix) Fix bug(models): Google provider fails to parse <think>/<final> tags, leaking reasoning and truncating replies

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

When using Google Gemini models (such as gemini-3.1-pro-preview or gemini-3.5-flash), OpenClaw's output parser fails to correctly parse and strip the <think>...</think> and <final>...</final> tag structure.

This results in severe UX issues where internal reasoning is leaked, and the actual final response is often truncated or completely hidden.

Root Cause

While OpenClaw correctly flags and hides native reasoning for providers like DeepSeek, or applies robust tag-stripping for some models, the Google Gemini provider adapter does not seem to recognize or split the custom <think> and <final> XML-like blocks from the stream.

As a result, the entire raw output (including <think> and the <final> tags) is treated as the visible assistant text.

RAW_BUFFERClick to expand / collapse

Description

When using Google Gemini models (such as gemini-3.1-pro-preview or gemini-3.5-flash), OpenClaw's output parser fails to correctly parse and strip the <think>...</think> and <final>...</final> tag structure.

This results in severe UX issues where internal reasoning is leaked, and the actual final response is often truncated or completely hidden.

Symptoms

  1. Reasoning Leak: The content within <think>...</think> is printed directly as visible assistant message text in WebChat, instead of being flagged as isReasoning: true or stripped.
  2. Tag Leak: The closing </final> tag is printed at the end of the assistant's message.
  3. Severe Truncation: Because the model outputs a long thinking process inside <think>, the total message length easily hits WebChat's size bounds (e.g., chatHistoryMaxChars limit), causing the message to be truncated before the <final> block is reached. The user never gets to see the actual answer!

Cause

While OpenClaw correctly flags and hides native reasoning for providers like DeepSeek, or applies robust tag-stripping for some models, the Google Gemini provider adapter does not seem to recognize or split the custom <think> and <final> XML-like blocks from the stream.

As a result, the entire raw output (including <think> and the <final> tags) is treated as the visible assistant text.

Suggested Fix

Update the Google/Gemini provider parser (or the global stream parser) to:

  1. Detect <think>...</think> blocks in the incoming stream from Gemini models and correctly map them to the isReasoning: true metadata (excluding them from the visible message content).
  2. Strip <final> and </final> tags from the final visible WebChat display payload so they do not leak into the UI.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING