mirror of
https://github.com/open-webui/open-webui.git
synced 2026-06-04 07:47:12 -05:00
[PR #20299] [CLOSED] fix: resolve infinite recursion and connection pool exhaustion in message retrieval #41181
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/20299
Author: @silentoplayz
Created: 12/31/2025
Status: ❌ Closed
Base:
dev← Head:fix/infinite-recursion-message-retrieval📝 Commits (1)
22571d6fix: resolve infinite recursion and connection pool exhaustion in message retrieval📊 Changes
1 file changed (+65 additions, -14 deletions)
View changed files
📝
backend/open_webui/models/messages.py(+65 -14)📄 Description
Pull Request Checklist
Note to first-time contributors: Please open a discussion post in Discussions to discuss your idea/fix with the community before creating a pull request, and describe your changes before submitting a pull request.
This is to ensure large feature PRs are discussed with the community first, before starting work on it. If the community does not want this feature or it is not relevant for Open WebUI as a project, it can be identified in the discussion before working on the feature and submitting the PR.
Before submitting, make sure you've checked the following:
devbranch. Not targeting thedevbranch will lead to immediate closure of the PR.Changelog Entry
Description
This PR fixes a
RecursionErrorand potential connection pool exhaustion caused by a cyclic dependency in message retrieval methods.The Issue:
The
get_thread_replies_by_message_idmethod calledget_message_by_idto hydrate thereply_to_messagefield. However,get_message_by_idrecursively callsget_thread_replies_by_message_idto populate thread replies. This created an infinite recursion loop when fetching messages that were part of a reply chain or thread, leading to a stack overflow and rapid consumption of database connections.The Fix:
get_message_by_id_slim: A new method that fetches a message and its user without recursively fetching thread replies or other nested relationships.get_thread_replies_by_message_id,get_messages_by_channel_id, andget_messages_by_parent_idto useget_message_by_id_slimwhen populating thereply_to_messagefield. This effectively breaks the recursion cycle.Added
get_message_by_id_slimmethod toMessageTable.Changed
get_thread_replies_by_message_idto useget_message_by_id_slim.get_messages_by_channel_idto useget_message_by_id_slim.get_messages_by_parent_idto useget_message_by_id_slim.Fixed
RecursionError: maximum recursion depth exceeded while calling a Python objectin message retrieval.This PR solves the following error:
Screenshots
Before
After
Additional Information
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.