The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: enforce complete fetch deadlines and inherit request context
Teknium36b0b6c9f29d
diff --git a/tests/hermes_cli/test_skills_hub.py b/tests/hermes_cli/test_skills_hub.pyindex 68607ad20c9..cb137f070b5 100644--- a/tests/hermes_cli/test_skills_hub.py+++ b/tests/hermes_cli/test_skills_hub.py@@ -125,21 +125,6 @@ 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.pyindex f95475dcec2..bad2048fa9e 100644--- a/tests/tools/test_skills_hub.py+++ b/tests/tools/test_skills_hub.py@@ -580,38 +580,6 @@ class TestCheckForSkillUpdates: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 bundlequickly instead of stalling the whole update run (#104291)."""diff --git a/tools/skills_hub_install.py b/tools/skills_hub_install.pyindex 4679167aba3..5e6efcccd0a 100644--- a/tools/skills_hub_install.py+++ b/tools/skills_hub_install.py@@ -12,6 +12,8 @@ import loggingimport hashlibimport shutilimport threading+import time+from contextvars import copy_contextfrom pathlib import Pathfrom typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuplefrom agent.skill_utils import is_excluded_skill_path@@ -256,18 +258,21 @@ def _fetch_bundle_bounded(every installed skill pays that cost on each update run (#104291). Thehelper thread is a daemon so an abandoned fetch cannot block CLI exit."""- box: Dict[str, SkillBundle] = {}+ deadline = time.monotonic() + timeout+ box: Dict[str, Tuple[float, Optional[SkillBundle]]] = {}def _run() -> None:try:- box["bundle"] = src.fetch(identifier)+ bundle = src.fetch(identifier)+ box["result"] = (time.monotonic(), bundle)except Exception:- pass # callers already treat a failed fetch as "unavailable"+ logger.debug("Skill update fetch failed for %s", identifier, exc_info=True)- worker = threading.Thread(target=_run, daemon=True)+ worker = threading.Thread(target=copy_context().run, args=(_run,), daemon=True)worker.start()- worker.join(timeout)- return box.get("bundle")+ worker.join(max(0.0, deadline - time.monotonic()))+ finished, bundle = box.get("result", (float("inf"), None))+ return bundle if finished <= deadline else Nonedef _source_matches(source: SkillSource, source_name: str) -> bool: