mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-08 12:58:11 -05:00
[PR #22723] [CLOSED] FIX: merge tool citations and RAG sources instead of overwriting #26830
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/22723
Author: @IllimarR
Created: 3/16/2026
Status: ❌ Closed
Base:
dev← Head:fix/merge-sources📝 Commits (1)
a1ce262fix: merge tool citations and RAG sources instead of overwriting📊 Changes
2 files changed (+17 additions, -6 deletions)
View changed files
📝
backend/open_webui/models/chats.py(+11 -4)📝
src/lib/components/chat/Chat.svelte(+6 -2)📄 Description
Pull Request Checklist
Before submitting, make sure you've checked the following:
devbranch. PRs targetingmainwill be immediately closed.devto ensure no unrelated commits (e.g. frommain) are included. Push updates to the existing PR branch instead of closing and reopening.Changelog Entry
Description
When tools emit citations via
__event_emitter__and the chat also has RAG/Knowledge files attached, both frontend and backend now merge the two sources lists instead of one silently replacing the other.Root cause: There are two independent systems that write
sourcesto the assistant message, and they conflict:Tool citations (Path A): During tool execution, the tool emits
type: "citation"events. The WebSocket handler appends these tomessage.sourcesand saves to DB. The frontend receivessource/citationevents and appends tomessage.sources.RAG/Knowledge sources (Path B): After tool execution,
chat_completion_files_handlercollects RAG sources from attached knowledge files. These are emitted aschat:completionevents and saved to DB viaupsert_message.Frontend overwrite (
Chat.svelte): Thechat:completionhandler checksif (sources && !message?.sources)— but by this point tool citations from Path A have already setmessage.sources, so RAG sources are silently skipped.Backend overwrite (
chats.py):upsert_messagedoes a shallow dict merge ({**existing, **message}), so the Path Bsourceskey completely replaces the Path A tool citations. On page reload, only Path B sources appear.Result: Users never see both tool citations AND RAG sources together — during a live session only tool citations are visible, and after page reload only RAG sources are visible.
How to reproduce
__event_emitter__(e.g., a web search or custom search tool)Added
Changed
Chat.svelte): Changed thechat:completionsource handler from skipping RAG sources when tool citations exist to concatenating both listschats.py): Changedupsert_messageto mergesourceslists (with deduplication) instead of shallow-overwritingDeprecated
Removed
Fixed
Security
Breaking Changes
Additional Information
not indeduplication to prevent duplicate sources when the same source appears in both pathsfor key in ("sources",)is written for extensibility — other list-type fields can be added to the tuple if needed in the future!message?.sources), both frontend and backend behavior is identical to beforeScreenshots or Videos
Contributor License Agreement
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.