The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: a dead unmanaged gateway start ends ensure promptly
Teknium5fe50c239d99
diff --git a/hermes_cli/gateway_runtime.py b/hermes_cli/gateway_runtime.pyindex f232181f142..7ea0b9e6c96 100644--- a/hermes_cli/gateway_runtime.py+++ b/hermes_cli/gateway_runtime.py@@ -230,17 +230,26 @@ def ensure_gateway_runtime(profile_home: str | Path, *, timeout: float = DEFAULTdeadline = time.monotonic() + timeouthome = Path(_canonical_home(profile_home))requested = False+ child = Nonedelay = 0.025try:while True:# The install-root marker also covers profiles.if _update_fenced({home, get_process_hermes_home(), get_default_hermes_root()}):return GatewayDiscovery("draining", reason_code="update_paused")+ # Poll BEFORE discovering: an exit observed first, then "absent", cannot be a child that+ # published its owner a moment later. A winning racer shows up as starting/ready instead.+ status = child.poll() if child is not None else Noneobserved = discover_gateway_endpoint(home, timeout=remaining(deadline))if observed.reason_code == "control_timeout":return GatewayDiscovery("starting", reason_code="deadline")if observed.state not in {"absent", "starting"}:return observed+ if status is not None and observed.state == "absent":+ # The one start this invocation requested died without leaving an owner: waiting+ # out the deadline cannot change that, and this call never launches a second one.+ return GatewayDiscovery("inaccessible", reason_code="runtime_exited", detail=(+ f"gateway exited with status {status}; see logs/gateway-stdio.log of the started profile"))if observed.state == "starting":requested = True# A default multiplexer that is still starting will serve this named profile; never@@ -267,7 +276,7 @@ def ensure_gateway_runtime(profile_home: str | Path, *, timeout: float = DEFAULTstart_existing_gateway_service(service, deadline=deadline)else:from hermes_cli.gateway_runtime_start import spawn_unmanaged_gateway- spawn_unmanaged_gateway(target, deadline=deadline)+ child = spawn_unmanaged_gateway(target, deadline=deadline)requested = Truetime.sleep(min(delay, remaining(deadline)))delay = min(delay * 1.5, 0.25)diff --git a/tests/hermes_cli/test_gateway_runtime_ensure.py b/tests/hermes_cli/test_gateway_runtime_ensure.pyindex beb98f20056..c189076bff2 100644--- a/tests/hermes_cli/test_gateway_runtime_ensure.py+++ b/tests/hermes_cli/test_gateway_runtime_ensure.py@@ -431,3 +431,25 @@ def test_reserved_root_never_suppresses_a_standalone_profile_start(tmp_path, monfinally:owner.close()assert spawned == [home.resolve()]++[email protected]("linux", "macos")+def test_dead_unmanaged_start_is_a_prompt_terminal_verdict(tmp_path, monkeypatch):+ """The one start this call requested exited without leaving an owner: report it, never+ `starting` until the deadline, and never launch a second daemon."""+ from hermes_cli import gateway_runtime as runtime, gateway_runtime_service as service, gateway_runtime_start as start++ home = tmp_path / "profile"+ home.mkdir(mode=0o700)+ children = []++ def dead_start(target, **kwargs):+ children.append(subprocess.Popen([sys.executable, "-c", "raise SystemExit(3)"]))+ return children[-1]+ monkeypatch.setattr(service, "discover_existing_gateway_service", lambda *a, **k: None)+ monkeypatch.setattr(start, "spawn_unmanaged_gateway", dead_start)+ before = time.monotonic()+ result = runtime.ensure_gateway_runtime(home, timeout=20.0)+ assert time.monotonic() - before < 10+ assert (result.state, result.reason_code) == ("inaccessible", "runtime_exited")+ assert "status 3" in result.detail and len(children) == 1