Skip to content

The agent that grows with you

fix(skills): a bundle with a failed blob fetch records no revision; tree misses are cached; the probe is guarded

kshitijk4poor4f9e15f1d3ec
diff --git a/tests/tools/test_skills_hub.py b/tests/tools/test_skills_hub.py
index 39a805e67bd..4208cdecda4 100644
--- a/tests/tools/test_skills_hub.py
+++ b/tests/tools/test_skills_hub.py
@@ -722,6 +722,24 @@ class TestCheckForSkillUpdates:
if expected_status == "up_to_date":
assert results[0]["current_hash"] == results[0]["latest_hash"] == "installed-hash"
+ def test_bundle_with_a_failed_blob_fetch_records_no_revision(self):
+ """A transient blob failure installs with a gap; the lock must NOT carry the tree sha, or the
+ revision short-circuit would report the gap ``up_to_date`` forever instead of re-fetching."""
+ calls: dict = {}
+ source = self._github_source_with_tree("a" * 40, calls)
+ good_bytes = source._fetch_file_bytes
+ source._fetch_file_bytes = (
+ lambda repo, path, **kw: None if path.endswith("notes.md") else good_bytes(repo, path, **kw))
+
+ bundle = source.fetch("owner/repo/demo-skill")
+
+ assert bundle is not None and "references/notes.md" not in bundle.files
+ assert bundle.metadata["source_revision"] == ""
+ # and a clean fetch of the same tree does record it
+ assert source.fetch("owner/repo/demo-skill") is not None
+ source._fetch_file_bytes = good_bytes
+ assert source.fetch("owner/repo/demo-skill").metadata["source_revision"] == "a" * 40
+
class TestCreateSourceRouter:
def test_url_source_runs_before_github_source(self):
diff --git a/tools/skills_hub_github.py b/tools/skills_hub_github.py
index f51b9e826e6..f2dc945a1b9 100644
--- a/tools/skills_hub_github.py
+++ b/tools/skills_hub_github.py
@@ -220,7 +220,7 @@ class GitHubSource(SkillSource):
self.taps = list(self.DEFAULT_TAPS) + list(extra_taps or [])
# Per-instance repo -> (default_branch, tree_entries); lives for one
# search/install flow so repeated tree lookups cost no API calls.
- self._tree_cache: Dict[str, Tuple[str, List[dict]]] = {}
+ self._tree_cache: Dict[str, Optional[Tuple[str, List[dict]]]] = {}
self._tree_revisions: Dict[str, str] = {}
# repo -> skills.sh.json grouping map; None = fetched, no sidecar.
self._skillsh_groupings: Dict[str, Optional[Dict[str, str]]] = {}
@@ -273,9 +273,12 @@ class GitHubSource(SkillSource):
return None
files: Dict[str, Union[str, bytes]] = {"SKILL.md": skill_md}
if tree is not None:
- if not self._collect_tree_files(repo, skill_dir, tree[1], pinned_ref, referenced, files):
+ complete = self._collect_tree_files(repo, skill_dir, tree[1], pinned_ref, referenced, files)
+ if complete is None:
return None
- revision = pinned_ref or tree[0]
+ # A bundle with a transiently failed blob fetch must not record the tree sha: the
+ # update check would otherwise see "same revision" and never re-fetch the gap (#101454).
+ revision = (pinned_ref or tree[0]) if complete else ""
else:
for rel_path in referenced:
self._add_support_file(repo, f"{skill_dir}/{rel_path}", rel_path, files, rel_path)
@@ -291,29 +294,34 @@ class GitHubSource(SkillSource):
no blob downloads — so an update check can skip refetching unchanged skills."""
if (split := _split_repo_id(identifier)) is None:
return ""
- self._get_repo_tree(split[0])
- return self._tree_revisions.get(split[0], "")
+ repo, _ = split
+ self._get_repo_tree(repo) # populates _tree_revisions
+ return self._tree_revisions.get(repo, "")
- def _add_support_file(self, repo: str, item_path: str, rel_path: str, files: dict, shown: str, **kw) -> None:
- """Fetch one support file into ``files``; a failed fetch warns (naming ``shown``) and is skipped."""
+ def _add_support_file(self, repo: str, item_path: str, rel_path: str, files: dict, shown: str, **kw) -> bool:
+ """Fetch one support file into ``files``; a failed fetch warns (naming ``shown``), is skipped, and
+ returns False."""
content = self._fetch_file_bytes(repo, item_path, **kw)
if content is None:
logger.warning("Failed to fetch referenced skill support file; continuing without it: %s", shown)
- else:
- files[rel_path] = content
+ return False
+ files[rel_path] = content
+ return True
def _collect_tree_files(
self, repo: str, skill_path: str, entries: List[dict], ref: Optional[str], referenced: set,
files: Dict[str, Union[str, bytes]],
- ) -> bool:
+ ) -> Optional[bool]:
"""Download the FULL skill directory from the pinned tree into ``files``. Link-driven fetching
silently dropped support files under non-canonical dirs (``reference/``, ``agents/``, root
LICENSE); everything still goes through quarantine + scan, and the scanner sees MORE this way.
- Returns False (bundle rejected) on an unsafe path or a SKILL.md-linked path that exists in the
+ Returns None (bundle rejected) on an unsafe path or a SKILL.md-linked path that exists in the
tree as a symlink/non-blob — that shape is an escape attempt. A linked path that is simply absent
- is a dangling link (repo-only dev tool, prose over-match): warn and install without it."""
+ is a dangling link (repo-only dev tool, prose over-match): warn and install without it. Returns
+ False when a blob fetch failed (installed with a gap the next update check must be able to fill)."""
prefix = f"{skill_path}/"
symlinked: set = set()
+ complete = True
for rel_path, item_path, regular in _tree_members(entries, prefix):
if not regular:
symlinked.add(rel_path)
@@ -324,8 +332,8 @@ class GitHubSource(SkillSource):
rel_path = _validate_bundle_rel_path(rel_path)
except ValueError:
logger.warning("Rejected unsafe file path in skill bundle: %s", item_path)
- return False
- self._add_support_file(repo, item_path, rel_path, files, item_path, ref=ref)
+ return None
+ complete &= self._add_support_file(repo, item_path, rel_path, files, item_path, ref=ref)
for rel_path in sorted(referenced):
# A SKILL.md-linked support path that isn't in the tree is a dangling link — a repo-only dev
# tool, prose over-match, or a file the author forgot to push. Warn and install without it
@@ -335,11 +343,11 @@ class GitHubSource(SkillSource):
# file.
if rel_path in symlinked:
logger.warning("Rejected non-regular referenced file in skill bundle: %s%s", prefix, rel_path)
- return False
+ return None
if rel_path not in files:
logger.warning(
"Referenced skill support file is missing; continuing without it: %s%s", prefix, rel_path)
- return True
+ return complete
def inspect(self, identifier: str) -> Optional[SkillMeta]:
"""Fetch just the SKILL.md metadata for preview."""
@@ -397,6 +405,9 @@ class GitHubSource(SkillSource):
time (~12 of the 60/hr unauthenticated budget before)."""
if repo in self._tree_cache:
return self._tree_cache[repo]
+ # Misses are cached too: within one command a truncated/unreachable tree stays that way,
+ # and the update check now probes the tree before every fetch (#101454).
+ self._tree_cache[repo] = None
repo_data = self._github_json(f"{_API}/{repo}")
if repo_data is None:
return None
@@ -407,7 +418,7 @@ class GitHubSource(SkillSource):
if tree_data is None:
return None
if tree_data.get("truncated"):
- logger.debug("Git tree truncated for %s, cannot cache", repo)
+ logger.debug("Git tree truncated for %s", repo)
return None
if isinstance(tree_data.get("sha"), str) and tree_data["sha"]:
self._tree_revisions[repo] = tree_data["sha"]
diff --git a/tools/skills_hub_install.py b/tools/skills_hub_install.py
index 5f9fe1ab775..dc32cc340ed 100644
--- a/tools/skills_hub_install.py
+++ b/tools/skills_hub_install.py
@@ -248,6 +248,15 @@ def _source_matches(source: SkillSource, source_name: str) -> bool:
return source.source_id() == _SOURCE_ID_ALIASES.get(source_name, source_name)
+
+def _current_revision_or_empty(src, identifier: str) -> str:
+ """A probe failure must degrade one row to the full-fetch path, not abort the whole check."""
+ try:
+ return src.current_revision(identifier)
+ except Exception:
+ logger.debug("current_revision probe failed for %s", identifier, exc_info=True)
+ return ""
+
def check_for_skill_updates(
name: Optional[str] = None, *, lock: Optional[HubLockFile] = None,
sources: Optional[List[SkillSource]] = None, auth: Optional[GitHubAuth] = None,
@@ -287,7 +296,7 @@ def check_for_skill_updates(
continue
matching = [src for src in sources if _source_matches(src, source_name)]
recorded = (entry.get("metadata") or {}).get("source_revision", "")
- if recorded and any(src.current_revision(identifier) == recorded for src in matching):
+ if recorded and any(_current_revision_or_empty(src, identifier) == recorded for src in matching):
# Same upstream tree as at install time: the bundle bytes cannot differ, so
# skip downloading SKILL.md + every support blob just to re-hash them (#101454).
content_hash = entry.get("content_hash", "")