Skip to content

The agent that grows with you

fix(update): one commit-graph fetch for the pre-fetch heal and the post-update pass

teknium1010618c7673d
diff --git a/hermes_cli/gitlock.py b/hermes_cli/gitlock.py
index b98b49f1451..2e9bb081205 100644
--- a/hermes_cli/gitlock.py
+++ b/hermes_cli/gitlock.py
@@ -408,16 +408,7 @@ def prune_stale_shallow_grafts(repo_root: Path) -> int:
def _partial_clone_filter(repo_root: Path, **run_kwargs) -> "str | None":
- """The checkout's existing fetch filter, or None for a non-partial clone.
-
- ``git fetch --filter=...`` *writes* ``remote.origin.promisor`` and
- ``remote.origin.partialclonefilter`` even when the repo was deliberately
- de-partialised, so a filter may only be passed when the repo already is a
- partial clone — and then it must repeat the clone's own filter rather
- than override it, or the tag fetch would silently tighten (or loosen)
- the transfer semantics the installer established. Read-only config probe;
- failures read as "not partial".
- """
+ """The checkout's own ``remote.origin.partialclonefilter``, or None for a non-partial clone."""
result = subprocess.run(
["git", "config", "--get", "remote.origin.promisor"],
cwd=str(repo_root), capture_output=True, text=True,
@@ -434,79 +425,52 @@ def _partial_clone_filter(repo_root: Path, **run_kwargs) -> "str | None":
def heal_shallow_history(repo_root: Path, branch: str, **run_kwargs) -> bool:
- """Unshallow a stale installer checkout before the updater's bounded fetch.
-
- A depth-1 install that has fallen far behind ``branch`` cannot complete the
- plain ``git fetch origin <branch>`` inside the updater's 300s network cap:
- the server must send the full ancestry of every side branch merged past the
- shallow boundary, each attempt is killed mid-transfer, and the unshallow
- step that would make later fetches incremental only ran *after* a
- successful update — so a stale shallow install could never update at all
- (#123254). This heals the checkout first, with the same commit-graph-only
- shape and 900s budget the post-update tag fetch uses, pulling ``branch``
- along so the bounded fetch that follows is small again.
-
- Returns whether the checkout was shallow. Raises on fetch failure; the
- checkout is left exactly as it was, so callers can downgrade the failure
- to a warning and keep the previous fetch behaviour.
+ """Unshallow a stale installer checkout before the updater's bounded fetch (#123254).
+
+ From a depth-1 clone far behind ``branch``, a plain ``git fetch origin <branch>`` makes the
+ server send the full ancestry of every side branch merged past the shallow boundary, which
+ cannot finish inside the 300s network cap; the post-update unshallow never got to run. Fetch
+ the commit graph first (900s budget), pulling ``branch`` along so the bounded fetch that
+ follows is small. Returns whether the checkout was shallow; raises on fetch failure.
"""
- shallow = _shallow_file_path(repo_root) is not None
- if not shallow:
- return False
- subprocess.run(
- ["git", "fetch", "--quiet", "--unshallow", "--filter=tree:0", "--no-tags",
- "origin", "refs/tags/v*:refs/tags/v*", branch],
- cwd=str(repo_root), check=True, capture_output=True, text=True,
- encoding="utf-8", errors="replace", timeout=900, **run_kwargs,
- )
- return True
+ return _shallow_file_path(repo_root) is not None and fetch_full_commit_graph(repo_root, branch, **run_kwargs)
-def fetch_full_commit_graph(repo_root: Path, **run_kwargs) -> bool:
+def fetch_full_commit_graph(repo_root: Path, *extra_refspecs: str, **run_kwargs) -> bool:
"""Refresh release tags and fill shallow history before publishing identity.
A full commit graph does not imply current tags, especially after a --no-tags
clone. Fetch version tags explicitly without fetching every remote branch or
- replacing existing tags. On partial clones trees stay on demand. A full clone
- must be fetched unfiltered: passing ``--filter`` would (re)write the promisor
- config on a checkout the user deliberately de-partialised, re-arming the
- ``should_include_obj`` fetch failure (#122353). Returns whether the checkout
- was unshallowed; fetch failures raise subprocess errors.
+ replacing existing tags. The fetch never changes the clone's mode: ``--filter`` makes git
+ write ``remote.origin.promisor``/``partialclonefilter``, so a full clone fetches unfiltered
+ (#122353) and a partial clone repeats its own filter. The one conversion is deliberate: a
+ depth-limited full clone whose history is really missing unshallows as ``tree:0``, because an
+ unfiltered ``--unshallow`` downloads the whole project history; a full clone grafted by a
+ ``--depth`` fetch already has its history and stays full. Returns whether the checkout was unshallowed; fetch failures raise
+ subprocess errors.
"""
- shallow = _shallow_file_path(repo_root) is not None
- partial_filter = _partial_clone_filter(repo_root, **run_kwargs)
+ shallow_path = _shallow_file_path(repo_root)
+ shallow = shallow_path is not None
+ fetch_filter = _partial_clone_filter(repo_root, **run_kwargs)
+ if fetch_filter is None and shallow and _batch_missing_parents(
+ repo_root, shallow_path.read_text(encoding="utf-8-sig").split()):
+ fetch_filter = "tree:0"
subprocess.run(
- ["git", "fetch", "--quiet", *([ "--unshallow" ] if shallow else []),
- *( [ f"--filter={partial_filter}" ] if partial_filter else [] ),
- "--no-tags", "origin", "refs/tags/v*:refs/tags/v*"],
+ ["git", "fetch", "--quiet", *(["--unshallow"] if shallow else []),
+ *([f"--filter={fetch_filter}"] if fetch_filter else []),
+ "--no-tags", "origin", "refs/tags/v*:refs/tags/v*", *extra_refspecs],
cwd=str(repo_root), check=True, capture_output=True, text=True,
encoding="utf-8", errors="replace", timeout=900, **run_kwargs,
)
return shallow
-# ---- Partial-clone fetch crash (git pack-objects BUG) ---------------------------
-#
-# On a partial clone (``clone --filter=tree:0``), git's promisor fetch runs index-pack
-# with ``--promisor``, whose repack_local_links() feeds pack-objects
-# ``--exclude-promisor-objects-best-effort``; pack-objects then BUG()s (SIGABRT, "should
-# only be called on existing objects") when the link traversal hits a legitimately
-# missing promisor object. Observed with git 2.53.0 / 2.54.0 (#124272): EVERY
-# ``git fetch`` dies, taking the ``update``/``check`` flows of this CLI with it. The
-# crash is deterministic per attempt and one fetch with the promisor machinery
-# disabled clears the state (the reporter's verified workaround), so the fetch paths
-# here retry once with that override instead of leaving the install stuck.
-
-_PACK_OBJECTS_CRASH_MARKERS = (
- "BUG: builtin/pack-objects.c",
- "index-pack failed",
-)
-# The BUG() assertion is the crash's fingerprint; how git then reports the abort
-# differs per platform and git build. POSIX builds emit "pack-objects died of
-# signal 6"; Windows builds (Git for Windows 2.54, #124293 field evidence)
-# instead print a second fatal line from the repack ("could not finish
-# pack-objects to repack local links") and no signal wording at all. Either
-# terminator of the same BUG() counts — match the fingerprint plus one of them.
+# git 2.53+ promisor fetches run index-pack --promisor, whose repack_local_links() BUG()s in
+# pack-objects (should_include_obj) when a local non-promisor object leads to a promisor-missing
+# one (#124272). The state is left behind by the repo, so every fetch dies the same way; one fetch
+# with the promisor machinery disabled gets past it. POSIX builds end with "died of signal 6",
+# Windows builds with "could not finish pack-objects to repack local links".
+_PACK_OBJECTS_CRASH_MARKERS = ("BUG: builtin/pack-objects.c", "index-pack failed")
_PACK_OBJECTS_CRASH_TERMINATORS = (
"pack-objects died of signal 6",
"could not finish pack-objects to repack local links",
diff --git a/hermes_cli/update_cmd.py b/hermes_cli/update_cmd.py
index 99896df3782..8a1b7206372 100644
--- a/hermes_cli/update_cmd.py
+++ b/hermes_cli/update_cmd.py
@@ -268,38 +268,24 @@ def _git_run(git_cmd, args, cwd=None, *, check=False, network=False):
# fetch writes to tmp_pack_* and only renames on success. Report as a failed run
# so every caller's existing stderr path prints one clear line.
result = subprocess.CompletedProcess(
- exc.cmd,
- 124,
- stdout="",
- stderr=f"git {args[0]} was still running after the {NETWORK_GIT_TIMEOUT_SECONDS}s network limit"
- f" (slow transfer, not a dead remote — a larger fetch may need `hermes update` again or a manual `git fetch`)",
- )
+ exc.cmd, 124, stdout="",
+ stderr=f"git {args[0]} timed out after {NETWORK_GIT_TIMEOUT_SECONDS}s (a stalled remote, or a transfer too large for the limit)")
if check:
raise subprocess.CalledProcessError(124, exc.cmd, output="", stderr=result.stderr) from exc
return result
def _heal_stale_shallow_checkout(repo_root: Path, branch: str) -> None:
- """Unshallow a stale installer checkout before the bounded fetch (#123254).
-
- Non-fatal by design: a server or proxy that rejects the unshallow/filter
- args leaves the checkout as it was, and the update proceeds with the same
- fetch (and the same 300s cap) as before — the heal can only widen the set
- of installs that can update.
- """
+ """Unshallow a shallow checkout before the bounded fetch (#123254). Non-fatal: on failure the
+ update proceeds with the fetch it always ran."""
from hermes_cli.gitlock import heal_shallow_history
try:
if heal_shallow_history(repo_root, branch, **_no_prompt_git_kwargs()):
- print(" ✓ Fetched full commit history (shallow checkout healed)")
+ print(" ✓ Fetched the commit history this shallow checkout was missing")
except (OSError, subprocess.SubprocessError) as exc:
- detail = (getattr(exc, "stderr", None) or str(exc)).strip().splitlines()[
- -1:
- ] or [type(exc).__name__]
- print(
- f" ⚠ Could not heal the shallow checkout before fetching ({detail[0]}); "
- "a very stale install may still time out"
- )
+ detail = (getattr(exc, "stderr", None) or str(exc)).strip().splitlines()[-1:] or [type(exc).__name__]
+ print(f" ⚠ Could not fetch the missing commit history ({detail[0]}); a very stale install may time out")
def _capture_head_sha(git_cmd, cwd) -> str | None:
@@ -1445,9 +1431,9 @@ def _cmd_update_impl(args, gateway_mode: bool):
# runs and failed restores preserve the stash but nothing ever mentioned it again.
_m()._warn_orphaned_update_autostashes(git_cmd, _m().PROJECT_ROOT)
- # Heal a stale shallow checkout first: the bounded fetch below cannot
- # finish on one (#123254), and the old post-update heal never got the
- # chance to run because the fetch itself never succeeded.
+ # A shallow checkout's plain fetch drags in ~the whole history and cannot finish inside
+ # the network cap (#123254); its grafts also make merge-base report orphan divergence
+ # (#123346, #124645). Unshallow it (commits only) first.
_heal_stale_shallow_checkout(_m().PROJECT_ROOT, branch)
print("→ Fetching updates...")
diff --git a/hermes_cli/update_cmd_git.py b/hermes_cli/update_cmd_git.py
index b6f29a46e8f..eddb579c7cd 100644
--- a/hermes_cli/update_cmd_git.py
+++ b/hermes_cli/update_cmd_git.py
@@ -407,15 +407,6 @@ _FETCH_FAILURE_RULES = (
(lambda s: "Permission denied (publickey)" in s or "Host key verification failed" in s,
"✗ SSH authentication failed — check your SSH key is added to GitHub, or switch"
" `origin` to HTTPS: `git remote set-url origin https://github.com/NousResearch/hermes-agent.git`."),
- # A wall-clock timeout kill says nothing about the transport: the fetch was
- # likely still transferring when the cap hit (#123254) — a huge pack on a
- # slow link, not a dead remote, and the install usually needs the shallow
- # heal (or one manual fetch) rather than network debugging.
- (lambda s: "network limit" in s,
- "✗ The fetch exceeded the update time limit while still transferring — this is a"
- " slow/large fetch, not a broken connection. A very stale shallow install can hit"
- " this repeatedly; re-running `hermes update` (which now heals the shallow history"
- " first) or one manual `git fetch origin` usually gets past it."),
)