mirror of
https://github.com/open-webui/open-webui.git
synced 2026-06-06 16:58:36 -05:00
[PR #24835] [CLOSED] fix: strip orphan tool_calls in convert_output_to_messages #131548
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/24835
Author: @kindredzhang
Created: 5/17/2026
Status: ❌ Closed
Base:
dev← Head:fix/24758-orphan-tool-calls-v2📝 Commits (1)
10ac911fix: strip orphan tool_calls in convert_output_to_messages📊 Changes
1 file changed (+22 additions, -1 deletions)
View changed files
📝
backend/open_webui/utils/misc.py(+22 -1)📄 Description
Pull Request Checklist
Closes #24758devfixDescription
When resuming a chat that previously triggered tool calls, the conversation can fail with a 400 error from strict LLM providers (AWS Bedrock, Anthropic). The root cause is in
convert_output_to_messages()inmisc.py:Strict providers enforce that every
tool_useid has a matchingtool_resultblock immediately after. Iffunction_call_outputis missing from stored history (e.g., KB state changed between turns), the orphanedtool_callscause:Fix
After
flush_pending()at the end ofconvert_output_to_messages, scan the produced messages and collect alltool_call_idvalues from tool role messages. Then walk the messages again and strip anytool_callswhose id has no match. If stripping leaves an assistant message with empty content and notool_calls, drop it entirely. Well-formed sequences are unaffected since the check is a no-op when all ids match.Root Cause
convert_output_to_messagesassumes everyfunction_callwill be followed by afunction_call_outputbefore the function returns. When that assumption is violated (DB never wrote it, KB update cleared it, etc.), the finalflush_pending()emits a malformed assistant message.Validation
Changelog Entry
Fixed
convert_output_to_messagesnow strips orphantool_callsthat lack a matchingtoolrole message, preventing 400 errors from strict providers (AWS Bedrock, Anthropic) when chat history is resumed with missingfunction_call_outputentries.Screenshots or Videos
Not applicable; backend logic fix, no UI change.
Contributor License Agreement
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.