The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): only ai.hermes launchd jobs get the ExitTimeOut drain cap
kshitijk4poord5f3d8d8daaf
diff --git a/gateway/restart.py b/gateway/restart.pyindex a0e0f55a7cf..49100201c06 100644--- a/gateway/restart.py+++ b/gateway/restart.py@@ -84,10 +84,18 @@ def parse_launchd_exit_timeout(print_output: object) -> float | None:def launchd_service_label(environ: Mapping[str, str] | None = None) -> str | None:- """Return this process's launchd job label, or ``None`` when not launchd-owned."""+ """Return this process's ``ai.hermes.*`` launchd job label, or ``None``.++ Only labels of the gateway's own jobs count (same predicate as+ :mod:`gateway.control_socket`). App-coalition labels+ (``application.<bundle>…``, exported into IDE integrated terminals) also+ populate ``XPC_SERVICE_NAME``, and ``launchctl print`` reports+ ``exit timeout = 1`` for them — treating those as a budget would cap the+ drain to 0 for a gateway Ctrl+C'd in such a terminal.+ """env = os.environ if environ is None else environlabel = str(env.get("XPC_SERVICE_NAME", "") or "").strip()- if not label or label == "0":+ if not label.startswith("ai.hermes"):return Nonereturn labeldiff --git a/tests/gateway/test_launchd_exit_timeout_drain_cap.py b/tests/gateway/test_launchd_exit_timeout_drain_cap.pyindex 5b2534b0501..55a9b26ba0c 100644--- a/tests/gateway/test_launchd_exit_timeout_drain_cap.py+++ b/tests/gateway/test_launchd_exit_timeout_drain_cap.py@@ -13,21 +13,36 @@ from __future__ import annotationsfrom types import SimpleNamespace+import pytest+from gateway.restart import (LAUNCHD_STOP_CLEANUP_RESERVE_S,effective_stop_drain_timeout,effective_stop_watchdog_delay,+ read_launchd_exit_timeout_s,resolve_launchd_capped_drain,)from gateway.shutdown_watchdog import resolve_shutdown_watchdog_delay-def test_capped_drain_fits_inside_launchd_budget_minus_reserve():+ "label, expected",+ [+ ("ai.hermes.gateway", 60.0 - LAUNCHD_STOP_CLEANUP_RESERVE_S),+ # App-coalition label (IDE integrated terminal) is not our job: no budget, drain unchanged.+ ("application.com.example.ide.123", 180.0),+ ],+)+def test_capped_drain_fits_inside_launchd_budget_minus_reserve(label, expected):# The incident shape: configured 180s, launchd clamps to 60s.assert resolve_launchd_capped_drain(180.0, 60.0) == 60.0 - LAUNCHD_STOP_CLEANUP_RESERVE_S# Never extends a short drain; no launchd budget leaves the configured drain alone.assert resolve_launchd_capped_drain(20.0, 60.0) == 20.0assert resolve_launchd_capped_drain(180.0, None) == 180.0+ # End to end through the reader: only ai.hermes jobs yield a budget.+ fake_run = lambda *a, **k: SimpleNamespace(returncode=0, stdout="exit timeout = 60\n") # noqa: E731+ budget = read_launchd_exit_timeout_s(environ={"XPC_SERVICE_NAME": label}, uid=501, run=fake_run)+ assert resolve_launchd_capped_drain(180.0, budget) == expecteddef _runner(*, drain: float, launchd: float | None, by_signal: bool):