Skip to content

The agent that grows with you

fix(update): self-heal git pack-objects crash on partial-clone fetches

Yuan Lifc6144e3c175
diff --git a/hermes_cli/gitlock.py b/hermes_cli/gitlock.py
index dc6687d1b9c..3c42c5402e6 100644
--- a/hermes_cli/gitlock.py
+++ b/hermes_cli/gitlock.py
@@ -437,3 +437,43 @@ def fetch_full_commit_graph(repo_root: Path, **run_kwargs) -> bool:
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",
+ "pack-objects died of signal 6",
+ "index-pack failed",
+)
+
+
+def is_partial_clone_pack_objects_crash(stderr: str) -> bool:
+ """True when a fetch failure is the git 2.53/2.54 partial-clone pack-objects BUG (#124272)."""
+ text = stderr or ""
+ return all(marker in text for marker in _PACK_OBJECTS_CRASH_MARKERS)
+
+
+def fetch_with_partial_clone_recovery(runner: Callable[..., subprocess.CompletedProcess],
+ git_cmd: List[str], fetch_args: List[str]) -> subprocess.CompletedProcess:
+ """Run a fetch, retrying once with the promisor machinery disabled on the pack-objects BUG.
+
+ ``runner(git_cmd, args) -> CompletedProcess`` and ``git_cmd + fetch_args`` is the plain
+ fetch argv. The retry inserts ``-c remote.origin.promisor=`` (per-invocation only — the
+ user's filter choice stays in their config) and its result is returned whatever its
+ exit code, so the caller keeps its normal failure handling.
+ """
+ result = runner(git_cmd, fetch_args)
+ if result.returncode == 0 or not is_partial_clone_pack_objects_crash(getattr(result, "stderr", "") or ""):
+ return result
+ logger.info("pack-objects crash on a partial clone; retrying the fetch with promisor disabled")
+ return runner(git_cmd + ["-c", "remote.origin.promisor="], fetch_args)
diff --git a/hermes_cli/update_cmd.py b/hermes_cli/update_cmd.py
index 88c69bd75a5..f5e872694b2 100644
--- a/hermes_cli/update_cmd.py
+++ b/hermes_cli/update_cmd.py
@@ -1420,11 +1420,18 @@ def _cmd_update_impl(args, gateway_mode: bool):
print("→ Fetching updates...")
if release_sha:
- fetch_result = _git_run(git_cmd, ["fetch", "--no-tags", "origin", target_ref], network=True)
+ fetch_args = ["fetch", "--no-tags", "origin", target_ref]
else:
- fetch_result = _git_run(
- git_cmd, ["fetch", "origin", _check.tracking_refspec("origin", branch)], network=True)
+ fetch_args = ["fetch", "origin", _check.tracking_refspec("origin", branch)]
+ from hermes_cli.gitlock import fetch_with_partial_clone_recovery, is_partial_clone_pack_objects_crash
+ # One retry with the promisor machinery disabled clears the git 2.53/2.54
+ # partial-clone pack-objects crash (#124272).
+ fetch_result = fetch_with_partial_clone_recovery(
+ lambda gc, a: _git_run(gc, a, network=True), git_cmd, fetch_args)
if fetch_result.returncode != 0:
+ if is_partial_clone_pack_objects_crash(fetch_result.stderr or ""):
+ print("✗ git still crashed after the partial-clone retry. Heal the checkout once manually:")
+ print(" git -c remote.origin.promisor= fetch origin && git fetch origin")
_print_fetch_failure(fetch_result.stderr)
_m()._resume_windows_gateways_after_update(_windows_gateway_resume)
sys.exit(1)
diff --git a/hermes_cli/update_cmd_check.py b/hermes_cli/update_cmd_check.py
index c541e03f32c..2bebf50cc07 100644
--- a/hermes_cli/update_cmd_check.py
+++ b/hermes_cli/update_cmd_check.py
@@ -101,7 +101,13 @@ def fetch_compare_branch(git_cmd: list[str], root: Path, branch: str, depth_args
fetch_result = _fetch(git_cmd, root, depth_args, "upstream", branch)
if fetch_result.returncode == 0:
return fetch_result, f"upstream/{branch}"
- return _fetch(git_cmd, root, depth_args, "origin", branch), f"origin/{branch}"
+ from hermes_cli.gitlock import fetch_with_partial_clone_recovery
+ # One retry with the promisor machinery disabled clears the git 2.53/2.54
+ # partial-clone pack-objects crash (#124272).
+ print("→ Fetching from origin...")
+ return fetch_with_partial_clone_recovery(
+ lambda gc, a: _git(gc, root, a, **_uc()._no_prompt_git_kwargs()),
+ git_cmd, ["fetch", *depth_args, "origin", tracking_refspec("origin", branch)]), f"origin/{branch}"
def repair_shallow_grafts(root: Path) -> None:
diff --git a/tests/hermes_cli/test_gitlock.py b/tests/hermes_cli/test_gitlock.py
index 86147756fec..06fc73edbf4 100644
--- a/tests/hermes_cli/test_gitlock.py
+++ b/tests/hermes_cli/test_gitlock.py
@@ -113,3 +113,76 @@ def test_clear_noop_on_non_repo(tmp_path: Path) -> None:
def test_clear_noop_with_no_locks(repo: Path) -> None:
assert clear_stale_git_locks(repo) == []
+
+
+# ---- Partial-clone pack-objects fetch crash (#124272) ----
+#
+# On a partial clone (tree:0 filter) git 2.53/2.54 crashes EVERY fetch: index-pack's
+# repack_local_links feeds pack-objects --exclude-promisor-objects-best-effort and
+# pack-objects BUG()s (SIGABRT) on a legitimately missing promisor object. The crash is
+# deterministic, so the recovery is one retry with the promisor machinery disabled (the
+# reporter's verified workaround). These pin the recognizer against look-alike failures
+# and the retry contract: retry exactly once, only on this crash, args untouched.
+
+from subprocess import CompletedProcess # noqa: E402
+
+from hermes_cli.gitlock import ( # noqa: E402
+ fetch_with_partial_clone_recovery,
+ is_partial_clone_pack_objects_crash,
+)
+
+_CRASH_STDERR = (
+ "remote: Enumerating objects: 12, done.\n"
+ "BUG: builtin/pack-objects.c:4842: should_include_obj should only be called on existing objects\n"
+ "error: pack-objects died of signal 6\n"
+ "fatal: could not finish pack-objects to repack local links\n"
+ "fatal: index-pack failed\n"
+)
+
+
+def test_crash_recognizer_matches_reported_stderr():
+ assert is_partial_clone_pack_objects_crash(_CRASH_STDERR)
+
+
+def test_crash_recognizer_rejects_unrelated_failures():
+ assert not is_partial_clone_pack_objects_crash(
+ "fatal: Authentication failed for 'https://github.com/example.git'")
+ assert not is_partial_clone_pack_objects_crash(
+ "error: pack-objects died of signal 6") # one marker alone is not the crash
+ assert not is_partial_clone_pack_objects_crash("")
+ assert not is_partial_clone_pack_objects_crash(None)
+
+
+def test_recovery_retries_once_with_promisor_disabled():
+ calls = []
+
+ def runner(git_cmd, args):
+ calls.append((list(git_cmd), list(args)))
+ if len(calls) == 1:
+ return CompletedProcess(git_cmd + args, 1, stdout="", stderr=_CRASH_STDERR)
+ return CompletedProcess(git_cmd + args, 0, stdout="", stderr="")
+
+ result = fetch_with_partial_clone_recovery(runner, ["git"], ["fetch", "origin", "main"])
+
+ assert [args for _, args in calls] == [["fetch", "origin", "main"]] * 2
+ assert calls[1][0] == ["git", "-c", "remote.origin.promisor="]
+ assert result.returncode == 0
+
+
+def test_recovery_passes_through_success_and_unrelated_failure():
+ calls = []
+
+ def failing_runner(git_cmd, args):
+ calls.append((list(git_cmd), list(args)))
+ return CompletedProcess(git_cmd + args, 1, stdout="", stderr="fatal: Permission denied (publickey)")
+
+ result = fetch_with_partial_clone_recovery(failing_runner, ["git"], ["fetch", "origin", "main"])
+ assert result.returncode == 1
+ assert calls == [(["git"], ["fetch", "origin", "main"])]
+
+ calls.clear()
+ ok_runner = lambda gc, a: (calls.append((list(gc), list(a))),
+ CompletedProcess(gc + a, 0, stdout="", stderr=""))[-1]
+ result = fetch_with_partial_clone_recovery(ok_runner, ["git"], ["fetch", "--no-tags", "origin", "abc123"])
+ assert result.returncode == 0
+ assert calls == [(["git"], ["fetch", "--no-tags", "origin", "abc123"])]