mirror of
https://github.com/open-webui/open-webui.git
synced 2026-07-17 08:21:12 -05:00
[PR #23073] [CLOSED] fix: Infinite loop when streaming tool message #42638
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/23073
Author: @yang1002378395-cmyk
Created: 3/26/2026
Status: ❌ Closed
Base:
dev← Head:fix-prefilled-input-reset-v2📝 Commits (2)
dc22bb2fix: preserve prefilled input value in input event dialog28926d2fix: 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 thentool_callsin a subsequent chunk, the code would still process thetool_calls, leading to infinite tool call loops.Root Cause
The streaming response handler did not validate
finish_reasonbefore adding tool_calls to theresponse_tool_callslist. Even after the stream signaled completion withfinish_reason: 'stop', tool calls from subsequent chunks would still be queued for execution.Fix
Check
finish_reasonbefore processingdelta_tool_calls. Iffinish_reasonis 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:
finish_reason: 'stop'finish_reason: 'tool_calls'Before fix: infinite loop
After fix: tool calls after
finish_reason: 'stop'are ignoredChecklist
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.