Skip to content

The agent that grows with you

fix(skills): keep every profile's raw config cache entry across a miss

liuhao1024932b20df0965
diff --git a/agent/skill_utils.py b/agent/skill_utils.py
index c4ed7ad92b6..34147aefb32 100644
--- a/agent/skill_utils.py
+++ b/agent/skill_utils.py
@@ -192,6 +192,10 @@ def skill_matches_apps(frontmatter: dict[str, Any]) -> bool:
_RAW_CONFIG_CACHE: dict[tuple[str, int, int, int, int], dict[str, Any]] = {}
+# A multiplexed watcher rotates through up to ~32 published profile/project scopes plus
+# the ambient one (#141610), so a miss must not drop the whole cache — only a stale
+# signature entry. The bound retires entries a config's own edits leave behind.
+_RAW_CONFIG_CACHE_MAX = 128
def _raw_config_cache_clear() -> None:
@@ -230,8 +234,9 @@ def _load_raw_config() -> dict[str, Any]:
if not isinstance(parsed, dict):
return {}
if cache_key is not None:
- _RAW_CONFIG_CACHE.clear()
_RAW_CONFIG_CACHE[cache_key] = parsed
+ while len(_RAW_CONFIG_CACHE) > _RAW_CONFIG_CACHE_MAX:
+ _RAW_CONFIG_CACHE.pop(next(iter(_RAW_CONFIG_CACHE)))
return parsed
diff --git a/tests/agent/test_skill_utils.py b/tests/agent/test_skill_utils.py
index a061c9affda..c670a009558 100644
--- a/tests/agent/test_skill_utils.py
+++ b/tests/agent/test_skill_utils.py
@@ -69,6 +69,120 @@ skills:
assert parse_count == 1
+def _write_disabled_config(home, disabled: str) -> None:
+ home.mkdir(parents=True, exist_ok=True)
+ (home / "config.yaml").write_text(
+ f"skills:\n disabled:\n - {disabled}\n", encoding="utf-8"
+ )
+
+
+class TestMultiprofileRawConfigCache:
+ """#141610: a multiplexed watcher rotates through up to ~32 published profile
+ scopes plus the ambient one; one profile's cache miss must not evict every
+ other profile's unchanged entry."""
+
+ @staticmethod
+ def _load_under(home) -> list:
+ from agent import skill_utils
+ from hermes_constants import (
+ reset_hermes_home_override,
+ set_hermes_home_override,
+ )
+
+ token = set_hermes_home_override(str(home))
+ try:
+ return skill_utils._load_raw_config()["skills"]["disabled"]
+ finally:
+ reset_hermes_home_override(token)
+
+ def test_watcher_rotation_reparses_no_unchanged_config(self, tmp_path, monkeypatch):
+ from agent import skill_utils
+
+ homes = [tmp_path / f"scope-{i:02d}" for i in range(33)]
+ for i, home in enumerate(homes):
+ _write_disabled_config(home, f"skill-{i:02d}")
+ parse_count = 0
+ real_yaml_load = skill_utils.yaml_load
+
+ def counting_yaml_load(text):
+ nonlocal parse_count
+ parse_count += 1
+ return real_yaml_load(text)
+
+ monkeypatch.setattr(skill_utils, "yaml_load", counting_yaml_load)
+ skill_utils._raw_config_cache_clear()
+
+ for _ in range(3):
+ for i, home in enumerate(homes):
+ assert self._load_under(home) == [f"skill-{i:02d}"]
+
+ assert parse_count == 33
+
+ def test_editing_one_profile_reparses_only_that_profile(
+ self, tmp_path, monkeypatch
+ ):
+ from agent import skill_utils
+
+ first, second = tmp_path / "first", tmp_path / "second"
+ _write_disabled_config(first, "old-disabled")
+ _write_disabled_config(second, "second-disabled")
+ parse_count = 0
+ real_yaml_load = skill_utils.yaml_load
+
+ def counting_yaml_load(text):
+ nonlocal parse_count
+ parse_count += 1
+ return real_yaml_load(text)
+
+ monkeypatch.setattr(skill_utils, "yaml_load", counting_yaml_load)
+ skill_utils._raw_config_cache_clear()
+ assert self._load_under(first) == ["old-disabled"]
+ assert self._load_under(second) == ["second-disabled"]
+
+ # A different length changes st_size, so the signature must change even on
+ # filesystems whose mtime granularity misses a quick rewrite.
+ (first / "config.yaml").write_text(
+ "skills:\n disabled:\n - new-disabled-name\n", encoding="utf-8"
+ )
+ assert self._load_under(first) == ["new-disabled-name"]
+ assert self._load_under(second) == ["second-disabled"]
+ assert parse_count == 3
+
+ def test_one_profile_parse_does_not_block_another_profile(
+ self, tmp_path, monkeypatch
+ ):
+ from concurrent.futures import ThreadPoolExecutor
+ from threading import Event
+
+ from agent import skill_utils
+
+ first, second = tmp_path / "first", tmp_path / "second"
+ _write_disabled_config(first, "first-disabled")
+ _write_disabled_config(second, "second-disabled")
+ entered, release = Event(), Event()
+ real_yaml_load = skill_utils.yaml_load
+
+ def delayed_yaml_load(text):
+ if "first-disabled" in text:
+ entered.set()
+ assert release.wait(5), "first profile was not released"
+ return real_yaml_load(text)
+
+ monkeypatch.setattr(skill_utils, "yaml_load", delayed_yaml_load)
+ skill_utils._raw_config_cache_clear()
+ with ThreadPoolExecutor(max_workers=2) as pool:
+ first_result = pool.submit(self._load_under, first)
+ try:
+ assert entered.wait(5), "first profile parse did not start"
+ second_result = pool.submit(self._load_under, second)
+ assert second_result.result(timeout=3) == ["second-disabled"]
+ finally:
+ release.set()
+ assert first_result.result(timeout=5) == ["first-disabled"]
+ assert self._load_under(first) == ["first-disabled"]
+ assert self._load_under(second) == ["second-disabled"]
+
+
class TestParseConfigStringList:
"""#86661: `hermes config set` and JSON-mode editor saves store lists as
quoted strings (e.g. '["a","b"]'). Treating such a string as a single name