fix(update-windows): per-profile cold-start runs after the relaunch and fails loud

- Run `_cold_start_attested_profiles` AFTER the paused profiles are relaunched,
  so a sibling that fails to cold-start can never keep the profiles that were
  running from coming back.
- A profile that stays down raises like the active-profile cold-start does;
  the merged outcome then marks the update incomplete instead of printing
  success with a gateway still offline.
- Trim the salvaged tests to the two invariants (dead-attested default beside
  a live beta is cold-started under its own home; every dead-attested profile
  is cold-started when nothing runs, active first). The "no attestation →
  token unchanged" case is the pre-existing behaviour already covered by
  test_pause_skips_cold_start_plan_when_desktop_owns_lifecycle.
This commit is contained in:
Hermes Agent
2026-09-14 18:23:17 -07:00
committed by Teknium
parent c728e6583e
commit 8fbae2813b
2 changed files with 10 additions and 19 deletions
+10 -4
View File
@@ -976,8 +976,12 @@ def _cold_start_attested_profiles(token: dict) -> None:
gateway_windows._write_start_attestation(ready_pids, f"cold-start after update (profile {name})", home=home)
print(f"\n✓ Gateway profile {name} started via cold-start after update (PID: {ready_pids[0]})")
token["cold_start_profiles"].pop(name, None)
if not token["cold_start_profiles"]:
token.pop("cold_start_profiles", None)
if token["cold_start_profiles"]:
# Surface the miss like the active-profile cold-start does: the merged outcome marks the update
# incomplete instead of reporting success with a profile still down.
raise RuntimeError("Windows gateway cold-start was not verified for profile(s): "
+ ", ".join(sorted(token["cold_start_profiles"])))
token.pop("cold_start_profiles", None)
def _cold_start_windows_gateway_after_update(token: dict | None = None) -> bool:
@@ -1219,16 +1223,18 @@ def _resume_windows_gateways_after_update(token: dict | None) -> None:
_cold_start_attested_profiles(token)
token["resume_needed"] = False
return
_cold_start_attested_profiles(token)
relaunched, unmapped_relaunched = _relaunch_paused_gateways(token, profiles, unmapped)
if relaunched or unmapped_relaunched:
_verify_relaunched_gateways_alive(token, profiles, unmapped)
token["resume_needed"] = False
if relaunched:
print(f"\n ✓ Restarting Windows gateway profile(s): {', '.join(relaunched)}")
if unmapped_relaunched:
lead = "" if relaunched else "\n"
print(f"{lead} ✓ Restarting {unmapped_relaunched} unmapped Windows gateway process(es)")
# After the paused profiles are back: a dead-attested sibling that fails to cold-start must not
# keep the profiles that WERE running from being relaunched.
_cold_start_attested_profiles(token)
token["resume_needed"] = False
def _resume_windows_gateways_and_merge_outcome(outcome, _windows_gateway_resume, gateway_mode: bool):
@@ -298,21 +298,6 @@ def test_dead_attested_default_is_cold_started_beside_running_beta(monkeypatch,
assert "Gateway profile default started via cold-start after update (PID: 4242)" in out
def test_no_attested_profile_leaves_the_pause_token_unchanged(monkeypatch, tmp_path):
_running_beta_pause_fixture(monkeypatch, tmp_path)
token = update_cmd._pause_windows_gateways_for_update()
assert "cold_start_profiles" not in token
assert token["profiles"] == {"beta": 777}
spawned = []
monkeypatch.setattr(gateway_windows, "_spawn_detached", lambda **k: spawned.append(k) or 4242)
monkeypatch.setattr(gateway_windows, "_write_start_attestation", lambda *a, **k: None)
update_cmd._resume_windows_gateways_after_update(token)
assert spawned == []
assert token["relaunched_profiles"] == ["beta"]
def test_every_dead_attested_profile_is_cold_started_when_nothing_runs(monkeypatch, tmp_path):
"""Nothing running, active profile exited cleanly (plan → None), ``beta`` dead-attested: beta still
gets a token and a spawn. And when BOTH owe a spawn, the fleet-wide active cold-start runs FIRST —