Agent Zero AI framework
Cache empty plugin lookup results
Alessandro965c4d07be7a
diff --git a/helpers/plugins.py b/helpers/plugins.pyindex 4441cbea0..8ba4587c0 100644--- a/helpers/plugins.py+++ b/helpers/plugins.py@@ -242,7 +242,7 @@ def get_plugin_name_from_path(path: str | Path) -> str:def get_plugins_list():- if cached := cache.get(PLUGINS_LIST_CACHE_AREA, ""):+ if (cached := cache.get(PLUGINS_LIST_CACHE_AREA, "")) is not None:return cachedresult: list[str] = []@@ -445,9 +445,11 @@ def get_plugin_paths(*subpaths: str) -> List[str]:def get_enabled_plugin_paths(agent: Agent | None, *subpaths: str) -> List[str]:- if cached := cache.get(- ENABLED_PLUGINS_PATHS_CACHE_AREA, cache.determine_cache_key(agent, *subpaths)- ):+ if (+ cached := cache.get(+ ENABLED_PLUGINS_PATHS_CACHE_AREA, cache.determine_cache_key(agent, *subpaths)+ )+ ) is not None:return cachedenabled = get_enabled_plugins(agent)@@ -476,9 +478,11 @@ def get_enabled_plugin_paths(agent: Agent | None, *subpaths: str) -> List[str]:def get_enabled_plugins(agent: Agent | None):- if cached := cache.get(- ENABLED_PLUGINS_LIST_CACHE_AREA, cache.determine_cache_key(agent)- ):+ if (+ cached := cache.get(+ ENABLED_PLUGINS_LIST_CACHE_AREA, cache.determine_cache_key(agent)+ )+ ) is not None:return cachedplugins = get_plugins_list()diff --git a/helpers/plugins.py.dox.md b/helpers/plugins.py.dox.mdindex 6eb0310f3..82a22f9d7 100644--- a/helpers/plugins.py.dox.md+++ b/helpers/plugins.py.dox.md@@ -53,6 +53,7 @@stale global or scoped disable files, and disable attempts are rejected.- Config hooks receive `hook_context={"caller": caller}` with one of `ui`,`agent`, or `api`; this is behavioral context, not an authorization boundary.+- Plugin list, enabled-plugin, and enabled-path lookups cache empty results like any other value; `clear_plugin_cache` and plugin watchdog events invalidate them.- Project- and agent-scoped plugin changes invalidate runtime caches without afrontend reload prompt because the loaded WebUI extension bundle is global.- Update this file whenever public functions, classes, persistence behavior, path/security assumptions, side effects, or cross-module contracts change.diff --git a/tests/test_plugin_activation_ui.py b/tests/test_plugin_activation_ui.pyindex 7799b7f29..e76b10b2e 100644--- a/tests/test_plugin_activation_ui.py+++ b/tests/test_plugin_activation_ui.py@@ -77,6 +77,23 @@ def test_always_enabled_plugin_ignores_disable_files_at_runtime(monkeypatch):assert plugins.get_enabled_plugins(None) == ["_required"]+def test_enabled_plugin_paths_cache_empty_results(monkeypatch):+ lookups = []+ monkeypatch.setattr(plugins, "get_enabled_plugins", lambda _agent: ["example"])+ monkeypatch.setattr(+ plugins,+ "find_plugin_dir",+ lambda name: lookups.append(name) or "/nonexistent/example",+ )+ plugins.cache.clear(plugins.ENABLED_PLUGINS_PATHS_CACHE_AREA)++ assert plugins.get_enabled_plugin_paths(None, "tools", "missing_probe.py") == []+ assert plugins.get_enabled_plugin_paths(None, "tools", "missing_probe.py") == []+ assert lookups == ["example"]++ plugins.cache.clear(plugins.ENABLED_PLUGINS_PATHS_CACHE_AREA)++def test_always_enabled_plugin_rejects_disable_attempt(monkeypatch):monkeypatch.setattr(plugins,