From ccc335cdbad312b42be9728ad511e8b7d17fec03 Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Mon, 14 Sep 2026 20:23:33 +0530 Subject: [PATCH] fix(update): consume the start attestation only after the cold-start is ready MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _cold_start_windows_gateway_after_update cleared the dead attestation as soon as _spawn_detached() returned a PID, before _wait_for_gateway_ready() proved the gateway survived. When readiness failed, the RuntimeError registered the retry, but the retry then saw Desktop lifecycle ownership with no marker and returned success without spawning anything — the silent outage of #109538 came back through the retry path (#110020 review). The marker is now consumed after readiness is confirmed, so a failed spawn leaves the retry its recovery obligation. --- hermes_cli/update_cmd_windows.py | 9 +++++---- .../test_update_cold_start_gateway_liveness.py | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/hermes_cli/update_cmd_windows.py b/hermes_cli/update_cmd_windows.py index 2751cf3649..379841978d 100644 --- a/hermes_cli/update_cmd_windows.py +++ b/hermes_cli/update_cmd_windows.py @@ -949,13 +949,14 @@ def _cold_start_windows_gateway_after_update() -> bool: pid = gateway_windows._spawn_detached() if not pid: raise RuntimeError("Windows gateway cold-start did not return a process ID") - # The dead attestation has now done its job (it authorized this spawn under Desktop ownership). - # Consume it the same way check_start_attestation does, so a stale crash marker cannot - # re-authorize a cold start on a later update if this one never becomes ready. - gateway_windows._clear_start_attestation() ready_pids = gateway_windows._wait_for_gateway_ready() if not ready_pids: raise RuntimeError(f"Windows gateway cold-start PID {pid} did not become ready") + # The dead attestation has done its job (it authorized this spawn under Desktop ownership). Consume + # it only now: a spawn that never became ready leaves it in place, so the registered retry still + # holds its recovery obligation instead of seeing Desktop ownership with no marker and returning + # success without a gateway (#110020 review). + gateway_windows._clear_start_attestation() print(f"\nāœ“ Gateway started via cold-start after update (PID: {', '.join(map(str, ready_pids))})") with suppress(Exception): gateway_windows._write_start_attestation(ready_pids, "cold-start after update") diff --git a/tests/hermes_cli/test_update_cold_start_gateway_liveness.py b/tests/hermes_cli/test_update_cold_start_gateway_liveness.py index cac4ae3a0b..c7b2a4309a 100644 --- a/tests/hermes_cli/test_update_cold_start_gateway_liveness.py +++ b/tests/hermes_cli/test_update_cold_start_gateway_liveness.py @@ -48,6 +48,20 @@ def test_cold_start_raises_when_process_does_not_survive(monkeypatch, capsys): assert "āœ“ Starting Windows gateway after update" not in capsys.readouterr().out +def test_failed_readiness_keeps_the_dead_attestation_for_the_retry(monkeypatch, tmp_path, capsys): + """#110020 review: the attestation is the retry's only authority to spawn under Desktop + ownership, so a spawn that returns a PID but never becomes ready must NOT consume it — + otherwise the registered retry sees ownership with no marker and "succeeds" with no gateway.""" + monkeypatch.setattr("hermes_cli.config.get_hermes_home", lambda: str(tmp_path)) + gateway_windows._write_start_attestation([555], "direct spawn (PID 555)") + marker = tmp_path / "state" / "gateway.start-attestation.json" + + with pytest.raises(RuntimeError, match="did not become ready"): + _run_cold_start(monkeypatch, capsys, surviving_pids=[]) + assert marker.exists() + assert gateway_windows.attested_gateway_died(current_pids=[]) is True + + def test_cold_start_reports_success_when_process_survives(monkeypatch, capsys): out = _run_cold_start(monkeypatch, capsys, surviving_pids=[4242])