Skip to content

The agent that grows with you

perf(banner): scope startup update-check fetch to origin/main

teknium158b78f5a0a6d
diff --git a/hermes_cli/banner.py b/hermes_cli/banner.py
index 08e2ceeb1fa..4d2b077ec96 100644
--- a/hermes_cli/banner.py
+++ b/hermes_cli/banner.py
@@ -219,7 +219,15 @@ def _check_via_local_git(repo_dir: Path) -> Optional[int]:
is_shallow = shallow == "true"
try:
- fetch_args = ["git", "fetch", "origin"]
+ # Scope the fetch to the one branch the behind-count compares against.
+ # An unscoped ``git fetch origin`` transfers every remote head (~1,400
+ # on this repo — measured 3.0 s vs 0.55 s scoped) and can burn the full
+ # 10 s timeout on slow links. ``cmd_update`` already scopes its fetch
+ # for the same reason. Modern git updates the ``origin/main`` tracking
+ # ref on a scoped fetch, so the ``HEAD..origin/main`` count below is
+ # unaffected; the shallow path compares against FETCH_HEAD, which a
+ # scoped fetch also updates.
+ fetch_args = ["git", "fetch", "origin", "main"]
if is_shallow:
fetch_args += ["--depth", "1"]
fetch_args.append("--quiet")
diff --git a/tests/hermes_cli/test_update_check.py b/tests/hermes_cli/test_update_check.py
index 48a8da3045c..3347afa5bbe 100644
--- a/tests/hermes_cli/test_update_check.py
+++ b/tests/hermes_cli/test_update_check.py
@@ -165,8 +165,9 @@ def test_check_via_local_git_shallow_clone_behind_reports_no_count(tmp_path):
result = banner._check_via_local_git(repo_dir)
assert result == banner.UPDATE_AVAILABLE_NO_COUNT
- # The shallow fetch must preserve the boundary (--depth 1), not unshallow.
- assert ["git", "fetch", "origin", "--depth", "1", "--quiet"] in calls
+ # The shallow fetch must preserve the boundary (--depth 1), not unshallow,
+ # and must stay scoped to main (unscoped fetches transfer ~1,400 heads).
+ assert ["git", "fetch", "origin", "main", "--depth", "1", "--quiet"] in calls
def test_check_via_local_git_shallow_clone_up_to_date(tmp_path):