fix(update): consume the start attestation only after the cold-start is ready

_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.
This commit is contained in:
kshitijk4poor
2026-09-14 20:23:33 +05:30
committed by kshitij
parent aec8a58611
commit ccc335cdba
2 changed files with 19 additions and 4 deletions
+5 -4
View File
@@ -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")
@@ -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])