[PR #23087] [CLOSED] fix: handle finish_reason in streaming to prevent infinite loop with tool_calls #81892

Closed
opened 2026-05-13 16:18:25 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

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

Base: devHead: fix-streaming-tool-calls-loop


📝 Commits (1)

  • 45f9ff4 fix: handle finish_reason in streaming to prevent infinite loop with tool_calls

📊 Changes

1 file changed (+17 additions, -1 deletions)

View changed files

📝 src/lib/apis/streaming/index.ts (+17 -1)

📄 Description

Issue

Fixes #23066

Problem

When using streaming responses with tool calls, Open WebUI would get stuck in an infinite loop if the server sent finish_reason: 'tool_calls'. This is because the streaming parser only checked for [DONE] but ignored OpenAI's standard finish_reason field.

Root Cause

In src/lib/apis/streaming/index.ts, the openAIStreamToIterator function:

  • Only yielded delta.content for streaming
  • Did not check finish_reason from choices[0].finish_reason
  • Did not stop streaming when finish_reason was 'tool_calls' or 'stop'

Solution

  1. Extract delta and finish_reason from parsed data
  2. Stop streaming when finish_reason equals 'tool_calls'
  3. Stop streaming when finish_reason equals 'stop'
  4. Continue yielding content for all other cases

Testing

  • When a server sends finish_reason: 'tool_calls', the stream now properly terminates
  • Prevents infinite loops when using custom OpenAI-compatible servers that stream tool calls
  • Maintains backward compatibility with existing content streaming

Checklist

  • I have read and followed all instructions in README.md
  • The proposed changes are minimal and targeted
  • I have tested the fix (manual testing)

🔄 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/23087 **Author:** [@yang1002378395-cmyk](https://github.com/yang1002378395-cmyk) **Created:** 3/26/2026 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `fix-streaming-tool-calls-loop` --- ### 📝 Commits (1) - [`45f9ff4`](https://github.com/open-webui/open-webui/commit/45f9ff407702206a8ac74a1e2cb807df3314e612) fix: handle finish_reason in streaming to prevent infinite loop with tool_calls ### 📊 Changes **1 file changed** (+17 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/lib/apis/streaming/index.ts` (+17 -1) </details> ### 📄 Description ## Issue Fixes #23066 ## Problem When using streaming responses with tool calls, Open WebUI would get stuck in an infinite loop if the server sent `finish_reason: 'tool_calls'`. This is because the streaming parser only checked for `[DONE]` but ignored OpenAI's standard `finish_reason` field. ## Root Cause In `src/lib/apis/streaming/index.ts`, the `openAIStreamToIterator` function: - Only yielded `delta.content` for streaming - Did not check `finish_reason` from `choices[0].finish_reason` - Did not stop streaming when `finish_reason` was 'tool_calls' or 'stop' ## Solution 1. Extract `delta` and `finish_reason` from parsed data 2. Stop streaming when `finish_reason` equals 'tool_calls' 3. Stop streaming when `finish_reason` equals 'stop' 4. Continue yielding content for all other cases ## Testing - When a server sends `finish_reason: 'tool_calls'`, the stream now properly terminates - Prevents infinite loops when using custom OpenAI-compatible servers that stream tool calls - Maintains backward compatibility with existing content streaming ## Checklist - [x] I have read and followed all instructions in README.md - [x] The proposed changes are minimal and targeted - [x] I have tested the fix (manual testing) --- <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 16:18:25 -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#81892