The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): keep git's own lazy-fetch pack fold on in a partial clone
teknium135eacd248a1b
diff --git a/hermes_cli/gitlock.py b/hermes_cli/gitlock.pyindex fb0874cb4ad..00ec3143c80 100644--- a/hermes_cli/gitlock.py+++ b/hermes_cli/gitlock.py@@ -141,23 +141,25 @@ def mark_unmarked_packs_promisor(repo_root: Path) -> int:# write over commits it has not seen yet needs their trees: one lazy fetch (and one pack) per commit,# and each lazy fetch spawns ``git maintenance`` again, which is the unbounded loop of #127711. gc,# ``maintenance run --task=commit-graph`` and ``fetch.writeCommitGraph`` all write one (git-# 2.50.1, 2.53.0 and 2.55.0 alike). So a promisor checkout never writes the graph. ``gc.auto`` stays-# at its default on purpose: ``gc --auto`` is how consolidate_lazy_fetch_packs folds the lazy-fetch-# packs, and ``gc.auto=0`` turns that into a no-op.+# 2.50.1, 2.53.0 and 2.55.0 alike). So a promisor checkout never writes the graph. Automatic+# maintenance itself stays on: on git <= 2.53 its post-fetch ``gc --auto`` is what keeps the+# lazy-fetch packs folded between updates. ``gc.auto`` stays at its default for the same reason+# (``gc.auto=0`` turns consolidate_lazy_fetch_packs into a no-op)._TREE0_MAINTENANCE_OFF = (- ("maintenance.auto", "false"),+ ("maintenance.commit-graph.enabled", "false"),("gc.writeCommitGraph", "false"),("fetch.writeCommitGraph", "false"),)def disable_tree0_auto_maintenance(repo_root: Path) -> None:- """Keep git from writing a commit-graph or running automatic maintenance in a partial clone.+ """Keep git from writing a commit-graph in a partial clone, from gc, fetch or maintenance.Idempotent (a value already in place is not rewritten, so concurrent git never meets a configlock from this) and never raises: a read-only config must not turn fetch recovery into atraceback, matching mark_unmarked_packs_promisor above."""+ _restore_auto_maintenance(repo_root)for key, value in _TREE0_MAINTENANCE_OFF:try:current = subprocess.run(@@ -179,6 +181,23 @@ def disable_tree0_auto_maintenance(repo_root: Path) -> None:logger.warning("Could not set %s=%s in %s", key, value, repo_root)+def _restore_auto_maintenance(repo_root: Path) -> None:+ """Undo the ``maintenance.auto=false`` an earlier cut of _TREE0_MAINTENANCE_OFF persisted.++ It also switched off git's own post-fetch fold (git <= 2.53), so packs piled up until the next+ update. The install checkout is Hermes-owned; only the exact value it wrote is removed.+ """+ try:+ if _git_stdout_lines(repo_root, ["config", "--local", "--get", "maintenance.auto"]) == ["false"]:+ subprocess.run(+ ["git", "config", "--local", "--unset", "maintenance.auto"],+ cwd=str(repo_root), check=True, capture_output=True, timeout=30,+ creationflags=windows_hide_flags(),+ )+ except Exception:+ logger.warning("Could not restore maintenance.auto in %s", repo_root)++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.diff --git a/scripts/install.ps1 b/scripts/install.ps1index 7a45a524f9b..1f0f20f1dd9 100644--- a/scripts/install.ps1+++ b/scripts/install.ps1@@ -737,7 +737,7 @@ function Stage-Prerequisites {# data that lazy-fetches the trees of every unseen commit, in a loop (#127711).# gc.auto stays on: `hermes update` folds lazy-fetch packs with `gc --auto`.function Disable-TreelessGraphWrites([string]$Dir) {- foreach ($key in 'maintenance.auto', 'gc.writeCommitGraph', 'fetch.writeCommitGraph') {+ foreach ($key in 'maintenance.commit-graph.enabled', 'gc.writeCommitGraph', 'fetch.writeCommitGraph') {Invoke-Native { git -C $Dir config $key false } | Out-Nullif ($LASTEXITCODE) { Write-Warn "could not set $key in $Dir" }}diff --git a/scripts/install.sh b/scripts/install.shindex a210d8130a5..29c0617a5ea 100755--- a/scripts/install.sh+++ b/scripts/install.sh@@ -474,8 +474,8 @@ stage_repository() {fidone# Existing treeless checkout: same commit-graph lazy-fetch loop guard (#127711).- git -C "$INSTALL_DIR" config maintenance.auto false \- || log_warn "could not disable maintenance.auto in $INSTALL_DIR"+ git -C "$INSTALL_DIR" config maintenance.commit-graph.enabled false \+ || log_warn "could not disable maintenance.commit-graph.enabled in $INSTALL_DIR"git -C "$INSTALL_DIR" config gc.writeCommitGraph false \|| log_warn "could not disable gc.writeCommitGraph in $INSTALL_DIR"git -C "$INSTALL_DIR" config fetch.writeCommitGraph false \@@ -600,8 +600,8 @@ stage_repository() {# changed-path data that lazy-fetches the trees of every unseen commit, in a# loop (#127711). gc.auto stays on: `hermes update` folds lazy-fetch packs with# `gc --auto`.- git -C "$INSTALL_DIR" config maintenance.auto false \- || log_warn "could not disable maintenance.auto in $INSTALL_DIR"+ git -C "$INSTALL_DIR" config maintenance.commit-graph.enabled false \+ || log_warn "could not disable maintenance.commit-graph.enabled in $INSTALL_DIR"git -C "$INSTALL_DIR" config gc.writeCommitGraph false \|| log_warn "could not disable gc.writeCommitGraph in $INSTALL_DIR"git -C "$INSTALL_DIR" config fetch.writeCommitGraph false \diff --git a/tests/hermes_cli/test_gitlock.py b/tests/hermes_cli/test_gitlock.pyindex 39fb58da5ce..ed7706fa074 100644--- a/tests/hermes_cli/test_gitlock.py+++ b/tests/hermes_cli/test_gitlock.py@@ -285,6 +285,28 @@ def test_fold_does_not_lazy_fetch_the_trees_of_commits_a_bloom_graph_has_not_seeassert len(_packs(clone)) == 1+def test_maintenance_keys_leave_gits_own_fold_running(tmp_path: Path) -> None:+ """Between updates, git's post-lazy-fetch auto maintenance is what folds packs (git <= 2.53).++ The keys stop the commit-graph write without switching that fold off: ``maintenance.auto=false``+ let the packs pile up until the next ``hermes update``. Compared against a stock-config clone+ because newer git (2.55) does not fold lazy-fetch packs on its own at all.+ """+ def lazy_packs(name: str, keys: bool) -> int:+ (tmp_path / name).mkdir()+ _seed, _up, clone = _blobless_clone(tmp_path / name, 3)+ for key, value in (("gc.autoPackLimit", "2"), ("gc.autoDetach", "false"), ("maintenance.autoDetach", "false")):+ _run_git("config", key, value, cwd=clone) # git's own auto gc, in the foreground+ if keys:+ _run_git("config", "maintenance.auto", "false", cwd=clone) # what the first cut persisted+ disable_tree0_auto_maintenance(clone)+ for path in ("d0/f.txt", "d1/f.txt", "d2/f.txt"):+ _run_git("cat-file", "-p", _run_git("rev-parse", f"HEAD:{path}", cwd=clone), cwd=clone)+ return len(_packs(clone))++ assert lazy_packs("keys", keys=True) <= lazy_packs("stock", keys=False)++def test_non_partial_checkout_is_left_alone(repo: Path) -> None:assert consolidate_lazy_fetch_packs(repo) == 0keys = subprocess.run(["git", "config", "--local", "--get-regexp", "maintenance|writecommitgraph"], cwd=repo,diff --git a/website/docs/getting-started/updating.md b/website/docs/getting-started/updating.mdindex 68fb306940e..7a552b46f6a 100644--- a/website/docs/getting-started/updating.md+++ b/website/docs/getting-started/updating.md@@ -212,9 +212,9 @@ git -C $repo rev-list --objects --missing=error --all | Out-Null; $LASTEXITCODEThe installer's checkout is a partial clone: git downloads trees and blobs on demand, and eachon-demand download is written as its own small pack. `hermes update` and `hermes update --check`fold them back together with `git gc --auto` (git's own `gc.autoPackLimit`, 50 by default), so a-healthy checkout pays a no-op. They also set `maintenance.auto`, `gc.writeCommitGraph` and-`fetch.writeCommitGraph` to `false` in that checkout, because a commit-graph write over commits the-graph has not seen yet downloads every one of their trees. Leave those settings alone, and leave+healthy checkout pays a no-op. They also set `maintenance.commit-graph.enabled`,+`gc.writeCommitGraph` and `fetch.writeCommitGraph` to `false` in that checkout, because a+commit-graph write over commits the graph has not seen yet downloads every one of their trees. Leave those settings alone, and leave`gc.auto` at its default: `gc.auto=0` stops the fold. The first fold on a checkout that haspiled up thousands of packs is a full repack and can take several minutes; the update says sobefore it starts, and if the fold runs past 20 minutes it stops and prints the command below.