gateway_host_record.py 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. """Host-gateway cleanup after a confirmed stop: the rendezvous record and the memoized probe."""
  2. from __future__ import annotations
  3. import logging
  4. logger = logging.getLogger("hermes_cli.gateway")
  5. def _discard_dead_host_record() -> bool:
  6. """Drop the host rendezvous record once its owner is provably gone (after a confirmed stop)."""
  7. try:
  8. from gateway.host_rendezvous import ROLE_GATEWAY, discard_dead_record
  9. return discard_dead_record(ROLE_GATEWAY)
  10. except Exception:
  11. logger.debug("Host record retraction failed", exc_info=True)
  12. return False
  13. def _forget_host_gateway_probe() -> None:
  14. """Drop the memoized host-gateway probe after a stop, before the restart starts a new one.
  15. The probe is cached for ``HOST_GATEWAY_CACHE_TTL_S`` and a stop finishes well inside it, so the
  16. in-process ``run_gateway`` read "PID <stopped> serves this profile", printed "nothing to start"
  17. and exited 0 with no gateway running.
  18. """
  19. try:
  20. from gateway.host_attach import invalidate_host_gateway_cache
  21. invalidate_host_gateway_cache()
  22. except Exception:
  23. logger.debug("Host gateway probe invalidation failed", exc_info=True)