The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): stop counting the Windows resume token as a fleet runtime
Teknium71823be9daea
diff --git a/hermes_cli/update_cmd.py b/hermes_cli/update_cmd.pyindex 49c46a5fae9..a83bd8cc5a6 100644--- a/hermes_cli/update_cmd.py+++ b/hermes_cli/update_cmd.py@@ -9656,21 +9656,36 @@ def _fleet_probe_expected_runtimes(cannot prove nothing was running; same contract as``_restart_phase_failure_is_incomplete``, #78574).* the pre-update plan inventoried ≥1 runtime.- * the Windows pause/resume token carries paused ``profiles`` or- ``unmapped`` entries — ``_pause_windows_gateways_for_update`` /- ``_resume_windows_gateways_after_update`` populate NEITHER- ``restarted_services`` NOR ``killed_pids``, which is exactly why the- original ``(restarted_services or killed_pids)`` guard never fires on- Windows.- The same condition gates the 2.0s settle sleep: a freshly resumed Windows- gateway needs the settle window to rewrite ``gateway_state.json`` just- like a systemd-restarted one.+ ``windows_resume_token`` is deliberately EXCLUDED (#93406 residual). The+ pause/resume token is bookkeeping for ``_pause_windows_gateways_for_update``+ / ``_resume_windows_gateways_after_update`` — it is not a runtime+ inventory, and its entries do not correspond to rows+ ``collect_fleet_versions()`` is capable of returning:++ * ``unmapped`` entries (Scheduled-Task gateways) never publish+ ``gateway_state.json`` rows at all, and+ * a paused profile gateway is resumed as a DETACHED relaunch that may not+ republish its identity within the probe window.++ Counting the token therefore made ``_fleet_rows_expected`` True on every+ Windows update that had paused a gateway, the probe's polling window ran+ out with zero rows on a perfectly healthy update, and verification+ reported "no rows … verification incomplete" and exited 1 after a long+ silent wait. Expected-runtimes must key only on signals that map to rows+ the probe can actually see; a genuinely live pre-update Windows gateway+ is already covered by ``pre_restart_pids`` and the plan inventory. The+ parameter stays in the signature so the call site keeps passing the token+ (cheap, explicit, and the docstring is where the exclusion is explained).++ The same condition gates the 2.0s settle sleep: a freshly restarted+ gateway needs the settle window to rewrite ``gateway_state.json``.Note this keys ONLY on zero-rows-despite-expected-runtimes. A non-emptysnapshot — including rows in ``unknown`` state — is still judged solely by``print_fleet_version_matrix``."""+ del windows_resume_token # excluded on purpose — see docstring (#93406)if restarted_services or killed_pids:return Trueif pre_restart_pids is None or pre_restart_pids:@@ -9680,13 +9695,6 @@ def _fleet_probe_expected_runtimes(return Trueexcept Exception:pass- if isinstance(windows_resume_token, dict) and (- windows_resume_token.get("profiles")- or windows_resume_token.get("unmapped")- or windows_resume_token.get("services")- or windows_resume_token.get("expected_services")- ):- return Truereturn Falsediff --git a/tests/hermes_cli/test_update_fleet_check_fail_closed.py b/tests/hermes_cli/test_update_fleet_check_fail_closed.pyindex ab71d5e8966..6e51e8c33f3 100644--- a/tests/hermes_cli/test_update_fleet_check_fail_closed.py+++ b/tests/hermes_cli/test_update_fleet_check_fail_closed.py@@ -8,13 +8,15 @@ verifiably live before the update.The first guard (PR #93410) keyed on ``(restarted_services or killed_pids)``,which never fires on Windows: ``_pause_windows_gateways_for_update`` /-``_resume_windows_gateways_after_update`` populate neither list, so a healthy-resumed Windows gateway still yielded zero rows and exit 0. The fix hoists-the "should the probe have produced rows?" decision into-``_fleet_probe_expected_runtimes`` and keys it on every pre-update liveness-signal: restart-phase bookkeeping, the pre-restart PID snapshot, the-pre-update plan inventory, and the Windows pause/resume token. The same-condition gates the 2.0s settle sleep.+``_resume_windows_gateways_after_update`` populate neither list. The fix+hoists the "should the probe have produced rows?" decision into+``_fleet_probe_expected_runtimes`` and keys it on the ROW-CAPABLE pre-update+liveness signals: restart-phase bookkeeping, the pre-restart PID snapshot,+and the pre-update plan inventory. The Windows pause/resume token is+deliberately NOT a signal — it is bookkeeping, not a runtime inventory, and+its entries have no corresponding ``collect_fleet_versions()`` rows (see+``test_update_fleet_probe_resume_token.py``). The same condition gates the+2.0s settle sleep."""from __future__ import annotations@@ -47,21 +49,22 @@ class TestEmptySnapshotFailClosed:is True)- def test_incomplete_when_windows_resume_token_has_profiles(self):- # (c) The Windows pause/resume path: restarted_services and- # killed_pids stay empty by construction, so the resume token is the- # ONLY signal that a gateway was live. This is exactly the case the- # original (restarted_services or killed_pids) guard missed.+ def test_windows_resume_token_alone_is_not_expected(self):+ # (c) The Windows pause/resume token is EXCLUDED from the expectation+ # (#93406 residual): it is pause/resume bookkeeping, not a runtime+ # inventory, and collect_fleet_versions() cannot return rows for its+ # entries (unmapped Scheduled-Task gateways never publish+ # gateway_state.json; a resumed profile gateway relaunches detached).+ # Counting it made a healthy Windows update wait out the probe window+ # and exit 1 on zero rows. Full coverage lives in+ # test_update_fleet_probe_resume_token.py.token = {"resume_needed": False, "profiles": {"default": 4321}}assert (- _fleet_probe_expected_runtimes(None, [], token, [], set()) is True+ _fleet_probe_expected_runtimes(None, [], token, [], set()) is False)-- def test_incomplete_when_windows_resume_token_has_unmapped(self):- # Scheduled-Task gateways land in token["unmapped"], not profiles.token = {"resume_needed": False, "unmapped": [{"pid": 99, "argv": ["x"]}]}assert (- _fleet_probe_expected_runtimes(None, [], token, [], set()) is True+ _fleet_probe_expected_runtimes(None, [], token, [], set()) is False)def test_incomplete_when_windows_resume_token_has_services(self):diff --git a/tests/hermes_cli/test_update_fleet_probe_resume_token.py b/tests/hermes_cli/test_update_fleet_probe_resume_token.pynew file mode 100644index 00000000000..cc916593850--- /dev/null+++ b/tests/hermes_cli/test_update_fleet_probe_resume_token.py@@ -0,0 +1,94 @@+"""Regression for #93406 (residual) — the Windows pause/resume token is NOT a+fleet runtime and must not be counted by ``_fleet_probe_expected_runtimes``.++The first #93406 guard counted the ``_windows_gateway_resume`` token+(``profiles`` / ``unmapped`` entries) as an "expected fleet rows" signal. But+the token is pause/resume *bookkeeping*, not a runtime inventory:++* ``unmapped`` entries (Scheduled-Task gateways) never publish+ ``gateway_state.json`` rows at all, and+* a paused-then-resumed profile gateway relaunches DETACHED and may not+ republish its identity within the probe's window,++so ``collect_fleet_versions()`` can legitimately return zero rows for a+perfectly healthy Windows update. With the token counted as an expected+runtime, ``_fleet_rows_expected`` is True, the verification loop silently+waits out its polling window (~14 min wall clock on an end-user report with+the retry loop), prints "Fleet version check returned no rows", and ``hermes+update`` exits 1 — for an update that succeeded.++The invariant this file pins: ``_fleet_probe_expected_runtimes`` may only+return True for signals that correspond to rows ``collect_fleet_versions()``+is actually capable of returning (restart-phase bookkeeping, the pre-restart+PID snapshot, the pre-update plan inventory). A genuinely live pre-update+Windows gateway is already covered by ``pre_restart_pids`` and the plan+inventory — the token adds no row-capable information on top.++Counterfactual: every test in ``TestResumeTokenIsNotARuntime`` FAILS on the+pre-fix ``_fleet_probe_expected_runtimes`` (which returns True for a+token-only signal).+"""++from __future__ import annotations++import types++from hermes_cli.main import _fleet_probe_expected_runtimes+++def _plan(runtimes):+ return types.SimpleNamespace(runtimes=runtimes)+++class TestResumeTokenIsNotARuntime:+ """Token-only signals must NOT mark fleet rows as expected (#93406)."""++ def test_token_profiles_alone_do_not_expect_rows(self):+ # A paused/resumed profile gateway relaunches detached; its row is+ # not guaranteed within the probe window. Token-only == no rows+ # expected, so zero rows stays exit 0 instead of a false failure.+ token = {"resume_needed": False, "profiles": {"default": 4321}}+ assert (+ _fleet_probe_expected_runtimes(None, [], token, [], set()) is False+ )++ def test_token_unmapped_alone_does_not_expect_rows(self):+ # Scheduled-Task gateways (token["unmapped"]) never publish+ # gateway_state.json rows — collect_fleet_versions() CANNOT return a+ # row for them, so they must not be counted as expected rows.+ token = {"resume_needed": False, "unmapped": [{"pid": 99, "argv": ["x"]}]}+ assert (+ _fleet_probe_expected_runtimes(None, [], token, [], set()) is False+ )++ def test_token_with_empty_pid_snapshot_is_still_not_expected(self):+ # Even alongside an affirmatively-empty PID snapshot and an empty+ # plan, the token alone must not flip the expectation.+ token = {"resume_needed": True, "profiles": {"work": 777}, "unmapped": []}+ assert (+ _fleet_probe_expected_runtimes(_plan([]), [], token, [], set())+ is False+ )+++class TestRowCapableSignalsStillCount:+ """The row-capable liveness signals are unaffected by the exclusion."""++ def test_pre_restart_pids_still_expect_rows_alongside_token(self):+ # A live pre-update gateway is covered by the PID snapshot — the+ # row-capable signal — regardless of the token riding along.+ token = {"resume_needed": False, "profiles": {"default": 4321}}+ assert (+ _fleet_probe_expected_runtimes(None, [4321], token, [], set())+ is True+ )++ def test_plan_inventory_still_expects_rows_alongside_token(self):+ token = {"resume_needed": False, "unmapped": [{"pid": 99, "argv": ["x"]}]}+ assert (+ _fleet_probe_expected_runtimes(_plan([object()]), [], token, [], set())+ is True+ )++ def test_unreadable_pre_state_still_expects_rows(self):+ assert _fleet_probe_expected_runtimes(None, None, None, [], set()) is True