Skip to content

The agent that grows with you

fix(skills): retry a failed skills.sh sitemap shard; never cache a partial catalog

teknium143eda09e2d5d
diff --git a/tests/tools/test_skills_hub.py b/tests/tools/test_skills_hub.py
index bcc2dfc2bde..32e759998ff 100644
--- a/tests/tools/test_skills_hub.py
+++ b/tests/tools/test_skills_hub.py
@@ -254,6 +254,31 @@ class TestSkillsShSource:
assert results[0].path == "vercel-react-best-practices"
assert results[0].extra["installs"] == 207679
+ @patch("tools.skills_hub_skillssh.time.sleep")
+ @patch("tools.skills_hub._write_index_cache")
+ @patch("tools.skills_hub._read_index_cache", return_value=None)
+ def test_sitemap_catalog_retries_failed_shard_and_never_caches_partial(
+ self, _mock_read_cache, mock_write_cache, _mock_sleep,
+ ):
+ """A per-skill sitemap shard that keeps failing is a hole in the catalog, not an
+ empty shard: retry it, and never publish the partial slice to the shared cache."""
+ index = ("<sitemapindex><sitemap><loc>https://www.skills.sh/sitemap-skills-0.xml</loc></sitemap>"
+ "<sitemap><loc>https://www.skills.sh/sitemap-skills-1.xml</loc></sitemap></sitemapindex>")
+ shard0 = "<urlset><url><loc>https://www.skills.sh/o/r/skill-a</loc></url></urlset>"
+ calls: List[str] = []
+
+ def fake_get_text(url, **kwargs):
+ calls.append(url)
+ if url.endswith("sitemap.xml"):
+ return index
+ return shard0 if url.endswith("sitemap-skills-0.xml") else None
+
+ with patch("tools.skills_hub_skillssh._get_text", side_effect=fake_get_text):
+ results = self._source()._sitemap_catalog(0)
+
+ assert [m.identifier for m in results] == ["skills-sh/o/r/skill-a"]
+ assert calls.count("https://www.skills.sh/sitemap-skills-1.xml") == SkillSource.CATALOG_PAGE_RETRIES
+ mock_write_cache.assert_not_called()
@patch("tools.skills_hub._write_index_cache")
@patch("tools.skills_hub._read_index_cache", return_value=None)
diff --git a/tools/skills_hub_clawhub.py b/tools/skills_hub_clawhub.py
index 70b52b3a2e5..cec319c5137 100644
--- a/tools/skills_hub_clawhub.py
+++ b/tools/skills_hub_clawhub.py
@@ -67,8 +67,6 @@ class ClawHubSource(GuardedFetchMixin, SkillSource):
# Wall-clock budget for a full catalog walk: 50k+ skills, sequential
# (~250 requests each under timeout=30), so unbounded it blocks for minutes.
CATALOG_WALK_BUDGET_SECONDS = 12
- # Consecutive failed fetches of one catalog page before the walk gives up as partial.
- CATALOG_PAGE_RETRIES = 5
ZIP_DOWNLOAD_MAX_BYTES = 25 * 1024 * 1024
ZIP_DOWNLOAD_CHUNK_BYTES = 64 * 1024
_SLUG_RE = re.compile(r"[A-Za-z0-9][A-Za-z0-9._-]*$")
diff --git a/tools/skills_hub_models.py b/tools/skills_hub_models.py
index bcefb0224e9..a1c5d8c5843 100644
--- a/tools/skills_hub_models.py
+++ b/tools/skills_hub_models.py
@@ -130,6 +130,8 @@ class SkillSource(ABC):
SOURCE_ID: str = ""
TRUST_LEVEL: str = "community"
+ # Consecutive failed fetches of one catalog page/shard before a walk gives up as partial.
+ CATALOG_PAGE_RETRIES = 5
@abstractmethod
def search(self, query: str, limit: int = 10) -> List[SkillMeta]:
diff --git a/tools/skills_hub_skillssh.py b/tools/skills_hub_skillssh.py
index 5d7a94a8484..a5cd8cd7777 100644
--- a/tools/skills_hub_skillssh.py
+++ b/tools/skills_hub_skillssh.py
@@ -3,6 +3,7 @@
import hashlib
import logging
import re
+import time
from typing import Any, Dict, List, Optional
from tools.skills_hub_github import GitHubAuth, GitHubSource, _split_repo_id
@@ -137,11 +138,20 @@ class SkillsShSource(SkillSource):
if not skill_sitemap_urls:
return self._featured_skills(limit)
- # Step 2: collect canonical "owner/repo/skill" IDs from each sitemap.
- seen, results = set(), []
+ # Step 2: collect canonical "owner/repo/skill" IDs from each sitemap. A shard
+ # ``_get_text`` returns None for is a hole, not an empty shard: retry it, and
+ # if it stays dark return the partial slice without publishing it to the cache.
+ seen, results, partial = set(), [], False
for sitemap_url in skill_sitemap_urls:
- xml = _xml(sitemap_url, 30)
- for loc_match in self._SITEMAP_LOC_RE.finditer(xml or ""):
+ for attempt in range(1, self.CATALOG_PAGE_RETRIES + 1):
+ xml = _xml(sitemap_url, 30)
+ if xml is not None or attempt == self.CATALOG_PAGE_RETRIES:
+ break
+ time.sleep(min(2 ** attempt, 8))
+ if xml is None:
+ partial = True
+ continue
+ for loc_match in self._SITEMAP_LOC_RE.finditer(xml):
m = self._SITEMAP_SKILL_RE.match(loc_match.group(1).strip())
if not m:
continue
@@ -153,7 +163,8 @@ class SkillsShSource(SkillSource):
path=skill, extra=self._urls_for(canonical, repo)))
if not results:
return self._featured_skills(limit)
- _cache_metas(cache_key, results)
+ if not partial:
+ _cache_metas(cache_key, results)
return results[:limit] if limit > 0 else results
def _featured_skills(self, limit: int) -> List[SkillMeta]: