Skip to content

The agent that grows with you

fix(skills): skip orphaned hub entries and bound per-fetch time in update checks

liuhao102447887693c6ea
diff --git a/hermes_cli/skills_hub.py b/hermes_cli/skills_hub.py
index 3a252abf0e7..186ad98affc 100644
--- a/hermes_cli/skills_hub.py
+++ b/hermes_cli/skills_hub.py
@@ -808,6 +808,10 @@ def do_check(name: Optional[str] = None, console: Optional[Console] = None) -> N
c.print(table)
update_count = sum(1 for entry in results if entry.get("status") == "update_available")
c.print(f"[dim]{update_count} update(s) available across {len(results)} checked skill(s)[/]\n")
+ orphaned = [entry.get("name", "") for entry in results if entry.get("status") == "orphaned"]
+ if orphaned:
+ c.print(f"[yellow]Orphaned:[/] {', '.join(orphaned)} — lock-file entries whose local "
+ "directory is gone. Remove them with: hermes skills uninstall <name>\n")
def _has_local_edits(installed: dict) -> bool:
diff --git a/tests/hermes_cli/test_skills_hub.py b/tests/hermes_cli/test_skills_hub.py
index cb137f070b5..68607ad20c9 100644
--- a/tests/hermes_cli/test_skills_hub.py
+++ b/tests/hermes_cli/test_skills_hub.py
@@ -125,6 +125,21 @@ def test_do_list_platform_env_is_ignored(three_source_env, monkeypatch):
assert seen["platform"] is None
+def test_do_check_prints_orphaned_hint(monkeypatch):
+ """Orphaned lock-file entries (local directory gone) surface with a
+ removal hint instead of silently slowing every update run (#104291)."""
+ out = _capture_check(monkeypatch, [
+ {"name": "ghost-skill", "identifier": "clawhub/ghost", "source": "clawhub",
+ "status": "orphaned"},
+ {"name": "ok-skill", "identifier": "clawhub/ok", "source": "clawhub",
+ "status": "up_to_date"},
+ ])
+
+ assert "ghost-skill" in out
+ assert "Orphaned:" in out
+ assert "hermes skills uninstall" in out
+
+
# ---------------------------------------------------------------------------
# Cross-registry hijack regression tests
#
diff --git a/tests/tools/test_skills_hub.py b/tests/tools/test_skills_hub.py
index 3abbe3e68d7..f95475dcec2 100644
--- a/tests/tools/test_skills_hub.py
+++ b/tests/tools/test_skills_hub.py
@@ -522,7 +522,12 @@ class TestCheckForSkillUpdates:
assert bundle_content_hash(bundle) == content_hash(skill_dir)
- def test_reports_update_when_remote_hash_differs(self):
+ def test_reports_update_when_remote_hash_differs(self, tmp_path, monkeypatch):
+ import tools.skills_hub as hub
+ skills_dir = tmp_path / "skills"
+ (skills_dir / "demo-skill").mkdir(parents=True)
+ monkeypatch.setattr(hub, "SKILLS_DIR", skills_dir)
+
lock = MagicMock()
lock.list_installed.return_value = [{
"name": "demo-skill",
@@ -548,6 +553,85 @@ class TestCheckForSkillUpdates:
assert results[0]["name"] == "demo-skill"
assert results[0]["status"] == "update_available"
+ def test_orphaned_entry_reported_without_remote_fetch(self, tmp_path, monkeypatch):
+ """A lock-file entry whose install directory no longer exists is
+ reported ``orphaned`` without paying the remote fetch cost (#104291)."""
+ import tools.skills_hub as hub
+ skills_dir = tmp_path / "skills"
+ skills_dir.mkdir()
+ monkeypatch.setattr(hub, "SKILLS_DIR", skills_dir)
+
+ lock = MagicMock()
+ lock.list_installed.return_value = [{
+ "name": "demo-skill",
+ "source": "github",
+ "identifier": "owner/repo/demo-skill",
+ "content_hash": "hash",
+ "install_path": "demo-skill", # never created on disk
+ }]
+
+ source = MagicMock()
+ source.source_id.return_value = "github"
+
+ results = check_for_skill_updates(lock=lock, sources=[source])
+
+ assert len(results) == 1
+ assert results[0]["status"] == "orphaned"
+ assert "bundle" not in results[0]
+ source.fetch.assert_not_called()
+
+ def test_unresolvable_install_path_keeps_fetch_behavior(self, tmp_path, monkeypatch):
+ """Entries whose install_path cannot resolve (empty/unsafe) keep the
+ pre-existing fetch behavior — only a resolvable-but-missing directory
+ counts as orphaned."""
+ import tools.skills_hub as hub
+ monkeypatch.setattr(hub, "SKILLS_DIR", tmp_path / "skills")
+
+ lock = MagicMock()
+ lock.list_installed.return_value = [{
+ "name": "demo-skill",
+ "source": "github",
+ "identifier": "owner/repo/demo-skill",
+ "content_hash": "oldhash",
+ "install_path": "",
+ }]
+
+ source = MagicMock()
+ source.source_id.return_value = "github"
+ source.fetch.return_value = SkillBundle(
+ name="demo-skill",
+ files={"SKILL.md": "new content"},
+ source="github",
+ identifier="owner/repo/demo-skill",
+ trust_level="community",
+ )
+
+ results = check_for_skill_updates(lock=lock, sources=[source])
+
+ assert len(results) == 1
+ assert results[0]["status"] == "update_available"
+ source.fetch.assert_called_once()
+
+ def test_hanging_fetch_is_abandoned_after_timeout(self):
+ """A fetch that outlives its wall-clock bound degrades to no bundle
+ quickly instead of stalling the whole update run (#104291)."""
+ from tools.skills_hub_install import _fetch_bundle_bounded
+
+ class _HangingSource:
+ def source_id(self):
+ return "github"
+
+ def fetch(self, identifier):
+ time.sleep(10)
+ raise AssertionError("fetch should have been abandoned")
+
+ started = time.monotonic()
+ bundle = _fetch_bundle_bounded(_HangingSource(), "owner/repo/demo-skill", timeout=0.2)
+ elapsed = time.monotonic() - started
+
+ assert bundle is None
+ assert elapsed < 5.0
+
class TestCreateSourceRouter:
def test_url_source_runs_before_github_source(self):
diff --git a/tools/skills_hub_install.py b/tools/skills_hub_install.py
index 5c3ea999369..4679167aba3 100644
--- a/tools/skills_hub_install.py
+++ b/tools/skills_hub_install.py
@@ -11,6 +11,7 @@ from __future__ import annotations
import logging
import hashlib
import shutil
+import threading
from pathlib import Path
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple
from agent.skill_utils import is_excluded_skill_path
@@ -243,6 +244,31 @@ def bundle_content_hash(bundle: SkillBundle) -> str:
_SOURCE_ID_ALIASES = {"skills.sh": "skills-sh"}
+_FETCH_TIMEOUT_SECONDS = 30.0
+
+
+def _fetch_bundle_bounded(
+ src: SkillSource, identifier: str, timeout: float = _FETCH_TIMEOUT_SECONDS,
+) -> Optional[SkillBundle]:
+ """Fetch one bundle with a hard wall-clock bound.
+
+ A dead upstream can hang on network IO far past any useful patience, and
+ every installed skill pays that cost on each update run (#104291). The
+ helper thread is a daemon so an abandoned fetch cannot block CLI exit.
+ """
+ box: Dict[str, SkillBundle] = {}
+
+ def _run() -> None:
+ try:
+ box["bundle"] = src.fetch(identifier)
+ except Exception:
+ pass # callers already treat a failed fetch as "unavailable"
+
+ worker = threading.Thread(target=_run, daemon=True)
+ worker.start()
+ worker.join(timeout)
+ return box.get("bundle")
+
def _source_matches(source: SkillSource, source_name: str) -> bool:
return source.source_id() == _SOURCE_ID_ALIASES.get(source_name, source_name)
@@ -272,12 +298,21 @@ def check_for_skill_updates(
for entry in installed:
identifier, source_name = entry.get("identifier", ""), entry.get("source", "")
row = {"name": entry.get("name", ""), "identifier": identifier, "source": source_name}
+ try:
+ install_dir = _resolve_lock_install_path(
+ entry.get("install_path", ""), entry.get("name", "skill"))
+ orphaned = not install_dir.exists()
+ except ValueError:
+ orphaned = False # unresolvable entries keep the pre-existing fetch behavior
+ if orphaned:
+ # The lock-file entry points at a directory that is gone: the fetched
+ # bundle could never be applied, so skip the network cost entirely
+ # instead of re-paying it on every update run (#104291).
+ results.append({**row, "status": "orphaned"})
+ continue
bundle = None
for src in filter(lambda s: _source_matches(s, source_name), sources):
- try:
- bundle = src.fetch(identifier)
- except Exception:
- bundle = None
+ bundle = _fetch_bundle_bounded(src, identifier)
if bundle:
break
if not bundle: