Skip to content

The agent that grows with you

fix: a failed service pause keeps its record on typed rollback failures

Teknium4c77e8954b7d
diff --git a/hermes_cli/update_cmd_windows.py b/hermes_cli/update_cmd_windows.py
index b9daec5f256..5f7388b11a4 100644
--- a/hermes_cli/update_cmd_windows.py
+++ b/hermes_cli/update_cmd_windows.py
@@ -811,6 +811,16 @@ def _windows_cold_start_plan() -> dict | None:
return None
+class ServicePauseFailed(RuntimeError):
+ """A gateway service could not be stopped; ``rollback_failures`` lists what the in-line
+ rollback could not restart. Empty = everything stopped was restarted, so the pause is void;
+ otherwise its record must stay, since gateways are still down."""
+
+ def __init__(self, detail: str, rollback_failures: list[str]):
+ super().__init__(detail)
+ self.rollback_failures = rollback_failures
+
+
def _pause_windows_gateway_services(service_gateways, token: dict, profiles: dict, unmapped: list) -> dict:
"""Stop each SCM gateway service, recording them on *token*; roll everything back on failure.
@@ -848,7 +858,7 @@ def _pause_windows_gateway_services(service_gateways, token: dict, profiles: dic
detail = f"Could not stop Windows gateway service {current_service_name or 'unknown'}: {exc}"
if rollback_failures:
detail += "; rollback failures: " + "; ".join(rollback_failures)
- raise RuntimeError(detail) from exc
+ raise ServicePauseFailed(detail, rollback_failures) from exc
def _owned_gateway_pids(pids, *, keep=(), quiet: bool = True) -> list[int]:
@@ -993,8 +1003,8 @@ def _pause_windows_gateways_for_update() -> dict | None:
_record_attested_cold_start_profiles(token, running_profiles)
try:
token = _pause_windows_gateway_services(service_gateways, token, profiles, unmapped)
- except RuntimeError as exc:
- if "rollback failures" not in str(exc): # everything stopped was restarted in-line
+ except ServicePauseFailed as exc:
+ if not exc.rollback_failures: # everything stopped was restarted in-line
pause_record.abandon_pause(intended, adopted)
raise
return pause_record.finish_pause(token, intended, adopted)
diff --git a/tests/hermes_cli/test_update_pause_service_rollback.py b/tests/hermes_cli/test_update_pause_service_rollback.py
new file mode 100644
index 00000000000..b3b89908e56
--- /dev/null
+++ b/tests/hermes_cli/test_update_pause_service_rollback.py
@@ -0,0 +1,51 @@
+"""A failed service pause keeps its record exactly when its rollback left gateways down.
+
+``_pause_windows_gateways_for_update`` decides whether to abandon the durable pause record from the
+service-pause failure. That decision is read from a typed ``rollback_failures`` list, never from the
+error message's wording: a reworded message must not delete the record while gateways stay stopped.
+
+Real pause producer and durable record; seams are the Windows-only discovery, the SCM stop/restore
+calls and the ordinary-gateway stop (nothing is signalled).
+"""
+
+from __future__ import annotations
+
+import os
+from types import SimpleNamespace
+
+import pytest
+
+from hermes_cli import gateway, update_cmd, update_cmd_windows
+from hermes_cli import update_pause_record as pause_record
+from hermes_cli.update_cmd_windows import ServicePauseFailed, _pause_windows_gateways_for_update
+
+
[email protected]("restore_fails", [False, True])
+def test_the_pause_record_survives_exactly_when_the_service_rollback_failed(monkeypatch, restore_fails):
+ from hermes_cli import main
+ pid = os.getpid() # a live identity for the service's gateway; never signalled
+ service = SimpleNamespace(name="hermes-gw", profile="default", gateway_pid=pid, gateway_create_time=1.0,
+ service_pid=pid, service_create_time=1.0, descendant_identities=())
+ monkeypatch.setattr(main, "_is_windows", lambda: True)
+ monkeypatch.setattr(gateway, "find_gateway_pids", lambda all_profiles=False: [])
+ monkeypatch.setattr(gateway, "find_profile_gateway_processes", lambda strict=False: [])
+ monkeypatch.setattr(gateway, "find_windows_gateway_services", lambda profile_processes=(): [service])
+ monkeypatch.setattr(update_cmd_windows, "_stop_windows_gateways", lambda *a, **k: {})
+ monkeypatch.setattr(update_cmd_windows, "_record_attested_cold_start_profiles", lambda *a: None)
+
+ def stop(*_a, **_k):
+ raise OSError("access denied")
+
+ def restore(_name):
+ if restore_fails:
+ raise OSError("service will not start")
+
+ monkeypatch.setattr(update_cmd, "_stop_windows_gateway_service", stop)
+ monkeypatch.setattr(update_cmd, "_restore_windows_gateway_service", restore)
+
+ with pytest.raises(ServicePauseFailed) as failed:
+ _pause_windows_gateways_for_update()
+ assert bool(failed.value.rollback_failures) is restore_fails
+ saved = pause_record.read(pause_record.record_path())
+ assert (saved is not None) is restore_fails, \
+ "a rolled-back pause kept its record" if saved else "the record of still-stopped gateways was deleted"