The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(dashboard): only an absent gateway takes the offline session edit path
unsupportedpastelsff75c93f427c
diff --git a/hermes_cli/web_server_sessions.py b/hermes_cli/web_server_sessions.pyindex 5d2d82cb970..59a3c39e11a 100644--- a/hermes_cli/web_server_sessions.py+++ b/hermes_cli/web_server_sessions.py@@ -192,8 +192,11 @@ async def _mutate_via_gateway_owner(profile, actor, params):dashboard`` is not the store owner, so the offline path'sexclusive-maintenance reservation can never win and every write actiondies on a bare 409 (#138915). The owner exposes the same revision-fenced- verb over the control socket; with no discoverable owner return None so the- caller falls back to the offline store.+ verb over the control socket. Only a home discovery reads as owner-less+ (``absent``) returns None, so the caller falls back to the offline store. An owner that+ exists but could not be identified (a control timeout, a profile mismatch, a refused peer,+ one starting or draining) answers 503 with discovery's reason: the offline reservation would+ lose to it and the edit would vanish behind the bare 409 (#144141).A dial, mint or RPC that dies on an endpoint discovery just identified isnot owner-less (a slow first dial, or an owner restart between discovery@@ -217,9 +220,14 @@ async def _mutate_via_gateway_owner(profile, actor, params):home = Path(_cron_profile_home(profile)[1]) if profile else Path(_default_db_path()).parent# Discovery is read-only and never starts a gateway.discovery = await asyncio.to_thread(discover_gateway_endpoint, home, timeout=1.5)- endpoint = getattr(discovery, 'endpoint', None)+ endpoint = discovery.endpointif endpoint is None:- return None+ if discovery.state == 'absent':+ return None+ reason = discovery.reason_code or discovery.state+ _log.warning('session write for %s: gateway owner not reachable (%s, %s): %s',+ home, discovery.state, reason, discovery.detail)+ raise HTTPException(status_code=503, detail=f'owner_unavailable: {reason}')if not getattr(endpoint, 'control_home', True):# The selected home answered on its own socket (a multiplexer-served profile already# names the multiplexer root). Pin it, so the ticket is minted on the socket that justdiff --git a/tests/hermes_cli/test_web_server_session_owner_forward.py b/tests/hermes_cli/test_web_server_session_owner_forward.pyindex 8d1b5ade88c..316954a1ca8 100644--- a/tests/hermes_cli/test_web_server_session_owner_forward.py+++ b/tests/hermes_cli/test_web_server_session_owner_forward.py@@ -31,7 +31,8 @@ def _discover(monkeypatch, endpoint, seen=None):def fake_discover(home, timeout=2.0):if seen is not None:seen['home'] = home- return SimpleNamespace(endpoint=endpoint)+ return SimpleNamespace(state='absent' if endpoint is None else 'ready', endpoint=endpoint,+ reason_code=None, detail=None)monkeypatch.setattr('hermes_cli.gateway_runtime.discover_gateway_endpoint', fake_discover)@@ -101,6 +102,31 @@ async def test_standalone_mutation_falls_back_to_offline_without_an_owner(tmp_paassert offline[0]['operation'] == 'rename'[email protected]('state, reason_code', [('inaccessible', 'control_timeout'),+ ('inaccessible', 'profile_mismatch'), ('starting', None)])+async def test_an_owner_discovery_cannot_identify_is_not_owner_less(tmp_path, monkeypatch, state, reason_code):+ """#144141: over SSH ``serve --isolated`` discovery of a running gateway came back without an+ endpoint, and every such verdict took the offline store, whose reservation the live owner+ always wins (409): pins and renames looked applied, then vanished. Only an ``absent`` owner is+ owner-less; anything else answers a retryable 503 that names discovery's reason."""+ from hermes_cli import web_server_sessions+ from hermes_cli.gateway_runtime import GatewayDiscovery++ request = _standalone_request(monkeypatch, tmp_path)+ monkeypatch.setattr('hermes_cli.gateway_runtime.discover_gateway_endpoint',+ lambda home, timeout=2.0: GatewayDiscovery(state, reason_code=reason_code))+ offline = []+ monkeypatch.setattr(web_server_sessions, '_mutate_offline_store',+ lambda profile, actor, params: offline.append(params))+ with pytest.raises(HTTPException) as exc:+ await web_server_sessions._mutate_session_request(+ request, None, 'session-7', request_id='req-7', expected_revision=0,+ operation='sidebar', payload={})+ assert (exc.value.status_code, exc.value.detail) == (503, f'owner_unavailable: {reason_code or state}')+ assert offline == []++@pytest.mark.asyncioasync def test_owner_dial_failure_surfaces_a_retryable_error(tmp_path, monkeypatch):"""A dial that dies on an endpoint discovery just identified is not owner-less (a slow first