[PR #23073] [CLOSED] fix: Infinite loop when streaming tool message #130674

Closed
opened 2026-05-21 15:08:32 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/23073
Author: @yang1002378395-cmyk
Created: 3/26/2026
Status: Closed

Base: devHead: fix-prefilled-input-reset-v2


📝 Commits (2)

  • dc22bb2 fix: preserve prefilled input value in input event dialog
  • 28926d2 fix: prevent infinite loop when streaming response sends finish_reason: stop followed by tool_calls

📊 Changes

3 files changed (+11 additions, -2 deletions)

View changed files

📝 backend/open_webui/utils/middleware.py (+6 -1)
📝 src/lib/components/chat/Chat.svelte (+3 -0)
📝 src/lib/components/common/ConfirmDialog.svelte (+2 -1)

📄 Description

Issue

Fixes #23066

Problem

When a malformed streaming response sends finish_reason: 'stop' in one chunk and then tool_calls in a subsequent chunk, the code would still process the tool_calls, leading to infinite tool call loops.

Root Cause

The streaming response handler did not validate finish_reason before adding tool_calls to the response_tool_calls list. Even after the stream signaled completion with finish_reason: 'stop', tool calls from subsequent chunks would still be queued for execution.

Fix

Check finish_reason before processing delta_tool_calls. If finish_reason is already 'stop', skip tool_calls processing to prevent the infinite loop.

Changes

  • backend/open_webui/utils/middleware.py: Added finish_reason check before processing delta_tool_calls (line ~3665)

Test Case

The issue provides a reproduction case using a FastAPI server that sends:

  1. Text message with finish_reason: 'stop'
  2. Tool calls with finish_reason: 'tool_calls'

Before fix: infinite loop
After fix: tool calls after finish_reason: 'stop' are ignored

Checklist

  • Code compiles without errors
  • Fix is minimal and targeted
  • Addresses the root cause

🔄 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/23073 **Author:** [@yang1002378395-cmyk](https://github.com/yang1002378395-cmyk) **Created:** 3/26/2026 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `fix-prefilled-input-reset-v2` --- ### 📝 Commits (2) - [`dc22bb2`](https://github.com/open-webui/open-webui/commit/dc22bb226e6ad9a467d449fcd978d4e96948e062) fix: preserve prefilled input value in input event dialog - [`28926d2`](https://github.com/open-webui/open-webui/commit/28926d2773c82b72ba32146b11027e72fe934ec7) fix: prevent infinite loop when streaming response sends finish_reason: stop followed by tool_calls ### 📊 Changes **3 files changed** (+11 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/utils/middleware.py` (+6 -1) 📝 `src/lib/components/chat/Chat.svelte` (+3 -0) 📝 `src/lib/components/common/ConfirmDialog.svelte` (+2 -1) </details> ### 📄 Description ## Issue Fixes #23066 ## Problem When a malformed streaming response sends `finish_reason: 'stop'` in one chunk and then `tool_calls` in a subsequent chunk, the code would still process the `tool_calls`, leading to infinite tool call loops. ## Root Cause The streaming response handler did not validate `finish_reason` before adding tool_calls to the `response_tool_calls` list. Even after the stream signaled completion with `finish_reason: 'stop'`, tool calls from subsequent chunks would still be queued for execution. ## Fix Check `finish_reason` before processing `delta_tool_calls`. If `finish_reason` is already `'stop'`, skip tool_calls processing to prevent the infinite loop. ## Changes - `backend/open_webui/utils/middleware.py`: Added finish_reason check before processing delta_tool_calls (line ~3665) ## Test Case The issue provides a reproduction case using a FastAPI server that sends: 1. Text message with `finish_reason: 'stop'` 2. Tool calls with `finish_reason: 'tool_calls'` Before fix: infinite loop After fix: tool calls after `finish_reason: 'stop'` are ignored ## Checklist - [x] Code compiles without errors - [x] Fix is minimal and targeted - [x] Addresses the root cause --- <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-21 15:08:32 -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#130674