mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 02:48:13 -05:00
[PR #23896] feat(plugins): cross-worker tool + function cache invalidation via Redis #50477
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/23896
Author: @Classic298
Created: 4/20/2026
Status: 🔄 Open
Base:
dev← Head:claude/cross-worker-plugin-cache📝 Commits (1)
498a04dfeat(plugins): cross-worker tool + function cache invalidation via Redis📊 Changes
5 files changed (+145 additions, -7 deletions)
View changed files
📝
backend/open_webui/main.py(+4 -0)📝
backend/open_webui/routers/functions.py(+18 -2)📝
backend/open_webui/routers/tools.py(+4 -0)➕
backend/open_webui/utils/plugin_cache.py(+110 -0)📝
backend/open_webui/utils/tools.py(+9 -5)📄 Description
Bug: request.app.state.TOOLS / FUNCTIONS are per-worker Python dicts. Save on worker A does not touch worker B's cache, so worker B keeps serving the stale compiled module until the process restarts. utils/tools.py's invocation path was also completely cache-blind — a bare dict.get with no content-hash fallback, so even same-worker edits skipped the TOOL_CONTENTS check and served the first-seen module forever.
Symptom: editing a tool in the Workspace UI, triggering a chat, and watching the OLD code execute until backend restart. Confirmed on a multi-worker deployment (UVICORN_WORKERS > 1) with Redis.
Fix — three parts:
backend/open_webui/utils/plugin_cache.py (new)
utils/tools.py
TOOLS.get(tool_id)toawait get_tool_module_from_cache(request, tool_id), which does content-hash invalidation from DB. Covers edits that predate or race the Redis pub/sub message.routers/tools.py + routers/functions.py
requestparameter they were missing.main.py lifespan starts the listener alongside the task listener and cancels it on shutdown. No new env vars — reuses REDIS_URL and REDIS_KEY_PREFIX.
Single-worker deployments still work: publish_invalidation unconditionally drops the local cache before trying to publish.
Contributor License Agreement
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.