Skip to content

The agent that grows with you

fix(desktop): terminate app-managed gateway on shutdown

Quark Assistant0b15eb5f053e
diff --git a/hermes_cli/web_server.py b/hermes_cli/web_server.py
index 62bef20e38e..f25255e65cc 100644
--- a/hermes_cli/web_server.py
+++ b/hermes_cli/web_server.py
@@ -281,6 +281,8 @@ async def _lifespan(app: "FastAPI"):
await PTY_REGISTRY.close_all()
if cron_stop is not None:
cron_stop.set()
+ if os.getenv("HERMES_DESKTOP") == "1":
+ _terminate_desktop_managed_gateway()
def _get_event_state(app: "FastAPI"):
@@ -3810,6 +3812,19 @@ _ACTION_IDS: Dict[str, str] = {}
_ACTION_RESULTS: Dict[str, Dict[str, Any]] = {}
+def _terminate_desktop_managed_gateway() -> None:
+ """Stop a live gateway restart child when its Desktop backend shuts down."""
+ proc = _ACTION_PROCS.get("gateway-restart")
+ if proc is None:
+ return
+ try:
+ if proc.poll() is None:
+ proc.terminate()
+ except OSError:
+ # The child may have exited between poll() and terminate().
+ pass
+
+
def _record_completed_action(name: str, message: str, exit_code: int = 1) -> None:
"""Record a non-spawned action result and write it to the action log."""
log_file_name = _ACTION_LOG_FILES[name]