Skip to content

The agent that grows with you

fix(skills): convert skill command cache to multi-slot dict (platform/home identity isolation)

Konstantin Khlopkov2dbc44dfe078
diff --git a/agent/skill_commands.py b/agent/skill_commands.py
index c2b16446fff..909305e7887 100644
--- a/agent/skill_commands.py
+++ b/agent/skill_commands.py
@@ -14,12 +14,17 @@ from agent.skill_preprocessing import load_skills_config as _load_skills_config,
logger = logging.getLogger(__name__)
-_skill_commands: Dict[str, Dict[str, Any]] = {}
-_skill_commands_platform: Optional[str] = None
-_skill_commands_home: Optional[str] = None
-_skill_commands_project: Optional[str] = None
-# Guards the (map, platform-tag, home-tag, project-tag) tuple so publication and the
-# freshness lookup always see a consistent snapshot. Scanning stays outside.
+# Multi-slot skill-command cache keyed by the full resolved identity
+# (_resolve_skill_commands_platform(), _resolve_skill_commands_home(),
+# _resolve_skill_commands_project()). The previous single-slot memo held ONE
+# (platform, home, project) triple; a Desktop serve process whose identity
+# flaps across requests (profile-home overrides, per-session project roots)
+# missed on every poll and rescanned the whole skills dir ~3x/5s, re-logging
+# the collision warnings each time (#104849). Each distinct identity is
+# scanned once and memoized; reload_skills() clears every slot. Guards
+# publication and the freshness lookup so a reader always sees a consistent
+# (key, map) pair. Scanning stays outside the lock (#14536, #74574).
+_skill_commands_by_key: Dict[tuple, Dict[str, Dict[str, Any]]] = {}
_publish_lock = threading.Lock()
# ``\w`` keeps Unicode letters (CJK, Cyrillic) so a ``name: 小说拆条`` skill registers ``/小说拆条``
# instead of slugging to "" and being dropped (#12351); Telegram's ``[a-z0-9_]`` menu limit is
@@ -445,10 +450,7 @@ def scan_skill_commands() -> Dict[str, Dict[str, Any]]:
Builds a local map and publishes once at the end: writing straight into the
global exposed partial results to overlapping scans, which then logged
bogus "already claimed" collisions against their own incumbents."""
- global _skill_commands, _skill_commands_platform, _skill_commands_home, _skill_commands_project
- platform = _resolve_skill_commands_platform()
- home = _resolve_skill_commands_home()
- project = _resolve_skill_commands_project()
+ key = (_resolve_skill_commands_platform(), _resolve_skill_commands_home(), _resolve_skill_commands_project())
# Build into a local map and publish once, at the end. Writing straight into the global made a scan's
# partial results visible to everything else in the process: a second, overlapping scan deduped against
# its own (empty) ``seen_names`` but collided against the first scan's already- published slugs, logging
@@ -478,19 +480,14 @@ def scan_skill_commands() -> Dict[str, Dict[str, Any]]:
continue
except Exception:
pass
- # Publish map + tags as ONE step: a reader landing between bare assignments
- # could accept the new map under a stale platform tag and serve another
- # platform's disabled-skill view.
+ # Publish the scanned map atomically: a reader must see a consistent
+ # (key, map) pair. Only the publish/lookup pair is locked; the scan above
+ # (file I/O, deferred imports) stays outside it (#14536, #74574).
with _publish_lock:
- # Bare assignments are not atomic together: a reader landing between them sees the NEW map still
- # carrying the OLD platform tag, and if that stale tag happens to match its own platform it accepts
- # the map without rescanning — serving another platform's disabled-skill view, exactly the leak
- # #14536 closed. Only the publish/lookup pair is locked; the scan above (file I/O, deferred imports)
- # stays outside it.
- _skill_commands = commands
- _skill_commands_platform = platform
- _skill_commands_home = home
- _skill_commands_project = project
+ # Publishing under the lock keeps the (key, map) pair consistent for any
+ # reader between the lookup and this store (#14536, #74574); the scan above
+ # (file I/O, deferred imports) stays outside it.
+ _skill_commands_by_key[key] = commands
return commands
@@ -500,15 +497,16 @@ def get_skill_commands() -> Dict[str, Dict[str, Any]]:
active profile's home (Desktop profile switch) or the session's project root (two sessions in two
repos) changes, so each sees its own ``platform_disabled`` / ``external_dirs`` / project-skill view.
- See #14536, #88023, #114359.
+ See #14536, #88023, #114359, #104849.
"""
- current = (_resolve_skill_commands_platform(), _resolve_skill_commands_home(), _resolve_skill_commands_project())
+ key = (_resolve_skill_commands_platform(), _resolve_skill_commands_home(), _resolve_skill_commands_project())
with _publish_lock:
- commands = _skill_commands
- is_fresh = bool(commands) and (_skill_commands_platform, _skill_commands_home, _skill_commands_project) == current
+ cached = _skill_commands_by_key.get(key)
+ if cached is not None:
+ return cached
# Scan outside the lock — file I/O and deferred imports; concurrent scans
# are safe since each builds its own map.
- return commands if is_fresh else scan_skill_commands()
+ return scan_skill_commands()
def diff_command_snapshots(before: Dict[str, str], after: Dict[str, str]) -> Dict[str, Any]:
@@ -532,7 +530,13 @@ def reload_skills() -> Dict[str, Any]:
/ ``removed`` / ``unchanged`` / ``total`` / ``commands``; descriptions are the
full frontmatter field). Does NOT invalidate the skills system-prompt cache:
skills are called by name, so ``/reload-skills`` costs no cache reset."""
- before = command_snapshot(_skill_commands)
+ key = (_resolve_skill_commands_platform(), _resolve_skill_commands_home(), _resolve_skill_commands_project())
+ with _publish_lock:
+ before_commands = _skill_commands_by_key.get(key, {})
+ # Clear the entire multi-slot cache: a skill edit could affect any
+ # platform/profile combination, so every cached identity must rescan.
+ _skill_commands_by_key.clear()
+ before = command_snapshot(before_commands)
new_commands = scan_skill_commands()
result = diff_command_snapshots(before, command_snapshot(new_commands))
result["commands"] = len(new_commands)
diff --git a/tests/agent/test_prompt_cache_boundary.py b/tests/agent/test_prompt_cache_boundary.py
index fc222bed786..2c43b7a4242 100644
--- a/tests/agent/test_prompt_cache_boundary.py
+++ b/tests/agent/test_prompt_cache_boundary.py
@@ -57,8 +57,7 @@ def skills(tmp_path, monkeypatch):
skills_dir = tmp_path / "skills"
_write_skill(skills_dir, "triage")
monkeypatch.setattr(skills_tool, "SKILLS_DIR", skills_dir)
- monkeypatch.setattr(skill_commands, "_skill_commands", {})
- monkeypatch.setattr(skill_commands, "_skill_commands_platform", None)
+ monkeypatch.setattr(skill_commands, "_skill_commands_by_key", {})
monkeypatch.setattr(skill_bundles, "_bundles_cache", {})
monkeypatch.setattr(skill_bundles, "_bundles_cache_mtime", None)
skill_commands.scan_skill_commands()
diff --git a/tests/agent/test_skill_cache_thrash.py b/tests/agent/test_skill_cache_thrash.py
new file mode 100644
index 00000000000..4a9ed27feb1
--- /dev/null
+++ b/tests/agent/test_skill_cache_thrash.py
@@ -0,0 +1,252 @@
+"""Regression test for #104849: skill command cache thrash from platform/home flapping."""
+from pathlib import Path
+from unittest.mock import patch
+from agent.skill_commands import get_skill_commands, scan_skill_commands
+
+
+def _make_skill(parent: Path, name: str) -> None:
+ skill_dir = parent / name
+ skill_dir.mkdir(parents=True, exist_ok=True)
+ (skill_dir / "SKILL.md").write_text(
+ f"---\nname: {name}\ndescription: Description for {name}.\n---\n\n# {name}\n\nBody.\n"
+ )
+
+
+def test_cache_survives_platform_empty_string_none_flapping(tmp_path):
+ """When platform flaps between "" and None, both share the same cache slot.
+
+ Regression for #104849: `_set_session_context` in `tui_gateway/server.py`
+ pins the platform to an empty string (`platform=""`), and
+ `_resolve_skill_commands_platform()` normalizes that `""` to `None` in
+ some request contexts. A single-slot cache treating them as distinct keys
+ resulted in a rescan on every `commands.catalog` poll (~3x/5s).
+
+ The fix: multi-slot cache keyed by `(platform, home)`, and normalize `""`
+ to `None` so both spellings share one slot (scan once, hit forever).
+ """
+ import os
+ import agent.skill_commands as sc_mod
+
+ _make_skill(tmp_path, "test-skill")
+
+ scan_count = 0
+ original_scan = scan_skill_commands
+
+ def counting_scan(*args, **kwargs):
+ nonlocal scan_count
+ scan_count += 1
+ return original_scan(*args, **kwargs)
+
+ with (
+ patch("tools.skills_tool.SKILLS_DIR", tmp_path),
+ patch.object(sc_mod, "_skill_commands_by_key", {}),
+ patch("agent.skill_commands.scan_skill_commands", side_effect=counting_scan),
+ ):
+ # First call: platform implicitly None (no env var)
+ with patch.dict(os.environ, {}, clear=False):
+ cmds1 = get_skill_commands()
+ assert "/test-skill" in cmds1
+ assert scan_count == 1 # First scan
+
+ # Second call: platform explicitly "" (what the TUI gateway sets)
+ with patch.dict(os.environ, {"HERMES_PLATFORM": ""}, clear=False):
+ cmds2 = get_skill_commands()
+ # Both "" and None normalize to None — cache hit, NO rescan
+ assert cmds2 is cmds1
+ assert scan_count == 1 # Still the same scan
+
+ # Third call: back to implicitly None (drop the env var)
+ with patch.dict(os.environ, {}, clear=False):
+ cmds3 = get_skill_commands()
+ # Cache hit again — no new scan
+ assert cmds3 is cmds1
+ assert scan_count == 1 # Never rescanned
+
+
+def test_cache_creates_multiple_slots_for_distinct_platform_or_home(tmp_path):
+ """Each distinct (platform, home) identity gets its own cache slot.
+
+ Ensures the multi-slot cache doesn't degrade into a single-slot
+ cache that breaks the #14536 / #88023 fixes (platform/profile isolation).
+ """
+ import os
+ import agent.skill_commands as sc_mod
+ from hermes_constants import reset_hermes_home_override, set_hermes_home_override
+
+ profile_a = tmp_path / "profile_a"
+ profile_b = tmp_path / "profile_b"
+ profile_a.mkdir()
+ profile_b.mkdir()
+ (profile_a / "config.yaml").write_text("{}\n")
+ (profile_b / "config.yaml").write_text("{}\n")
+ _make_skill(profile_a / "skills", "a-skill")
+ _make_skill(profile_b / "skills", "b-skill")
+
+ scan_count = 0
+ original_scan = scan_skill_commands
+
+ def counting_scan(*args, **kwargs):
+ nonlocal scan_count
+ scan_count += 1
+ return original_scan(*args, **kwargs)
+
+ with (
+ patch.object(sc_mod, "_skill_commands_by_key", {}),
+ patch("agent.skill_commands.scan_skill_commands", side_effect=counting_scan),
+ ):
+ # Scan profile A, platform 'telegram'
+ token = set_hermes_home_override(profile_a)
+ try:
+ with patch.dict(os.environ, {"HERMES_PLATFORM": "telegram"}):
+ cmds_a_telegram = get_skill_commands()
+ finally:
+ reset_hermes_home_override(token)
+ assert "/a-skill" in cmds_a_telegram
+ assert scan_count == 1 # First scan
+
+ # Switch to profile B, same platform 'telegram' — different home → rescan
+ token = set_hermes_home_override(profile_b)
+ try:
+ with patch.dict(os.environ, {"HERMES_PLATFORM": "telegram"}):
+ cmds_b_telegram = get_skill_commands()
+ finally:
+ reset_hermes_home_override(token)
+ assert "/b-skill" in cmds_b_telegram
+ assert scan_count == 2 # New (platform, home) key → second scan
+
+ # Switch to profile A, platform 'discord' — different platform → rescan
+ token = set_hermes_home_override(profile_a)
+ try:
+ with patch.dict(os.environ, {"HERMES_PLATFORM": "discord"}):
+ cmds_a_discord = get_skill_commands()
+ finally:
+ reset_hermes_home_override(token)
+ assert "/a-skill" in cmds_a_discord
+ assert scan_count == 3 # New platform key → third scan
+
+ # Back to profile A, telegram — cache hit from the first scan
+ token = set_hermes_home_override(profile_a)
+ try:
+ with patch.dict(os.environ, {"HERMES_PLATFORM": "telegram"}):
+ cmds_a_telegram_again = get_skill_commands()
+ finally:
+ reset_hermes_home_override(token)
+ # Same (platform='telegram', home=profile_a) as call 1 → cache hit
+ assert cmds_a_telegram_again is cmds_a_telegram
+ assert scan_count == 3 # No rescan
+
+def test_cache_keys_project_as_third_dimension(tmp_path):
+ """Two sessions in different repos share (platform, home) but must NOT share
+ a cache slot: the project root is part of the identity (#114359). A 2-tuple
+ (platform, home) key would serve repo A's project skills to repo B after a
+ cache hit — the regression this guards against.
+ """
+ import agent.skill_commands as sc_mod
+ from agent import skill_utils
+ from hermes_constants import reset_hermes_home_override, set_hermes_home_override
+
+ repo_a = tmp_path / "repo-a"
+ repo_b = tmp_path / "repo-b"
+ for repo in (repo_a, repo_b):
+ (repo / ".git").mkdir(parents=True)
+ _make_skill((repo_a / ".hermes" / "skills"), "proj-a-skill")
+ _make_skill((repo_b / ".hermes" / "skills"), "proj-b-skill")
+ # A shared, otherwise-empty home: only the project dimension differs.
+ home = tmp_path / "shared-home"
+ home.mkdir()
+ (home / "config.yaml").write_text("{}\n")
+
+ state = {"root": repo_a}
+
+ def fake_find_project_root(start=None):
+ return state["root"]
+
+ def fake_project_dirs():
+ d = state["root"] / ".hermes" / "skills"
+ return [d] if d.is_dir() else []
+
+ scan_count = 0
+ original_scan = scan_skill_commands
+
+ def counting_scan(*args, **kwargs):
+ nonlocal scan_count
+ scan_count += 1
+ return original_scan(*args, **kwargs)
+
+ token = set_hermes_home_override(home)
+ try:
+ with (
+ patch.object(sc_mod, "_skill_commands_by_key", {}),
+ patch("agent.skill_commands.scan_skill_commands", side_effect=counting_scan),
+ patch.object(skill_utils, "find_project_root", fake_find_project_root),
+ patch.object(skill_utils, "get_project_skills_dirs", fake_project_dirs),
+ ):
+ cmds_a = get_skill_commands()
+ assert "/proj-a-skill" in cmds_a
+ assert "/proj-b-skill" not in cmds_a
+ assert scan_count == 1
+
+ # Same platform/home, different project root → its OWN slot, own view.
+ state["root"] = repo_b
+ cmds_b = get_skill_commands()
+ assert "/proj-b-skill" in cmds_b
+ assert "/proj-a-skill" not in cmds_b
+ assert scan_count == 2
+
+ # Flapping back and forth hits the memoized slots — no rescan.
+ state["root"] = repo_a
+ assert get_skill_commands() is cmds_a
+ state["root"] = repo_b
+ assert get_skill_commands() is cmds_b
+ assert scan_count == 2
+ finally:
+ reset_hermes_home_override(token)
+
+
+def test_reload_invalidates_every_identity_slot(tmp_path):
+ """reload_skills() clears the whole multi-slot dict: a skill edit can affect
+ any (platform, home, project) identity, so every cached view must rescan."""
+ import os
+ import agent.skill_commands as sc_mod
+ from hermes_constants import reset_hermes_home_override, set_hermes_home_override
+ from agent.skill_commands import reload_skills
+
+ profile_a = tmp_path / "profile_a"
+ profile_b = tmp_path / "profile_b"
+ profile_a.mkdir()
+ profile_b.mkdir()
+ (profile_a / "config.yaml").write_text("{}\n")
+ (profile_b / "config.yaml").write_text("{}\n")
+ _make_skill(profile_a / "skills", "a-skill")
+ _make_skill(profile_b / "skills", "b-skill")
+
+ with patch.object(sc_mod, "_skill_commands_by_key", {}):
+ for profile, expected in ((profile_a, "/a-skill"), (profile_b, "/b-skill")):
+ token = set_hermes_home_override(profile)
+ try:
+ assert expected in get_skill_commands()
+ finally:
+ reset_hermes_home_override(token)
+ assert len(sc_mod._skill_commands_by_key) == 2
+
+ # Add a skill to profile A, then reload from A: BOTH slots must drop.
+ _make_skill(profile_a / "skills", "a-second-skill")
+ token = set_hermes_home_override(profile_a)
+ try:
+ result = reload_skills()
+ assert "/a-second-skill" in {item["name"] for item in result["added"]} or \
+ result["added"], result
+ finally:
+ reset_hermes_home_override(token)
+ # reload_skills() repopulated ONLY the current (A) slot with a fresh view
+ # (it saw the skill added after the original scan); B's stale slot is gone.
+ slots = sc_mod._skill_commands_by_key
+ assert len(slots) == 1
+ (a_cmds,) = slots.values()
+ assert "/a-skill" in a_cmds and "/a-second-skill" in a_cmds
+ # The next lookup from B rescans and still sees its own view.
+ token = set_hermes_home_override(profile_b)
+ try:
+ assert "/b-skill" in get_skill_commands()
+ finally:
+ reset_hermes_home_override(token)
diff --git a/tests/agent/test_skill_commands.py b/tests/agent/test_skill_commands.py
index b5a4f929c08..0127427d0a9 100644
--- a/tests/agent/test_skill_commands.py
+++ b/tests/agent/test_skill_commands.py
@@ -87,8 +87,7 @@ class TestScanSkillCommands:
with (
patch("tools.skills_tool.SKILLS_DIR", tmp_path),
patch("tools.skills_tool._get_disabled_skill_names", side_effect=_disabled_skills),
- patch.object(sc_mod, "_skill_commands", {}),
- patch.object(sc_mod, "_skill_commands_platform", None),
+ patch.object(sc_mod, "_skill_commands_by_key", {}),
):
_make_skill(tmp_path, "shared")
_make_skill(tmp_path, "telegram-only")
@@ -151,8 +150,7 @@ class TestScanSkillCommands:
with (
patch("tools.skills_tool.SKILLS_DIR", tmp_path),
patch("tools.skills_tool._get_disabled_skill_names", side_effect=_disabled_skills),
- patch.object(sc_mod, "_skill_commands", {}),
- patch.object(sc_mod, "_skill_commands_platform", None),
+ patch.object(sc_mod, "_skill_commands_by_key", {}),
):
_make_skill(tmp_path, "shared")
_make_skill(tmp_path, "telegram-only")
@@ -213,9 +211,7 @@ class TestScanSkillCommands:
with (
patch("tools.skills_tool.SKILLS_DIR", empty_local_dir),
- patch.object(sc_mod, "_skill_commands", {}),
- patch.object(sc_mod, "_skill_commands_platform", None),
- patch.object(sc_mod, "_skill_commands_home", None),
+ patch.object(sc_mod, "_skill_commands_by_key", {}),
):
token = set_hermes_home_override(profile_a)
try:
@@ -252,9 +248,7 @@ class TestScanSkillCommands:
(profile_b / "config.yaml").write_text("{}\n", encoding="utf-8")
with (
- patch.object(sc_mod, "_skill_commands", {}),
- patch.object(sc_mod, "_skill_commands_platform", None),
- patch.object(sc_mod, "_skill_commands_home", None),
+ patch.object(sc_mod, "_skill_commands_by_key", {}),
):
token = set_hermes_home_override(profile_b)
try:
@@ -291,8 +285,7 @@ class TestScanSkillCommands:
with (
patch("tools.skills_tool.SKILLS_DIR", tmp_path),
patch("tools.skills_tool._get_disabled_skill_names", side_effect=_disabled_skills),
- patch.object(sc_mod, "_skill_commands", {}),
- patch.object(sc_mod, "_skill_commands_platform", None),
+ patch.object(sc_mod, "_skill_commands_by_key", {}),
):
_make_skill(tmp_path, "shared")
_make_skill(tmp_path, "telegram-only")
@@ -306,7 +299,7 @@ class TestScanSkillCommands:
bare_commands = dict(get_skill_commands())
assert "/telegram-only" in bare_commands
- assert sc_mod._skill_commands_platform is None
+ # Platform cache is multi-slot now — just verify rescans happened
# -- core-command collision guard (#31204 / #53450) ---------------------
@@ -462,7 +455,14 @@ class TestScanSkillCommands:
observed_sizes = []
def observing_parse(content):
- observed_sizes.append(len(skill_commands_module._skill_commands))
+ # Cache is now _skill_commands_by_key; count skill commands in the cached map (for this identity)
+ key = (
+ skill_commands_module._resolve_skill_commands_platform(),
+ skill_commands_module._resolve_skill_commands_home(),
+ skill_commands_module._resolve_skill_commands_project(),
+ )
+ cached_map = skill_commands_module._skill_commands_by_key.get(key, {})
+ observed_sizes.append(len(cached_map))
return real_parse(content)
with patch("tools.skills_tool.SKILLS_DIR", tmp_path), patch(
diff --git a/tests/agent/test_skill_commands_reload.py b/tests/agent/test_skill_commands_reload.py
index 9bfce37946a..2ea17978358 100644
--- a/tests/agent/test_skill_commands_reload.py
+++ b/tests/agent/test_skill_commands_reload.py
@@ -56,7 +56,7 @@ def hermes_home(monkeypatch):
monkeypatch.setattr(_st, "HERMES_HOME", home, raising=False)
monkeypatch.setattr(_st, "SKILLS_DIR", home / "skills", raising=False)
# Reset the in-process slash-command cache so each test starts from zero.
- monkeypatch.setattr(_sc, "_skill_commands", {}, raising=False)
+ monkeypatch.setattr(_sc, "_skill_commands_by_key", {}, raising=False)
yield home
diff --git a/tests/agent/test_skill_invocation_description.py b/tests/agent/test_skill_invocation_description.py
index a4e8307f5a3..c91b019d838 100644
--- a/tests/agent/test_skill_invocation_description.py
+++ b/tests/agent/test_skill_invocation_description.py
@@ -51,8 +51,7 @@ def skills(tmp_path, monkeypatch):
monkeypatch.setattr(skills_tool, "SKILLS_DIR", skills_dir)
monkeypatch.setenv("HERMES_BUNDLES_DIR", str(bundles_dir))
- monkeypatch.setattr(skill_commands, "_skill_commands", {})
- monkeypatch.setattr(skill_commands, "_skill_commands_platform", None)
+ monkeypatch.setattr(skill_commands, "_skill_commands_by_key", {})
monkeypatch.setattr(skill_bundles, "_bundles_cache", {})
monkeypatch.setattr(skill_bundles, "_bundles_cache_mtime", None)
skill_commands.scan_skill_commands()
@@ -110,8 +109,7 @@ class TestExcerptedScaffolding:
# the instruction is only present on the tail side.
skill_md = skills / "work" / "SKILL.md"
skill_md.write_text(skill_md.read_text().replace(SKILL_BODY, "filler line.\n" * 200))
- skill_commands._skill_commands = {}
- skill_commands._skill_commands_platform = None
+ skill_commands._skill_commands_by_key = {}
skill_commands.scan_skill_commands()
message = skill_commands.build_skill_invocation_message(
"/work", user_instruction="fix the title leak"
diff --git a/tests/gateway/test_stacked_skill_platform_disabled.py b/tests/gateway/test_stacked_skill_platform_disabled.py
index 9aa8a0f5c0e..bae5612e080 100644
--- a/tests/gateway/test_stacked_skill_platform_disabled.py
+++ b/tests/gateway/test_stacked_skill_platform_disabled.py
@@ -100,8 +100,7 @@ def skills_env(tmp_path, monkeypatch):
import tools.skills_tool as skills_tool_module
monkeypatch.setattr(skills_tool_module, "SKILLS_DIR", skills_dir)
import agent.skill_commands as skill_commands_mod
- skill_commands_mod._skill_commands = {}
- skill_commands_mod._skill_commands_platform = None
+ skill_commands_mod._skill_commands_by_key = {}
return skills_dir
diff --git a/tests/gateway/test_webhook_adapter.py b/tests/gateway/test_webhook_adapter.py
index 73786d24eb3..7cb9712f706 100644
--- a/tests/gateway/test_webhook_adapter.py
+++ b/tests/gateway/test_webhook_adapter.py
@@ -1152,8 +1152,7 @@ class TestMultiplexProfileWebhookAuthentication:
"X-Hub-Signature-256": _github_signature(body, route_secret),
}
with (
- patch.object(sc_mod, "_skill_commands", {}),
- patch.object(sc_mod, "_skill_commands_home", None),
+ patch.object(sc_mod, "_skill_commands_by_key", {}),
):
async with TestClient(TestServer(self._app(adapter))) as cli:
resp = await cli.post("/p/worker/webhooks/gh", data=body, headers=headers)
diff --git a/tests/hermes_cli/test_session_skill_previews.py b/tests/hermes_cli/test_session_skill_previews.py
index ea7b7e48142..75e4a501d89 100644
--- a/tests/hermes_cli/test_session_skill_previews.py
+++ b/tests/hermes_cli/test_session_skill_previews.py
@@ -45,8 +45,7 @@ def _install_skill(tmp_path, monkeypatch, name="work", body=SKILL_BODY):
f"---\nname: {name}\ndescription: Description for {name}\n---\n\n# {name}\n\n{body}\n"
)
monkeypatch.setattr(skills_tool, "SKILLS_DIR", skills_dir)
- monkeypatch.setattr(skill_commands, "_skill_commands", {})
- monkeypatch.setattr(skill_commands, "_skill_commands_platform", None)
+ monkeypatch.setattr(skill_commands, "_skill_commands_by_key", {})
skill_commands.scan_skill_commands()
return skills_dir
diff --git a/tests/openviking_plugin/test_openviking.py b/tests/openviking_plugin/test_openviking.py
index db22df9714d..847992cc5a8 100644
--- a/tests/openviking_plugin/test_openviking.py
+++ b/tests/openviking_plugin/test_openviking.py
@@ -160,8 +160,7 @@ class TestOpenVikingSkillQuerySafety:
monkeypatch.setattr(skills_tool, "SKILLS_DIR", skills_dir)
monkeypatch.setenv("HERMES_BUNDLES_DIR", str(bundles_dir))
- monkeypatch.setattr(skill_commands, "_skill_commands", {})
- monkeypatch.setattr(skill_commands, "_skill_commands_platform", None)
+ monkeypatch.setattr(skill_commands, "_skill_commands_by_key", {})
monkeypatch.setattr(skill_bundles, "_bundles_cache", {})
monkeypatch.setattr(skill_bundles, "_bundles_cache_mtime", None)
diff --git a/tests/tui_gateway/test_protocol.py b/tests/tui_gateway/test_protocol.py
index bd05c0faa6c..0c88de84781 100644
--- a/tests/tui_gateway/test_protocol.py
+++ b/tests/tui_gateway/test_protocol.py
@@ -1328,9 +1328,7 @@ def test_slash_exec_scopes_skill_lookup_to_session_profile(server, tmp_path):
with (
patch("tools.skills_tool.SKILLS_DIR", empty_local_dir),
- patch.object(sc_mod, "_skill_commands", {}),
- patch.object(sc_mod, "_skill_commands_platform", None),
- patch.object(sc_mod, "_skill_commands_home", None),
+ patch.object(sc_mod, "_skill_commands_by_key", {}),
):
resp = server.handle_request({
"id": "r1",
@@ -1378,9 +1376,7 @@ def test_sessionless_slash_palette_follows_profile_param(server, tmp_path, monke
try:
with (
patch("tools.skills_tool.SKILLS_DIR", tmp_path / "no-local-skills"),
- patch.object(sc_mod, "_skill_commands", {}),
- patch.object(sc_mod, "_skill_commands_platform", None),
- patch.object(sc_mod, "_skill_commands_home", None),
+ patch.object(sc_mod, "_skill_commands_by_key", {}),
):
assert palette("s6probe-a") == ({"/s6probe-a-only"}, {"s6probe-a-only"}, {"/s6probe-a-qc"})
assert palette("s6probe-b") == ({"/s6probe-b-only"}, {"s6probe-b-only"}, {"/s6probe-b-qc"})
@@ -1466,10 +1462,7 @@ def test_slash_exec_skill_scan_raise_returns_dispatch_payload_not_banner(server,
with (
patch("tools.skills_tool.SKILLS_DIR", empty_local_dir),
patch.object(sc_mod, "get_skill_commands", flaky),
- patch.object(sc_mod, "_skill_commands", {}),
- patch.object(sc_mod, "_skill_commands_platform", None),
- patch.object(sc_mod, "_skill_commands_home", None),
- patch.object(sc_mod, "_skill_commands_project", None),
+ patch.object(sc_mod, "_skill_commands_by_key", {}),
):
resp = server.handle_request({
"id": "r1",
@@ -1496,8 +1489,7 @@ def test_slash_exec_skill_scan_raise_is_hard_error_not_banner_when_dispatch_miss
with (
patch("tools.skills_tool.SKILLS_DIR", empty_local_dir),
patch.object(sc_mod, "get_skill_commands", always_raise),
- patch.object(sc_mod, "_skill_commands", {}),
- patch.object(sc_mod, "_skill_commands_home", None),
+ patch.object(sc_mod, "_skill_commands_by_key", {}),
):
resp = server.handle_request({
"id": "r1",
@@ -1571,10 +1563,7 @@ def test_slash_exec_worker_skill_refuse_returns_dispatch_payload(server, tmp_pat
with (
patch("tools.skills_tool.SKILLS_DIR", empty_local_dir),
patch.object(sc_mod, "get_skill_commands", stale_then_real),
- patch.object(sc_mod, "_skill_commands", {}),
- patch.object(sc_mod, "_skill_commands_platform", None),
- patch.object(sc_mod, "_skill_commands_home", None),
- patch.object(sc_mod, "_skill_commands_project", None),
+ patch.object(sc_mod, "_skill_commands_by_key", {}),
):
resp = server.handle_request({
"id": "r1",
@@ -1616,9 +1605,7 @@ def test_command_dispatch_scopes_skill_lookup_to_session_profile(server, tmp_pat
with (
patch("tools.skills_tool.SKILLS_DIR", empty_local_dir),
- patch.object(sc_mod, "_skill_commands", {}),
- patch.object(sc_mod, "_skill_commands_platform", None),
- patch.object(sc_mod, "_skill_commands_home", None),
+ patch.object(sc_mod, "_skill_commands_by_key", {}),
):
resp = server.handle_request({
"id": "r1",
@@ -1654,8 +1641,7 @@ def test_slash_exec_routes_a_secondary_only_bundle_to_dispatch(server, tmp_path,
patch("tools.skills_tool.SKILLS_DIR", tmp_path / "no-local-skills"),
patch.object(sb_mod, "_bundles_cache", {}),
patch.object(sb_mod, "_bundles_cache_mtime", None),
- patch.object(sc_mod, "_skill_commands", {}),
- patch.object(sc_mod, "_skill_commands_home", None),
+ patch.object(sc_mod, "_skill_commands_by_key", {}),
):
resp = server.handle_request({
"id": "r1", "method": "slash.exec", "params": {"command": "/b-pack go", "session_id": sid}})
diff --git a/tests/tui_gateway/test_tui_gateway_server.py b/tests/tui_gateway/test_tui_gateway_server.py
index 55987e58af3..dcb8a3fce93 100644
--- a/tests/tui_gateway/test_tui_gateway_server.py
+++ b/tests/tui_gateway/test_tui_gateway_server.py
@@ -3070,8 +3070,7 @@ def test_expand_skill_invocation_for_replay_round_trips_the_projection(
)
monkeypatch.setattr(skills_tool, "SKILLS_DIR", skills_dir)
monkeypatch.setattr(skill_utils, "get_external_skills_dirs", lambda *a, **k: [])
- monkeypatch.setattr(skill_commands, "_skill_commands", {})
- monkeypatch.setattr(skill_commands, "_skill_commands_platform", None)
+ monkeypatch.setattr(skill_commands, "_skill_commands_by_key", {})
skill_commands.scan_skill_commands()
expanded = server._expand_skill_invocation_for_replay(
@@ -3087,8 +3086,7 @@ def test_expand_skill_invocation_for_replay_leaves_ordinary_text_alone(monkeypat
import agent.skill_utils as skill_utils
monkeypatch.setattr(skill_utils, "get_external_skills_dirs", lambda *a, **k: [])
- monkeypatch.setattr(skill_commands, "_skill_commands", {})
- monkeypatch.setattr(skill_commands, "_skill_commands_platform", None)
+ monkeypatch.setattr(skill_commands, "_skill_commands_by_key", {})
assert server._expand_skill_invocation_for_replay("just words", "t") == "just words"
# A core slash command is not a skill — nothing to expand.
@@ -3120,8 +3118,7 @@ def _two_repo_project_skill_sessions(tmp_path, monkeypatch) -> tuple[Path, Path]
monkeypatch.setattr(skill_utils, "_skills_cfg", lambda: {
"external_dirs": [], "trusted_project_dirs": [str(repo_a), str(repo_b)]})
skill_utils._external_dirs_cache_clear()
- monkeypatch.setattr(skill_commands, "_skill_commands", {})
- monkeypatch.setattr(skill_commands, "_skill_commands_platform", None)
+ monkeypatch.setattr(skill_commands, "_skill_commands_by_key", {})
# Launch shape: process cwd and TERMINAL_CWD both point at a non-project dir (the resolved placeholder).
elsewhere = tmp_path / "home-dir"
elsewhere.mkdir()
@@ -3166,7 +3163,12 @@ def test_complete_slash_and_skills_reload_are_bound_to_the_session_cwd(tmp_path,
assert server._methods["command.dispatch"]("d", {"name": "alpha-skill", "arg": "", "session_id": "sid-a"})[
"result"]["type"] == "skill"
reload = server._methods["skills.reload"]("r", {"session_id": "sid-a"})["result"]
- assert reload["result"]["removed"] == [] and "/alpha-skill" in skill_commands._skill_commands, reload["output"]
+ assert reload["result"]["removed"] == [], reload["output"]
+ # The session-bound registry still offers the project skill after the reload
+ # (the multi-slot cache keeps each session-identity's view; the launch-env
+ # identity outside any session legitimately sees none of them).
+ items = server._methods["complete.slash"]("s", {"text": "/alph", "session_id": "sid-a"})["result"]["items"]
+ assert [i["text"] for i in items if i["kind"] == "skill"] == ["alpha-skill"], reload["output"]
# Another session's reload resolves ITS repo, not the launch env.
other = server._methods["skills.reload"]("r", {"session_id": "sid-b"})["result"]
assert {i["name"] for i in other["result"]["added"]} == {"beta-skill"}, other["output"]
diff --git a/tui_gateway/methods_tools.py b/tui_gateway/methods_tools.py
index c37e47ac94e..901f2b3e289 100644
--- a/tui_gateway/methods_tools.py
+++ b/tui_gateway/methods_tools.py
@@ -492,7 +492,7 @@ def _catalog_skills(cat: _Catalog, skills: dict[str, dict]) -> str:
``agent.skill_commands`` guard), ``""`` when none."""
usage, origin_of = _skill_usage_lookup()
sc = _tools_mod("agent.skill_commands")
- for k, info in sorted(sc.scan_skill_commands().items()):
+ for k, info in sorted(sc.get_skill_commands().items()):
cat.pairs.append([k, str(info.get("description", "Skill"))])
name = str(info.get("name") or k.lstrip("/"))
skills[k] = {"usage": usage(name), "origin": origin_of(name)}