From 0f46d6096c65117eed1f33a1ee9ffdefbe9568e3 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Thu, 1 Oct 2026 06:14:33 +0200 Subject: [PATCH] fix: server memory grows with every chat until a restart (#31534) Every chat that got a reply left a small lock behind in the server process, so a long-running server kept one for every chat it had ever answered and only a restart gave the memory back. The lock is now dropped as soon as nothing is using it, so a finished reply leaves nothing behind per chat, while replies, sub-agent results and timers for the same chat still wait for each other as before. Fixes #31521 --- backend/open_webui/utils/subagents.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/utils/subagents.py b/backend/open_webui/utils/subagents.py index c38c701845..61893a4900 100644 --- a/backend/open_webui/utils/subagents.py +++ b/backend/open_webui/utils/subagents.py @@ -3,6 +3,7 @@ from __future__ import annotations import asyncio import copy import time +import weakref from datetime import timedelta from uuid import uuid4 @@ -41,7 +42,7 @@ MUTATING_MEMORY_TOOLS = { _background_active: set[str] = set() _background_lock = asyncio.Lock() _foreground_semaphore: asyncio.Semaphore | None = None -_parent_locks: dict[str, asyncio.Lock] = {} +_parent_locks: weakref.WeakValueDictionary[str, asyncio.Lock] = weakref.WeakValueDictionary() def _build_request(source: Request, user_id: str, *, internal: bool) -> Request: