mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-21 16:18:55 +00:00
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.
This commit is contained in:
parent
0e09cc5cd4
commit
41e59f6126
2 changed files with 30 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue