From 41e59f6126d49e93a47e8bf027bb18054bdeca55 Mon Sep 17 00:00:00 2001 From: Erosika Date: Thu, 2 Jul 2026 18:42:31 -0400 Subject: [PATCH] fix(memory): retry failed config schema loads instead of caching None A syntax error in a provider's config_schema.py was cached as 'no schema' until process restart, rendering a silent empty panel even after the file was fixed. Cache only successful loads and genuine file-absence. --- plugins/memory/config_schema.py | 3 +++ tests/plugins/memory/test_config_schema.py | 27 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/plugins/memory/config_schema.py b/plugins/memory/config_schema.py index d0db037e90bb..65c0260a8452 100644 --- a/plugins/memory/config_schema.py +++ b/plugins/memory/config_schema.py @@ -132,7 +132,10 @@ def get_provider_config_schema(name: str) -> ProviderConfigSchema | None: spec.loader.exec_module(module) schema = getattr(module, "CONFIG_SCHEMA", None) except Exception: + # A broken schema file must not cache: it would render as a silent + # empty panel until process restart even after the file is fixed. _log.exception("failed to load config schema for memory provider %r", name) + return None _SCHEMA_CACHE[name] = schema return schema diff --git a/tests/plugins/memory/test_config_schema.py b/tests/plugins/memory/test_config_schema.py index 2d1c70db3478..b88caced322a 100644 --- a/tests/plugins/memory/test_config_schema.py +++ b/tests/plugins/memory/test_config_schema.py @@ -1,5 +1,6 @@ """Tests for config-schema loading from memory provider plugin dirs.""" +import plugins.memory.config_schema as config_schema from plugins.memory.config_schema import get_provider_config_schema @@ -14,3 +15,29 @@ def test_plugin_without_schema_is_none(): def test_schemas_are_cached_per_provider(): assert get_provider_config_schema("honcho") is get_provider_config_schema("honcho") + + +def test_broken_schema_is_not_cached(monkeypatch, tmp_path): + # A load failure must retry on the next request, not pin an empty panel. + broken_dir = tmp_path / "broken" + broken_dir.mkdir() + schema_file = broken_dir / "config_schema.py" + schema_file.write_text("this is not python(", encoding="utf-8") + + monkeypatch.setattr(config_schema, "_SCHEMA_CACHE", {}) + import plugins.memory as memory + + monkeypatch.setattr(memory, "find_provider_dir", lambda name: broken_dir) + + assert get_provider_config_schema("broken") is None + assert "broken" not in config_schema._SCHEMA_CACHE + + schema_file.write_text( + "from plugins.memory.config_schema import ProviderConfigSchema\n" + 'CONFIG_SCHEMA = ProviderConfigSchema(name="broken", label="Broken")\n', + encoding="utf-8", + ) + + recovered = get_provider_config_schema("broken") + assert recovered is not None + assert recovered.label == "Broken"