[PR #23013] [CLOSED] fix: rewire orphan tool messages to preserve conversation context #130640

Closed
opened 2026-05-21 15:04:51 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/23013
Author: @Classic298
Created: 3/25/2026
Status: Closed

Base: devHead: tool-call


📝 Commits (6)

  • 11c56f0 fix: orphaned tool msg
  • 7ae05b5 fix: rewire orphan tool messages instead of dropping them
  • 1b507ae fix: rewire orphan tool messages with real tool names
  • 0650ebc fix: log and handle streaming provider error responses
  • 36f2b5b fix: surface provider errors that were silently swallowed
  • 4c1ac90 fix: log provider errors from response body (non-exception path)

📊 Changes

4 files changed (+167 additions, -9 deletions)

View changed files

📝 backend/open_webui/main.py (+2 -2)
📝 backend/open_webui/routers/openai.py (+10 -0)
📝 backend/open_webui/utils/middleware.py (+23 -3)
📝 backend/open_webui/utils/misc.py (+132 -4)

📄 Description

Summary

  • When chat history reconstruction produces tool_result messages without a matching tool_use (e.g. partial history, retries, edited chains), strict providers like Anthropic/Vertex reject the payload with HTTP 400
  • Instead of dropping orphan tool messages (losing context), we now rewire them by injecting a synthetic tool_call into the preceding assistant message so the sequence stays valid
  • Applies at both the output→message conversion layer (convert_output_to_messages) and the final message sanitization pass (rewire_orphan_tool_messages)

Contributor License Agreement

Note

Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.


🔄 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/23013 **Author:** [@Classic298](https://github.com/Classic298) **Created:** 3/25/2026 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `tool-call` --- ### 📝 Commits (6) - [`11c56f0`](https://github.com/open-webui/open-webui/commit/11c56f05fc968f5bf30ac34a6d2857b174ddfbb7) fix: orphaned tool msg - [`7ae05b5`](https://github.com/open-webui/open-webui/commit/7ae05b5b03c314008d22fe34d42d5c8c0ae8c8af) fix: rewire orphan tool messages instead of dropping them - [`1b507ae`](https://github.com/open-webui/open-webui/commit/1b507aed0528c85f57b4e8b6a0ce46cd0c4e7801) fix: rewire orphan tool messages with real tool names - [`0650ebc`](https://github.com/open-webui/open-webui/commit/0650ebcd480c1ba32d182df6a7d3f6573bf83782) fix: log and handle streaming provider error responses - [`36f2b5b`](https://github.com/open-webui/open-webui/commit/36f2b5bde4c9ca07fe42b88d4c6b9142aa1e09c9) fix: surface provider errors that were silently swallowed - [`4c1ac90`](https://github.com/open-webui/open-webui/commit/4c1ac90b0f8dc116224ea1ed910e97037c5b12e4) fix: log provider errors from response body (non-exception path) ### 📊 Changes **4 files changed** (+167 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/main.py` (+2 -2) 📝 `backend/open_webui/routers/openai.py` (+10 -0) 📝 `backend/open_webui/utils/middleware.py` (+23 -3) 📝 `backend/open_webui/utils/misc.py` (+132 -4) </details> ### 📄 Description ## Summary - When chat history reconstruction produces `tool_result` messages without a matching `tool_use` (e.g. partial history, retries, edited chains), strict providers like Anthropic/Vertex reject the payload with HTTP 400 - Instead of dropping orphan tool messages (losing context), we now **rewire** them by injecting a synthetic `tool_call` into the preceding assistant message so the sequence stays valid - Applies at both the output→message conversion layer (`convert_output_to_messages`) and the final message sanitization pass (`rewire_orphan_tool_messages`) ### Contributor License Agreement <!-- 🚨 DO NOT DELETE THE TEXT BELOW 🚨 Keep the "Contributor License Agreement" confirmation text intact. Deleting it will trigger the CLA-Bot to INVALIDATE your PR. Your PR will NOT be reviewed or merged until you check the box below confirming that you have read and agree to the terms of the CLA. --> - [X] By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. > [!NOTE] > Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in. --- <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:04:51 -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#130640