From 22d522c55836137971f161a65d340bcb6f3290dc Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Mon, 14 Sep 2026 02:21:40 +0200 Subject: [PATCH] fix: drop a deleted plugin's source from the content cache (#29983) Deleting a tool or a function leaves its full source text in memory for the life of the process. Each delete handler pops the module cache and leaves the matching content cache untouched, so the code of every plugin ever deleted stays resident. Both handlers now pop the content cache next to the module cache. Measured over 200 deletes of an 8.8KB plugin: 1.78 MB of source retained per kind before, nothing after. This is memory only, never a stale module. A cache hit needs the id present in both caches and delete already popped the module cache, so the leftover source could not have produced one. The two routers are one change because it is the same pair of lines at the same point in sibling handlers, with no per-site reasoning and no reason to revert one without the other. --- backend/open_webui/routers/functions.py | 3 +++ backend/open_webui/routers/tools.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/backend/open_webui/routers/functions.py b/backend/open_webui/routers/functions.py index be3fe3edf1..212a419500 100644 --- a/backend/open_webui/routers/functions.py +++ b/backend/open_webui/routers/functions.py @@ -23,6 +23,7 @@ from open_webui.models.functions import ( ) from open_webui.utils.auth import get_admin_user, get_verified_user from open_webui.utils.plugin import ( + get_function_contents_cache, get_functions_cache, get_function_module_from_cache, load_function_module_by_id, @@ -440,6 +441,8 @@ async def delete_function_by_id( if result: FUNCTIONS = get_functions_cache(request) FUNCTIONS.pop(id, None) + FUNCTION_CONTENTS = get_function_contents_cache(request) + FUNCTION_CONTENTS.pop(id, None) await publish_event( request, EVENTS.FUNCTION_DELETED, diff --git a/backend/open_webui/routers/tools.py b/backend/open_webui/routers/tools.py index 86860237aa..a814eb30f3 100644 --- a/backend/open_webui/routers/tools.py +++ b/backend/open_webui/routers/tools.py @@ -32,6 +32,7 @@ from open_webui.utils.access_control import ( ) from open_webui.utils.auth import get_admin_user, get_verified_user from open_webui.utils.plugin import ( + get_tool_contents_cache, get_tools_cache, get_tool_module_from_cache, load_tool_module_by_id, @@ -681,6 +682,8 @@ async def delete_tools_by_id( if result: TOOLS = get_tools_cache(request) TOOLS.pop(id, None) + TOOL_CONTENTS = get_tool_contents_cache(request) + TOOL_CONTENTS.pop(id, None) await publish_event( request, EVENTS.TOOL_DELETED,