mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 10:58:17 -05:00
[PR #21584] [CLOSED] fix: skip memory context injection when system prompt is empty #41779
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/21584
Author: @lesj0610
Created: 2/19/2026
Status: ❌ Closed
Base:
dev← Head:fix/memory-context-system-prompt-gate📝 Commits (10+)
fe6783cMerge pull request #19030 from open-webui/devfc05e0aMerge pull request #19405 from open-webui/deve3faec6Merge pull request #19416 from open-webui/dev9899293Merge pull request #19448 from open-webui/dev140605eMerge pull request #19462 from open-webui/dev6f1486fMerge pull request #19466 from open-webui/devd95f533Merge pull request #19729 from open-webui/deva7271530.6.43 (#20093)6adde20Merge pull request #20394 from open-webui/devf9b0534Merge pull request #20522 from open-webui/dev📊 Changes
1 file changed (+13 additions, -3 deletions)
View changed files
📝
backend/open_webui/utils/middleware.py(+13 -3)📄 Description
Summary
` system messages from being appended.
Why
When the system prompt is intentionally blank, middleware still appended a system message via memory handling. This caused unintended prompt injection and unnecessary context artifacts.
Changes
chat_memory_handler(backend/open_webui/utils/middleware.py):User Contextonly when memory query produced non-empty context.Changelog Entry
Description
User Contextsystem message even when no system prompt was configured.Added
Changed
chat_memory_handlernow skips memory-context system-message injection when the system prompt is blank.Deprecated
Removed
Fixed
` system-message injection.
Security
Breaking Changes
Additional Information
backend/open_webui/utils/middleware.py.Screenshots or Videos
Testing
User Contextsystem message is appended when system prompt is empty.User Contextis appended when system prompt is set and memory returns results.python3 -m compileall backend/open_webui/utils/middleware.pyContributor 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.