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.
This commit is contained in:
Classic298 2026-09-14 02:21:40 +02:00 committed by GitHub
parent 5af01fe604
commit 22d522c558
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 0 deletions

View file

@ -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,

View file

@ -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,