Skip to content

The agent that grows with you

perf(skills): skip bundle downloads when the GitHub tree revision is unchanged

kshitijk4poor075ed55493a4
diff --git a/tests/tools/test_skills_hub.py b/tests/tools/test_skills_hub.py
index b7631b4d73c..39a805e67bd 100644
--- a/tests/tools/test_skills_hub.py
+++ b/tests/tools/test_skills_hub.py
@@ -679,6 +679,49 @@ class TestCheckForSkillUpdates:
assert "bundle" not in results[0]
source.fetch.assert_not_called()
+ @staticmethod
+ def _github_source_with_tree(tree_sha: str, calls: dict) -> GitHubSource:
+ """Real ``GitHubSource`` whose API is stubbed: one tree at ``tree_sha`` holding SKILL.md
+ plus two support blobs; every file GET is counted in ``calls``."""
+ src = GitHubSource(auth=MagicMock())
+ entries = [{"path": f"demo-skill/{p}", "type": "blob", "sha": f"sha-{p}", "size": 3}
+ for p in ("SKILL.md", "scripts/run.sh", "references/notes.md")]
+ api = {"/repos/owner/repo": {"default_branch": "main"},
+ "/repos/owner/repo/git/trees/main": {"sha": tree_sha, "tree": entries}}
+ src._github_json = lambda url, **kw: api[url.split("api.github.com", 1)[1]]
+ def _file(repo, path, **kw):
+ calls["files"] = calls.get("files", 0) + 1
+ return "---\nname: demo-skill\n---\nSee scripts/run.sh and references/notes.md\n"
+ src._fetch_file_content = _file
+ src._fetch_file_bytes = lambda repo, path, **kw: _file(repo, path, **kw).encode()
+ return src
+
+ @pytest.mark.parametrize("recorded, expected_status, expected_gets",
+ [("a" * 40, "up_to_date", 0), ("b" * 40, "update_available", 3)])
+ def test_unchanged_upstream_revision_skips_bundle_download(
+ self, tmp_path, monkeypatch, recorded, expected_status, expected_gets):
+ """A lock entry whose recorded ``source_revision`` still matches the upstream tree
+ sha is reported ``up_to_date`` with zero file GETs; a moved tree pays the full fetch (#101454)."""
+ import tools.skills_hub as hub
+ (tmp_path / "skills" / "demo-skill").mkdir(parents=True)
+ 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": "installed-hash", "install_path": "demo-skill",
+ "metadata": {"source_revision": recorded},
+ }]
+ calls: dict = {}
+ source = self._github_source_with_tree("a" * 40, calls)
+
+ results = check_for_skill_updates(lock=lock, sources=[source])
+
+ assert [r["status"] for r in results] == [expected_status]
+ assert calls.get("files", 0) == expected_gets
+ assert ("bundle" in results[0]) == (expected_status == "update_available")
+ if expected_status == "up_to_date":
+ assert results[0]["current_hash"] == results[0]["latest_hash"] == "installed-hash"
+
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 54999a57ac1..f51b9e826e6 100644
--- a/tools/skills_hub_github.py
+++ b/tools/skills_hub_github.py
@@ -286,6 +286,14 @@ class GitHubSource(SkillSource):
trust_level=self.trust_level_for(identifier), metadata={"source_url": url, "source_revision": revision},
)
+ def current_revision(self, identifier: str) -> str:
+ """Tree sha the default branch currently resolves to — one cached tree lookup per repo,
+ 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], "")
+
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."""
content = self._fetch_file_bytes(repo, item_path, **kw)
diff --git a/tools/skills_hub_install.py b/tools/skills_hub_install.py
index 0272e51ac40..5f9fe1ab775 100644
--- a/tools/skills_hub_install.py
+++ b/tools/skills_hub_install.py
@@ -285,8 +285,16 @@ def check_for_skill_updates(
# instead of re-paying it on every update run (#104291).
results.append({**row, "status": "orphaned"})
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):
+ # 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", "")
+ results.append({**row, "status": "up_to_date", "current_hash": content_hash, "latest_hash": content_hash})
+ continue
bundle = None
- for src in filter(lambda s: _source_matches(s, source_name), sources):
+ for src in matching:
try:
bundle = src.fetch(identifier)
except Exception:
diff --git a/tools/skills_hub_models.py b/tools/skills_hub_models.py
index a1c5d8c5843..969e87d8d0f 100644
--- a/tools/skills_hub_models.py
+++ b/tools/skills_hub_models.py
@@ -151,6 +151,11 @@ class SkillSource(ABC):
def trust_level_for(self, identifier: str) -> str:
return self.TRUST_LEVEL
+ def current_revision(self, identifier: str) -> str:
+ """Upstream revision the skill would be fetched at; "" when the registry has no cheap
+ revision probe, which keeps update checks on the full-fetch path."""
+ return ""
+
class GuardedFetchMixin:
"""SSRF/policy-guarded GETs, routed through ``tools.skills_hub`` (test-patchable)."""