The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): `hermes update` drain stays reachable for a parked approval/clarify (#139041)
Tekniumda76391fdc7f
diff --git a/hermes_cli/gateway_runtime.py b/hermes_cli/gateway_runtime.pyindex 77081dcc5dd..e400ebb4ac7 100644--- a/hermes_cli/gateway_runtime.py+++ b/hermes_cli/gateway_runtime.py@@ -252,6 +252,17 @@ def _update_fenced(homes) -> bool:return False+def _fenced_verdict(home: Path, timeout: float) -> GatewayDiscovery:+ """What ensure answers while an update owns the install. The update's own drain+ (``pause-for-update``) is a restart's after-turn wait whose owner may hold a turn parked on+ approval/clarify, so it is handed out for clients to answer it (#139041). Discovery only:+ nothing is started or replaced while fenced, and any other owner state stays ``update_paused``."""+ observed = discover_gateway_endpoint(home, timeout=timeout)+ if observed.state == "draining" and attachable(observed):+ return observed+ return GatewayDiscovery("draining", reason_code="update_paused")++_REPLACE_FAILED_DETAIL = "an older Hermes gateway still owns this profile after a stop; run: hermes gateway stop"# ``draining`` reasons after which the owner is going away by itself: its own idle exit, or the# older-Hermes owner this call just stopped. Ensure waits it out and starts the current owner.@@ -316,7 +327,7 @@ def ensure_gateway_runtime(profile_home: str | Path, *, timeout: float = DEFAULTwhile 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")+ return _fenced_verdict(home, remaining(deadline))# 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 Nonediff --git a/hermes_cli/update_cmd_drain_report.py b/hermes_cli/update_cmd_drain_report.pyindex 7e386e501e6..41d6852216e 100644--- a/hermes_cli/update_cmd_drain_report.py+++ b/hermes_cli/update_cmd_drain_report.py@@ -89,6 +89,11 @@ def format_drain_report(work: Optional[list], *, remaining_s: float, home: Optioelse:lines.append(f" waiting on {len(work)} active work unit(s):")lines.extend(f" • {describe_active_work_unit(u, home)}" for u in work)+ if any(isinstance(u, dict) and u.get("kind") == "chat" for u in work):+ # The draining gateway stays reachable for this (#139041): a chat turn parked on an+ # approval/clarify is answered from a client, not waited out.+ lines.append(" a chat turn waiting on an approval or clarify question can be answered now: "+ "open it with `hermes --tui` (resume the session)")lines.append(" finish or kill the work above to release the drain now; ""agent.restart_after_turn_timeout in config.yaml caps this wait")return "\n".join(lines)diff --git a/tests/gateway/test_restart_wait_prompt_reach.py b/tests/gateway/test_restart_wait_prompt_reach.pyindex 543e28f79e5..73795416995 100644--- a/tests/gateway/test_restart_wait_prompt_reach.py+++ b/tests/gateway/test_restart_wait_prompt_reach.py@@ -40,6 +40,44 @@ def test_ensure_hands_out_the_restart_wait_owner_as_draining_with_its_endpoint(tasyncio.run(probe())[email protected]("linux")+def test_update_fence_hands_out_only_the_draining_owners_restart_wait(tmp_path):+ """`hermes update`'s drain (pause-for-update) is a restart wait: while the update marker is live,+ ensure still hands that owner out so a parked prompt can be answered; anything else (a ready owner,+ a stopping one, none at all) stays ``update_paused`` and nothing is ever started."""+ import os+ import time+ from tests.hermes_cli.test_gateway_runtime import control_peer+ from hermes_cli.gateway_runtime import ensure_gateway_runtime+ from hermes_cli.update_lock import MARKER_NAME, process_create_time++ home = tmp_path / "profile"+ identity = str(home.resolve())+ payload = {"protocol": 1, "runtime_protocol": 1, "instance_id": "owner", "authority_epoch": 1,+ "hermes_home": identity, "state": "draining", "drain_reason": "restart_wait",+ "api_origin": "http://127.0.0.1:41817", "supervisor": "none",+ "served_profiles": [{"profile_id": identity, "home": identity}],+ "capabilities": ["session-authority-v1"]}++ def ensure():+ result = ensure_gateway_runtime(home, timeout=5)+ return result.state, result.reason_code, None if result.endpoint is None else result.endpoint.instance_id++ async def probe():+ async with control_peer(home, payload):+ (home / MARKER_NAME).write_text(+ f"{os.getpid()}\n{int(time.time())}\nct:{process_create_time():.3f}\n", encoding="utf-8")+ assert await asyncio.to_thread(ensure) == ("draining", "restart_wait", "owner")+ del payload["drain_reason"] # stop() began+ assert await asyncio.to_thread(ensure) == ("draining", "update_paused", None)+ payload["state"] = "ready"+ assert await asyncio.to_thread(ensure) == ("draining", "update_paused", None)+ assert await asyncio.to_thread(ensure) == ("draining", "update_paused", None)+ assert not (home / "logs").exists() # no start was attempted while fenced++ asyncio.run(probe())++@pytest.mark.asyncioasync def test_restart_wait_commits_new_input_queued_and_never_claims_it(tmp_path, monkeypatch):from gateway.config import Platform