fix(update): verify Windows gateway cold-start survives before reporting success

_cold_start_windows_gateway_after_update() printed the success line off a
successful Popen return alone, which only proves CreateProcess succeeded,
not that the child survived. On Windows, a job object denying
CREATE_BREAKAWAY_FROM_JOB hard-kills the child during updater teardown
before it logs anything, yet the updater still printed "Starting Windows
gateway after update (PID ...)" — leaving Telegram/Discord/etc. offline
with no indication anything failed (#84185).

Route the success report through gateway_windows._report_gateway_start(),
the same post-spawn liveness poll every other _spawn_detached() caller
already uses, so a dead child is reported as a failure with a
manual-recovery hint instead of a false success.
This commit is contained in:
chelsealong
2026-08-12 02:20:26 +00:00
committed by Teknium
parent 517151ee4a
commit 49d72a02f6
2 changed files with 58 additions and 1 deletions
+8 -1
View File
@@ -3467,6 +3467,13 @@ def _cold_start_windows_gateway_after_update() -> None:
Best-effort and idempotent: re-checks that nothing is running first so a
concurrent start (e.g. the autostart entry firing) can't produce a
duplicate gateway.
A successful ``Popen`` only proves the process was created, not that it
survived (e.g. a Windows job object denying breakaway kills it before it
logs anything — #84185). So the success line is gated on the same
post-spawn liveness poll every other ``_spawn_detached`` caller uses
(``gateway_windows._report_gateway_start``), instead of being printed
unconditionally from the returned PID.
"""
if not _m()._is_windows():
return
@@ -3495,7 +3502,7 @@ def _cold_start_windows_gateway_after_update() -> None:
if pid:
print()
print(f" ✓ Starting Windows gateway after update (PID {pid})")
gateway_windows._report_gateway_start(f"cold-start after update (PID {pid})")
def _for_each_systemd_gateway_unit(
list_units_stdout: str,
@@ -0,0 +1,50 @@
"""#84185: a Windows gateway cold-started after update that dies immediately
(e.g. a job object denying breakaway) must not be reported as started.
``_cold_start_windows_gateway_after_update`` used to print the success line
straight off a successful ``Popen`` return, which only proves the process was
created, not that it survived. This asserts the observable output: the
success line is gated on the process actually being found alive afterwards,
same as every other ``_spawn_detached`` caller.
"""
from __future__ import annotations
from hermes_cli import gateway as hermes_gateway
from hermes_cli import gateway_windows
from hermes_cli import main as cli_main
from hermes_cli import update_cmd
def _run_cold_start(monkeypatch, capsys, *, surviving_pids):
monkeypatch.setattr(cli_main, "_is_windows", lambda: True)
# The pre-spawn re-check (``all_profiles=True``) must find nothing
# running so the cold-start path proceeds and actually spawns.
monkeypatch.setattr(
hermes_gateway,
"find_gateway_pids",
lambda all_profiles=False: [] if all_profiles else surviving_pids,
)
monkeypatch.setattr(gateway_windows, "_spawn_detached", lambda: 4242)
# Avoid the real 6s/0.4s poll loop in _report_gateway_start.
monkeypatch.setattr(
gateway_windows, "_wait_for_gateway_ready", lambda *a, **k: surviving_pids
)
update_cmd._cold_start_windows_gateway_after_update()
return capsys.readouterr().out
def test_cold_start_reports_failure_when_process_does_not_survive(monkeypatch, capsys):
out = _run_cold_start(monkeypatch, capsys, surviving_pids=[])
assert "✓ Starting Windows gateway after update" not in out
assert "no process detected" in out
def test_cold_start_reports_success_when_process_survives(monkeypatch, capsys):
out = _run_cold_start(monkeypatch, capsys, surviving_pids=[4242])
assert "✓ Gateway started via cold-start after update" in out