Skip to content

The agent that grows with you

fix: startup update check no longer lazy-fetches history in partial clones

teknium158f3bf10c053
diff --git a/hermes_cli/_subprocess_compat.py b/hermes_cli/_subprocess_compat.py
index 61951030484..3c050c8e86e 100644
--- a/hermes_cli/_subprocess_compat.py
+++ b/hermes_cli/_subprocess_compat.py
@@ -28,6 +28,7 @@ __all__ = [
"bounded_probe_run",
"noninteractive_git_env",
"NO_DRIVER_DIFF_FLAGS",
+ "NO_LAZY_FETCH_ENV",
"pid_is_hermes",
]
@@ -211,6 +212,14 @@ def windows_detach_popen_kwargs() -> dict:
return {"start_new_session": True}
+# Read-only probes must never lazy-fetch. In a partial (blobless/treeless) clone a missing object makes
+# git spawn ``git fetch`` from the promisor remote, and a probe's timeout kills only its own git: the
+# startup update check's ``merge-base --is-ancestor <fresh upstream tip>`` started a ~233k-object
+# history download on every launch that ran on orphaned, piling up partial packs. With this set the
+# probe fails fast on the missing object instead (git >= 2.44; older git ignores the variable).
+NO_LAZY_FETCH_ENV = {"GIT_NO_LAZY_FETCH": "1"}
+
+
# GIT_CONFIG_KEY_n/VALUE_n overrides for internal git children: no credential/askpass prompts, no
# repo-configured fsmonitor/hooks/pager/editor/external-diff programs.
_GIT_CONFIG_INJECT_PREFIXES = ("GIT_CONFIG_KEY_", "GIT_CONFIG_VALUE_")
@@ -583,7 +592,7 @@ def bounded_git_probe(argv: Sequence[str], *, timeout: float) -> str:
openai/codex#36793). ``process_group`` only changes which group the child belongs to; it does not detach
the terminal or alter the fast path.
"""
- result = bounded_probe_run(argv, timeout=timeout, env=noninteractive_git_env())
+ result = bounded_probe_run(argv, timeout=timeout, env={**noninteractive_git_env(), **NO_LAZY_FETCH_ENV})
if result is None or result.returncode != 0:
return ""
return (result.stdout or "").strip()
diff --git a/hermes_cli/banner.py b/hermes_cli/banner.py
index 4416a46d7aa..b7c74b27462 100644
--- a/hermes_cli/banner.py
+++ b/hermes_cli/banner.py
@@ -179,15 +179,16 @@ def _git_run(args: list[str], *, cwd: Optional[Path] = None, timeout: int = 5, t
git output is UTF-8; on Windows ``text=True`` defaults to the ANSI code page and a byte like the
3rd of 🐛 in a commit subject crashes the stdlib reader thread (#52649), hence the explicit
encoding. ``network=True`` (ls-remote/fetch) detaches stdin and disables git/GCM prompts so a
- passive update check can never hang on a ``Username for 'https://github.com':`` prompt.
+ passive update check can never hang on a ``Username for 'https://github.com':`` prompt. No probe
+ here may lazy-fetch from a partial clone's promisor remote (see ``NO_LAZY_FETCH_ENV``).
"""
- from hermes_cli._subprocess_compat import noninteractive_git_env, windows_hide_flags
+ from hermes_cli._subprocess_compat import NO_LAZY_FETCH_ENV, noninteractive_git_env, windows_hide_flags
# The banner/update probes run from GUI-hosted backends too (desktop-spawned
# ``hermes serve``), where a bare git child flashes a console window.
- kwargs: dict = {"creationflags": windows_hide_flags()}
+ kwargs: dict = {"creationflags": windows_hide_flags(), "env": {**os.environ, **NO_LAZY_FETCH_ENV}}
if network:
- kwargs.update({"stdin": subprocess.DEVNULL, "env": noninteractive_git_env()})
+ kwargs.update({"stdin": subprocess.DEVNULL, "env": {**noninteractive_git_env(), **NO_LAZY_FETCH_ENV}})
try:
return subprocess.run(
["git", *args], capture_output=True, timeout=timeout, cwd=str(cwd) if cwd is not None else None,
diff --git a/tests/hermes_cli/test_git_probe_no_lazy_fetch.py b/tests/hermes_cli/test_git_probe_no_lazy_fetch.py
new file mode 100644
index 00000000000..7443004d677
--- /dev/null
+++ b/tests/hermes_cli/test_git_probe_no_lazy_fetch.py
@@ -0,0 +1,75 @@
+"""Read-only git probes never lazy-fetch from a partial clone's promisor remote.
+
+In a blobless clone, asking about an object the clone has not fetched (the fresh upstream tip the
+startup update check compares against) makes git download it — for a real install, the whole
+commit/tree history — and the probe's timeout kills only its own git, orphaning the fetch.
+"""
+
+import os
+import re
+import subprocess
+from pathlib import Path
+
+import pytest
+
+from hermes_cli import banner
+from hermes_cli._subprocess_compat import bounded_git_probe
+
+_ENV = {**os.environ, "GIT_CONFIG_GLOBAL": os.devnull, "GIT_CONFIG_NOSYSTEM": "1"}
+
+
+def _git(*args, cwd=None, env=_ENV):
+ return subprocess.run(["git", "-c", "user.name=t", "-c", "user.email=t@t", *args], cwd=cwd, env=env,
+ check=True, capture_output=True, text=True).stdout.strip()
+
+
+def _git_supports_no_lazy_fetch() -> bool:
+ m = re.search(r"(\d+)\.(\d+)", _git("--version"))
+ return bool(m) and (int(m[1]), int(m[2])) >= (2, 44)
+
+
+pytestmark = pytest.mark.skipif(not _git_supports_no_lazy_fetch(), reason="GIT_NO_LAZY_FETCH needs git >= 2.44")
+
+
+def partial_clone(tmp_path: Path):
+ """(clone, local_head, unfetched_upstream_tip) for a blobless clone of a local upstream."""
+ seed, up, clone = tmp_path / "seed", tmp_path / "up.git", tmp_path / "clone"
+ _git("init", "-q", "-b", "main", str(seed))
+ for i in range(2):
+ (seed / f"f{i}.txt").write_text(f"v{i}\n" * 50, encoding="utf-8")
+ _git("add", "-A", cwd=seed)
+ _git("commit", "-qm", f"c{i}", cwd=seed)
+ _git("clone", "-q", "--bare", str(seed), str(up))
+ _git("config", "uploadpack.allowFilter", "true", cwd=up)
+ _git("config", "uploadpack.allowAnySHA1InWant", "true", cwd=up)
+ _git("clone", "-q", "--filter=blob:none", "--no-checkout", up.as_uri(), str(clone))
+ (seed / "new.txt").write_text("upstream moved\n", encoding="utf-8")
+ _git("add", "-A", cwd=seed)
+ _git("commit", "-qm", "upstream", cwd=seed)
+ _git("push", "-q", str(up), "main", cwd=seed)
+ return clone, _git("rev-parse", "HEAD", cwd=clone), _git("rev-parse", "main", cwd=up)
+
+
+def _fetched(clone: Path, sha: str) -> bool:
+ env = {**_ENV, "GIT_NO_LAZY_FETCH": "1"}
+ return subprocess.run(["git", "cat-file", "-e", sha], cwd=clone, env=env, capture_output=True).returncode == 0
+
+
+def test_update_check_ancestry_probe_never_fetches_from_the_promisor(partial_clone, monkeypatch):
+ clone, head, upstream_tip = partial_clone
+ monkeypatch.setattr(banner, "_github_compare_behind", lambda cur, tgt: None)
+
+ assert banner._tips_behind(head, upstream_tip, clone) == banner.UPDATE_AVAILABLE_NO_COUNT
+ assert not _fetched(clone, upstream_tip), "the update check downloaded upstream history"
+ # Control: an upstream tip already in local history still reads as up to date.
+ parent = _git("rev-parse", "HEAD~1", cwd=clone)
+ assert banner._tips_behind(head, parent, clone) == 0
+
+
+def test_bounded_git_probe_never_fetches_from_the_promisor(partial_clone):
+ clone, head, upstream_tip = partial_clone
+
+ assert bounded_git_probe(["git", "-C", str(clone), "log", "-1", "--format=%H", upstream_tip], timeout=10) == ""
+ assert not _fetched(clone, upstream_tip), "a session-start git probe downloaded upstream history"
+ assert bounded_git_probe(["git", "-C", str(clone), "log", "-1", "--format=%H", head], timeout=10) == head
diff --git a/website/docs/user-guide/configuration.md b/website/docs/user-guide/configuration.md
index 6ddbc5404de..b87b25d27db 100644
--- a/website/docs/user-guide/configuration.md
+++ b/website/docs/user-guide/configuration.md
@@ -170,7 +170,9 @@ Leaving these unset keeps the legacy defaults (`HERMES_API_TIMEOUT=1800`s, `HERM
Passive update checks (CLI banner, TUI badge, dashboard, desktop app) ask the
GitHub REST API for the tip of `main` and, when it differs from your checkout,
the compare endpoint for the exact count and changelog. They never run
-`git fetch`, and every install asks at most **once per 24 hours** (a failed check
+`git fetch` — in a partial (`--filter=blob:none`) clone they also never
+download missing objects from the promisor remote (Git 2.44 or newer) — and
+every install asks at most **once per 24 hours** (a failed check
retries after an hour). Applying an update (`hermes update`, or the desktop's
Update button) always fetches fresh and invalidates the cached answer. Explicit
checks — `hermes update --check`, the desktop's "Check for Updates…" menu item,