Skip to content

The agent that grows with you

fix(update): refresh the install checkout's commit-graph after each update

Teknium0c8125188672
diff --git a/hermes_cli/update_cmd_maint.py b/hermes_cli/update_cmd_maint.py
index 49499162c5b..73c61932eab 100644
--- a/hermes_cli/update_cmd_maint.py
+++ b/hermes_cli/update_cmd_maint.py
@@ -1028,6 +1028,10 @@ def _run_post_update_maintenance(
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 refresh release history ({detail[0]}); the version label may be stale or unknown until the next update")
+ # Keeps every later version lookup off a full history walk; detached, so it never delays this run.
+ with _best_effort('Commit-graph refresh failed to start: %s'):
+ from hermes_cli.worktree_ops import spawn_commit_graph_refresh
+ spawn_commit_graph_refresh(Path(_m().PROJECT_ROOT))
# Seed the model-catalog cache from the checkout instead of a bot-gated, flaky fetch.
with _best_effort('Model catalog seed during update failed: %s'):
diff --git a/hermes_cli/worktree_ops.py b/hermes_cli/worktree_ops.py
index 1099af2ac7b..52ca623a2bf 100644
--- a/hermes_cli/worktree_ops.py
+++ b/hermes_cli/worktree_ops.py
@@ -216,6 +216,33 @@ def _refresh_commit_graph(repo_root: str) -> None:
env={**noninteractive_git_env(), **NO_LAZY_FETCH_ENV})
+def _claim_commit_graph_refresh(git_dir: Path) -> bool:
+ return _commit_graph_stale(git_dir) and _claim_repack_slot(git_dir, _COMMIT_GRAPH_LOCK)
+
+
+_REFRESH_CHILD = ("import sys; sys.path.insert(0, sys.argv[1]); "
+ "from hermes_cli.worktree_ops import _refresh_commit_graph; _refresh_commit_graph(sys.argv[1])")
+
+
+def spawn_commit_graph_refresh(repo_root: Path) -> bool:
+ """Start the bounded commit-graph refresh in a detached child when it is due; never waits.
+
+ ``hermes update`` is the one regular git pass an install checkout gets (``hermes -w`` is
+ rarely launched from it), so without this its version lookups never get a graph. Detached
+ because the write takes seconds and must neither delay the update nor die with it; the child
+ is the same runner the ``-w`` pass uses (niced, process tree killed at the timeout).
+ """
+ from hermes_cli._subprocess_compat import windows_detach_popen_kwargs
+
+ git_dir = Path(repo_root) / ".git"
+ if not (git_dir / "objects").is_dir() or not _claim_commit_graph_refresh(git_dir):
+ return False
+ subprocess.Popen([sys.executable, "-c", _REFRESH_CHILD, str(repo_root)], cwd=str(repo_root),
+ stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
+ close_fds=True, **windows_detach_popen_kwargs())
+ return True
+
+
def _maintain_pack_health(repo_root: str) -> None:
"""Repack on pack sprawl and keep the commit-graph fresh (background thread, fail-soft).
@@ -236,7 +263,7 @@ def _maintain_pack_health(repo_root: str) -> None:
# Repacking can strand now-duplicated admin files; prune on the same pass.
_git(["worktree", "prune"], repo_root, timeout=60, check=False,
stdin=subprocess.DEVNULL, env=noninteractive_git_env())
- if _commit_graph_stale(git_dir) and _claim_repack_slot(git_dir, _COMMIT_GRAPH_LOCK):
+ if _claim_commit_graph_refresh(git_dir):
_refresh_commit_graph(repo_root)
except Exception as e:
logger.debug("pack maintenance skipped: %s", e)
diff --git a/tests/hermes_cli/test_update_post_commit_followups.py b/tests/hermes_cli/test_update_post_commit_followups.py
index 0d0d339844b..ab2a19db578 100644
--- a/tests/hermes_cli/test_update_post_commit_followups.py
+++ b/tests/hermes_cli/test_update_post_commit_followups.py
@@ -141,6 +141,12 @@ def test_failed_config_migration_is_owed_and_later_maintenance_runs(tmp_path, mo
monkeypatch.setattr("hermes_cli.gitlock.fetch_full_commit_graph", lambda *a, **kw: False)
monkeypatch.setattr("hermes_cli.model_catalog.seed_cache_from_checkout", lambda root: False)
+ def broken_graph_refresh(root):
+ calls.append(("commit_graph", root))
+ raise OSError("fork failed") # a refresh that cannot start must not fail or owe anything
+
+ monkeypatch.setattr("hermes_cli.worktree_ops.spawn_commit_graph_refresh", broken_graph_refresh)
+
def broken_migration(**kwargs):
raise SystemExit(1) # a migration helper that exits must not fail the committed update
@@ -154,6 +160,7 @@ def test_failed_config_migration_is_owed_and_later_maintenance_runs(tmp_path, mo
had_desktop_app_before_update=False, pre_update_version=None, followups=owed) is True
assert [step for step, _ in owed] == ["config_migration"]
assert calls[0] == "repair_windows_home_acl"
+ assert ("commit_graph", update_cmd._m().PROJECT_ROOT) in calls
assert calls[-2:] == ["verdict", "notices"]
assert "⚠ Update follow-up 'config_migration'" in capsys.readouterr().out
update_receipt.finalize_update_receipt("success")
diff --git a/website/docs/getting-started/updating.md b/website/docs/getting-started/updating.md
index 8c67fbc9a20..4b7a767bb81 100644
--- a/website/docs/getting-started/updating.md
+++ b/website/docs/getting-started/updating.md
@@ -314,9 +314,11 @@ downloads every one of their trees. Leave those settings alone, and leave `gc.au
default so git's own automatic gc can still fold packs.
Hermes keeps the commit-graph current itself, because without one every version lookup walks the
-whole history: a `hermes -w` launch updates a missing or day-old graph in the background with
+whole history: each `hermes update` (after the new code is in place) and each `hermes -w` launch
+update a missing or day-old graph in the background, at most once every 6 hours, with
`git commit-graph write --reachable --split --no-changed-paths`, which reads commits only and never
-downloads a tree. A `commit-graph.lock` or `multi-pack-index.lock` that a killed git left behind is
+downloads a tree. The update does not wait for it, and a write still running after 10 minutes is
+stopped. A `commit-graph.lock` or `multi-pack-index.lock` that a killed git left behind is
removed by the same stale-lock sweep as `index.lock` once it is 10 minutes old and no git is running.
Each `hermes update` also spends at most 60 seconds cleaning those packs up, picking up where the