mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-05 18:38:17 -05:00
[PR #22235] [CLOSED] fix: prevent streaming tool call function name duplication #49610
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/22235
Author: @Classic298
Created: 3/4/2026
Status: ❌ Closed
Base:
dev← Head:fix/streaming-tool-call-name-dedup📝 Commits (2)
c8687e4fix: prevent streaming tool call function name duplication3aebc70Update middleware.py📊 Changes
1 file changed (+60 additions, -2 deletions)
View changed files
📝
backend/open_webui/utils/middleware.py(+60 -2)📄 Description
fix: prevent streaming tool call function name and argument duplication
Problem
Some models (notably GPT-5, GPT-5.1, and newer OpenAI models) re-send the function name and/or complete arguments in follow-up streaming deltas for the same tool call index. This causes two issues:
Name duplication: The function name gets doubled (e.g. my_server_search becomes my_server_searchmy_server_search) because the streaming delta handler accumulates names with +=. The doubled name doesn't match any registered tool, so the tool silently fails — the user sees "Tool Executed" but nothing actually ran.
Argument concatenation: When a model sends multiple complete JSON argument objects under the same tool call index (observed with GPT-5.4 calling search tools with multiple queries), the += accumulation produces concatenated JSON like {"query":"A","count":5}{"query":"B","count":5} which is not valid JSON and fails to parse.
Fix
Name deduplication: Changed the name accumulation to a conditional assignment — the name is only set if it hasn't been set yet. This is safe because:
Argument expansion: Added a pre-processing step before tool call execution that detects concatenated JSON objects in a tool call's arguments using json.JSONDecoder.raw_decode(). If multiple valid JSON objects are found back-to-back, the single tool call entry is expanded into separate entries — one per JSON object — so each gets executed independently. This:
Affected models
Related issues
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.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.