[PR #21050] [CLOSED] fix: Handle unclosed reasoning tags across tool call iterations #80776

Closed
opened 2026-05-13 14:59:56 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/21050
Author: @Classic298
Created: 1/29/2026
Status: Closed

Base: devHead: fix-tags


📝 Commits (2)

  • 0562f1a fix: Handle unclosed reasoning tags across tool call iterations
  • 84a01b8 Merge branch 'dev' into fix-tags

📊 Changes

1 file changed (+34 additions, -12 deletions)

View changed files

📝 backend/open_webui/utils/middleware.py (+34 -12)

📄 Description

Summary

Fixes text duplication and raw tag rendering when models use inline reasoning tags (like ) but don't close them before tool calls.

image

Problem

Some models (e.g., MiniMax M2.1, Kimi K2) output reasoning content using inline tags but don't always close them with before making tool calls. On subsequent iterations:

  1. The closing tag would appear at the start of a new text block, rendering as raw text
  2. New tags would match against stale tags from previous iterations in the accumulated content variable
  3. This caused thinking content to appear as plain text and duplicate across iterations

Solution

  1. Orphaned end tag handling: When a text block starts with a closing tag like , we now look backwards through content_blocks to find an unclosed reasoning block and close it properly
  2. Scoped start tag matching: Changed start tag matching to search in the current text block's content instead of the global accumulated content variable, preventing stale tags from being matched

Testing

Tested with MiniMax M2.1 using multiple tool call iterations with web search - reasoning blocks now render correctly and text no longer duplicates.

Contributor License Agreement

By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.

Note

Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/21050 **Author:** [@Classic298](https://github.com/Classic298) **Created:** 1/29/2026 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `fix-tags` --- ### 📝 Commits (2) - [`0562f1a`](https://github.com/open-webui/open-webui/commit/0562f1a4331d5d24db0655318caf8019b3378a80) fix: Handle unclosed reasoning tags across tool call iterations - [`84a01b8`](https://github.com/open-webui/open-webui/commit/84a01b84733fd2a8d2511195b3a328604e52646f) Merge branch 'dev' into fix-tags ### 📊 Changes **1 file changed** (+34 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/utils/middleware.py` (+34 -12) </details> ### 📄 Description ### Summary Fixes text duplication and raw tag rendering when models use inline reasoning tags (like <think>) but don't close them before tool calls. <img width="1303" height="629" alt="image" src="https://github.com/user-attachments/assets/acf127e1-878d-47a9-8b3a-ef0d0ad2b1f8" /> ### Problem Some models (e.g., MiniMax M2.1, Kimi K2) output reasoning content using inline <think> tags but don't always close them with </think> before making tool calls. On subsequent iterations: 1. The closing </think> tag would appear at the start of a new text block, rendering as raw text 2. New <think> tags would match against stale tags from previous iterations in the accumulated content variable 3. This caused thinking content to appear as plain text and duplicate across iterations ### Solution 1. **Orphaned end tag handling**: When a text block starts with a closing tag like </think>, we now look backwards through content_blocks to find an unclosed reasoning block and close it properly 2. **Scoped start tag matching**: Changed start tag matching to search in the current text block's content instead of the global accumulated content variable, preventing stale tags from being matched ### Testing Tested with MiniMax M2.1 using multiple tool call iterations with web search - reasoning blocks now render correctly and text no longer duplicates. ### Contributor License Agreement By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. > [!NOTE] > Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-13 14:59:56 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#80776