Skip to content

The agent that grows with you

fix(update): mark unmarked packs instead of the inert promisor retry (#124272)

kshitijk4poor282ad01cb598
diff --git a/hermes_cli/gitlock.py b/hermes_cli/gitlock.py
index 313d2feb80e..a69a53b9ea7 100644
--- a/hermes_cli/gitlock.py
+++ b/hermes_cli/gitlock.py
@@ -91,13 +91,42 @@ def clear_stale_git_locks(repo_root: Path, *, min_age_seconds: Optional[int] = N
)
+def _pack_dir(repo_root: Path) -> Path:
+ git_dir = Path(repo_root) / ".git"
+ return (git_dir if git_dir.is_dir() else Path(repo_root)) / "objects" / "pack"
+
+
+def mark_unmarked_packs_promisor(repo_root: Path) -> int:
+ """Give every pack without a ``.promisor`` marker one; returns how many were marked.
+
+ git 2.53+ ``index-pack --promisor`` hands objects that sit outside promisor packs to
+ pack-objects, which BUG()s on the missing objects they lead to (#124272). Unmarked packs in a
+ partial clone come from a filtered fetch that turned a full or depth-limited clone partial (the
+ old packs keep no marker) and from checkouts that lost their markers. The marker only tells git
+ that objects those packs link to may be fetched on demand; nothing is rewritten or deleted.
+ """
+ marked = 0
+ for pack in _pack_dir(repo_root).glob("pack-*.pack"):
+ marker = pack.with_suffix(".promisor")
+ try:
+ with open(marker, "xb"):
+ marked += 1
+ except FileExistsError:
+ pass
+ except OSError as exc:
+ # A read-only store must not turn a fetch failure into a traceback.
+ logger.warning("Could not mark %s as a partial-clone pack: %s", pack, exc)
+ if marked:
+ logger.info("Marked %d pack(s) in %s as partial-clone packs", marked, repo_root)
+ return marked
+
+
def clear_stale_tmp_packs(repo_root: Path, *, min_age_seconds: Optional[int] = None) -> List[str]:
"""Remove aborted-transfer temp pack files; same contract as clear_stale_git_locks.
Resolves ``.git/objects/pack`` for a checkout and ``objects/pack`` for a bare repo such as
the checkpoint store — a ``git gc`` killed by a timeout strands the same debris there."""
- git_dir = Path(repo_root) / ".git"
- pack_dir = (git_dir if git_dir.is_dir() else Path(repo_root)) / "objects" / "pack"
+ pack_dir = _pack_dir(repo_root)
def _candidates():
try:
@@ -416,34 +445,39 @@ def fetch_full_commit_graph(repo_root: Path, *extra_refspecs: str, **run_kwargs)
(#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.
+ ``--depth`` fetch already has its history and stays full. The converted clone's existing packs
+ are marked as partial-clone packs, or every later fetch crashes on git 2.53+ (#124272).
+ Returns whether the checkout was unshallowed; fetch failures raise subprocess errors.
"""
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()):
+ converts = fetch_filter is None and shallow and bool(_batch_missing_parents(
+ repo_root, shallow_path.read_text(encoding="utf-8-sig").split()))
+ if converts:
fetch_filter = "tree:0"
- subprocess.run(
- ["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,
- )
+ try:
+ subprocess.run(
+ ["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,
+ )
+ finally:
+ # git writes the partial-clone config before it fetches, so a failed fetch converts too.
+ if converts:
+ mark_unmarked_packs_promisor(repo_root)
return shallow
# 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. Only the assertion itself is version-stable,
-# so that is the fingerprint; the wrapper around it is not. git <= 2.54 reports the aborted helper
-# with "index-pack failed" — POSIX builds ending with "died of signal 6", Windows builds with
-# "could not finish pack-objects to repack local links" — but the 2.55 builds that dropped that
-# string end with "fetch-pack: invalid index-pack output" (#125138), so keying the fingerprint on
-# "index-pack failed" left those builds with no retry at all: the update simply exited 1.
+# pack-objects (should_include_obj) when an object outside the promisor packs leads to a
+# promisor-missing one (#124272). The unmarked packs stay, so fetches keep dying until they are
+# marked. The assertion is the fingerprint; a terminator line confirms the helper aborted. Those
+# lines vary by build (POSIX "died of signal 6", Windows "could not finish pack-objects to repack
+# local links", git 2.55 "fetch-pack: invalid index-pack output", #125138), so a new git wording
+# needs a new terminator here.
_PACK_OBJECTS_CRASH_FINGERPRINT = "should_include_obj should only be called on existing objects"
_PACK_OBJECTS_CRASH_TERMINATORS = (
"pack-objects died of signal 6",
@@ -461,16 +495,18 @@ def is_partial_clone_pack_objects_crash(stderr: str) -> bool:
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.
+ git_cmd: List[str], fetch_args: List[str],
+ repo_root: Path) -> subprocess.CompletedProcess:
+ """Run a fetch; on the pack-objects BUG, mark the unmarked packs and retry it once.
``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.
+ fetch argv. The retry's result is returned whatever its exit code, so the caller keeps its
+ normal failure handling. (A ``-c remote.origin.promisor=`` override does not help: git
+ registers promisor remotes additively, so the repo's own ``true`` still wins.)
"""
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)
+ mark_unmarked_packs_promisor(repo_root)
+ logger.info("pack-objects crash on a partial clone; retrying the fetch")
+ return runner(git_cmd, fetch_args)
diff --git a/hermes_cli/update_cmd.py b/hermes_cli/update_cmd.py
index 382e331eba7..95fc075d43c 100644
--- a/hermes_cli/update_cmd.py
+++ b/hermes_cli/update_cmd.py
@@ -1552,14 +1552,13 @@ def _cmd_update_impl(args, gateway_mode: bool):
else:
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).
+ # Marking the unmarked packs clears the git 2.53+ 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)
+ lambda gc, a: _git_run(gc, a, network=True), git_cmd, fetch_args, _m().PROJECT_ROOT)
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("✗ git still crashed after marking this checkout's packs. See 'Fetch fails with"
+ " should_include_obj' in https://hermes-agent.nousresearch.com/docs/getting-started/updating")
_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 2bebf50cc07..31c70539169 100644
--- a/hermes_cli/update_cmd_check.py
+++ b/hermes_cli/update_cmd_check.py
@@ -102,12 +102,11 @@ def fetch_compare_branch(git_cmd: list[str], root: Path, branch: str, depth_args
if fetch_result.returncode == 0:
return fetch_result, f"upstream/{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).
+ # Marking the unmarked packs clears the git 2.53+ 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}"
+ git_cmd, ["fetch", *depth_args, "origin", tracking_refspec("origin", branch)], root), f"origin/{branch}"
def repair_shallow_grafts(root: Path) -> None:
diff --git a/hermes_cli/worktree_ops.py b/hermes_cli/worktree_ops.py
index aa34f9b6805..7c9fb9f53e2 100644
--- a/hermes_cli/worktree_ops.py
+++ b/hermes_cli/worktree_ops.py
@@ -542,15 +542,23 @@ def _deepen_shallow_repo(repo_root: str, timeout: int = 600) -> bool:
names = [r.strip() for r in remotes.splitlines() if r.strip()]
remote = "origin" if "origin" in names else names[0]
- for extra in (["--filter=blob:none"], []):
- try:
- result = _git(["fetch", remote, "--unshallow", *extra], repo_root, timeout=timeout)
- except subprocess.TimeoutExpired:
- return False
- if result.returncode == 0:
- break
- logger.debug("git fetch --unshallow%s failed: %s", " " + " ".join(extra) if extra else "",
- result.stderr.strip()[-500:])
+ try:
+ for extra in (["--filter=blob:none"], []):
+ try:
+ result = _git(["fetch", remote, "--unshallow", *extra], repo_root, timeout=timeout)
+ except subprocess.TimeoutExpired:
+ return False
+ if result.returncode == 0:
+ break
+ logger.debug("git fetch --unshallow%s failed: %s", " " + " ".join(extra) if extra else "",
+ result.stderr.strip()[-500:])
+ finally:
+ # The filtered attempt makes the clone partial (git writes the config before fetching,
+ # so even when it fails); its old packs need the marker or git 2.53+ crashes every
+ # later fetch (#124272).
+ if _git_out(["config", "--bool", "--get", f"remote.{remote}.promisor"], repo_root) == "true":
+ from hermes_cli.gitlock import mark_unmarked_packs_promisor
+ mark_unmarked_packs_promisor(Path(repo_root))
except Exception as e:
logger.debug("Deepening shallow repo failed (non-fatal): %s", e)
return False
diff --git a/tests/hermes_cli/test_gitlock.py b/tests/hermes_cli/test_gitlock.py
index 61c4685d7d2..f9cfa8174ea 100644
--- a/tests/hermes_cli/test_gitlock.py
+++ b/tests/hermes_cli/test_gitlock.py
@@ -117,12 +117,11 @@ def test_clear_noop_with_no_locks(repo: Path) -> None:
# ---- 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.
+# On a partial clone git 2.53+ crashes fetches: index-pack's repack_local_links feeds
+# pack-objects --exclude-promisor-objects-best-effort the objects outside promisor packs, and
+# pack-objects BUG()s (SIGABRT) on the missing objects they lead to. Unmarked packs keep the
+# crash coming, so the recovery marks them and retries once. 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
@@ -178,7 +177,12 @@ def test_crash_recognizer_rejects_unrelated_failures():
[_CRASH_STDERR, _CRASH_STDERR_WINDOWS, _CRASH_STDERR_GIT_255],
ids=["posix", "windows", "git-255"],
)
-def test_recovery_retries_once_with_promisor_disabled(crash_stderr):
+def test_recovery_marks_unmarked_packs_and_retries_the_same_fetch(crash_stderr, tmp_path):
+ pack_dir = tmp_path / ".git" / "objects" / "pack"
+ pack_dir.mkdir(parents=True)
+ (pack_dir / "pack-local.pack").write_bytes(b"")
+ (pack_dir / "pack-fetched.pack").write_bytes(b"")
+ (pack_dir / "pack-fetched.promisor").write_bytes(b"")
calls = []
def runner(git_cmd, args):
@@ -187,8 +191,8 @@ def test_recovery_retries_once_with_promisor_disabled(crash_stderr):
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"])
+ result = fetch_with_partial_clone_recovery(runner, ["git"], ["fetch", "origin", "main"], tmp_path)
- assert [args for _, args in calls] == [["fetch", "origin", "main"]] * 2
- assert calls[1][0] == ["git", "-c", "remote.origin.promisor="]
+ assert calls == [(["git"], ["fetch", "origin", "main"])] * 2
+ assert (pack_dir / "pack-local.promisor").exists()
assert result.returncode == 0
diff --git a/tests/hermes_cli/test_update_shallow_heal.py b/tests/hermes_cli/test_update_shallow_heal.py
index fbea204874e..93f0b753216 100644
--- a/tests/hermes_cli/test_update_shallow_heal.py
+++ b/tests/hermes_cli/test_update_shallow_heal.py
@@ -41,6 +41,10 @@ def test_depth1_clone_of_a_tagless_origin_gets_its_commit_graph(tmp_path):
assert _git(clone, "rev-list", "--count", "HEAD").stdout.strip() == "3"
# History really was missing: fetched commits-only, as a tree:0 partial clone.
assert _git(clone, "config", "remote.origin.partialclonefilter").stdout.strip() == "tree:0"
+ # The clone's own depth-1 pack is a partial-clone pack now too, or git 2.53+ crashes every
+ # later fetch in pack-objects (#124272).
+ packs = list((clone / ".git" / "objects" / "pack").glob("pack-*.pack"))
+ assert packs and all(p.with_suffix(".promisor").exists() for p in packs)
def test_depth_prefetch_on_a_full_clone_restores_ancestry_and_keeps_it_full(tmp_path):
diff --git a/tests/hermes_cli/test_worktree.py b/tests/hermes_cli/test_worktree.py
index 07468c3350f..89f42b291b5 100644
--- a/tests/hermes_cli/test_worktree.py
+++ b/tests/hermes_cli/test_worktree.py
@@ -564,11 +564,17 @@ class TestShallowCloneDeepening:
def test_deepen_connects_history_and_clears_false_unpushed(self, tmp_path):
import cli
- _, clone, wt = self._stuck_worktree(tmp_path)
+ up, clone, wt = self._stuck_worktree(tmp_path)
assert cli._worktree_has_unpushed_commits(str(wt))
+ self._run(["git", "config", "uploadpack.allowFilter", "true"], up)
assert worktree_ops._deepen_shallow_repo(str(clone)) is True
assert not cli._repo_is_shallow(str(clone))
+ # The blobless unshallow made the clone partial; its old packs must carry the partial-clone
+ # marker, or git 2.53+ crashes every later fetch (#124272).
+ assert self._run(["git", "config", "--get", "remote.origin.promisor"], clone).stdout.strip() == "true"
+ packs = list((clone / ".git" / "objects" / "pack").glob("pack-*.pack"))
+ assert packs and all(p.with_suffix(".promisor").exists() for p in packs)
assert not cli._worktree_has_unpushed_commits(str(wt)), (
"after deepening, the worktree's HEAD is an ancestor of "
"origin/main and must no longer count as unpushed"