Skip to content

The agent that grows with you

fix(update): bound failed source sync retries

KoNit-Kb49f77a19383
diff --git a/hermes_cli/venv_sync.py b/hermes_cli/venv_sync.py
index 6ae56627e90..d5c4487a213 100644
--- a/hermes_cli/venv_sync.py
+++ b/hermes_cli/venv_sync.py
@@ -510,7 +510,16 @@ def _finish_source_update(root: Path, *, current: bool, pending: Path) -> None:
completed = _tree_matches_completed_stamp(root)
# ponytail: commit-only match; a product dir deleted by hand is rebuilt on demand
# by its own entry point (the TUI/web freshness gates), not here.
- _sync_source_dependencies(root, arm=not completed)
+ try:
+ _sync_source_dependencies(root, arm=not completed)
+ except Exception:
+ # The pending marker is armed before this sync. A sync failure is
+ # therefore an automatic completion failure too: without recording
+ # it, every Desktop relaunch bypasses the retry backoff and starts
+ # the same expensive repair again.
+ if not completed:
+ _record_completion_attempt(root, failed=True)
+ raise
if completed:
clear_completion(root)
return
diff --git a/tests/hermes_cli/test_update_launch_completion.py b/tests/hermes_cli/test_update_launch_completion.py
index 80a96c3a4f2..db0d6c92dda 100644
--- a/tests/hermes_cli/test_update_launch_completion.py
+++ b/tests/hermes_cli/test_update_launch_completion.py
@@ -349,6 +349,21 @@ def test_failed_launch_keeps_previous_completion_and_retries(tmp_path, monkeypat
assert not (root / ".update-incomplete").exists()
+def test_failed_dependency_sync_counts_toward_completion_retry_limit(tmp_path, monkeypatch):
+ """A failure before the completion child still leaves an armed tail to bound (#139952)."""
+ import pm
+
+ root = _self_checkout(tmp_path, monkeypatch)
+ monkeypatch.setattr(pm, "venv_is_current", lambda **kw: False)
+ monkeypatch.setattr(pm, "sync_venv", lambda *args, **kwargs: (_ for _ in ()).throw(RuntimeError("sync failed")))
+
+ with pytest.raises(RuntimeError, match="sync failed"):
+ venv_sync.prepare_launch(root, [])
+
+ assert venv_sync.completion_pending_path(root).is_file()
+ assert venv_sync._completion_attempts_path(root).read_text(encoding="utf-8").strip() == "1"
+
+
def test_blessed_legacy_install_is_adopted_before_sync(tmp_path, monkeypatch, completion_tail):
import pm
from hermes_cli import _launchers