Files
hermes-agent/hermes_cli/gateway_host_record.py
unsupportedpastels 2a42ecd2a4 fix(cli): start a new gateway after restart even with a warm host probe
The host-gateway probe is memoized for HOST_GATEWAY_CACHE_TTL_S (2 s) and
the stop in _cmd_restart finishes well inside that, so the in-process
run_gateway read "PID <stopped> serves this profile", printed "nothing to
start" and exited 0 with no gateway running. _cmd_restart's stop/start
path and _restart_all_as_host now drop the memo after the stop.

The new test warms the memo through the real host_attach API and drives
run_gateway's attach decision for real; it fails on the previous head with
the same output the reviewer reproduced live.

Refs: #138624 (review by teknium1, finding 1), #134889 (N1)
2026-10-14 20:05:34 -04:00

33 lines
1.2 KiB
Python

"""Host-gateway cleanup after a confirmed stop: the rendezvous record and the memoized probe."""
from __future__ import annotations
import logging
logger = logging.getLogger("hermes_cli.gateway")
def _discard_dead_host_record() -> bool:
"""Drop the host rendezvous record once its owner is provably gone (after a confirmed stop)."""
try:
from gateway.host_rendezvous import ROLE_GATEWAY, discard_dead_record
return discard_dead_record(ROLE_GATEWAY)
except Exception:
logger.debug("Host record retraction failed", exc_info=True)
return False
def _forget_host_gateway_probe() -> None:
"""Drop the memoized host-gateway probe after a stop, before the restart starts a new one.
The probe is cached for ``HOST_GATEWAY_CACHE_TTL_S`` and a stop finishes well inside it, so the
in-process ``run_gateway`` read "PID <stopped> serves this profile", printed "nothing to start"
and exited 0 with no gateway running.
"""
try:
from gateway.host_attach import invalidate_host_gateway_cache
invalidate_host_gateway_cache()
except Exception:
logger.debug("Host gateway probe invalidation failed", exc_info=True)