Skip to content

The agent that grows with you

fix(dashboard): answer a dead owner dial with a retryable 503, not a 409

liuhao10242d380e7a7fc2
diff --git a/hermes_cli/web_server_sessions.py b/hermes_cli/web_server_sessions.py
index 0a4d07970d4..dd2fd3cd5ea 100644
--- a/hermes_cli/web_server_sessions.py
+++ b/hermes_cli/web_server_sessions.py
@@ -192,14 +192,20 @@ async def _mutate_via_gateway_owner(profile, actor, params):
dashboard`` is not the store owner, so the offline path's
exclusive-maintenance reservation can never win and every write action
dies on a bare 409 (#138915). The owner exposes the same revision-fenced
- verb over the control socket; with no discoverable owner (or a dial that
- died under us) return None so the caller falls back to the offline store.
+ verb over the control socket; with no discoverable owner return None so the
+ caller falls back to the offline store.
+
+ A dial or RPC that dies on an endpoint discovery just identified is not
+ owner-less (a slow first dial, not a stale endpoint): the offline
+ reservation would only lose to that same owner and answer with the bare 409
+ this forward exists to remove, so it surfaces a retryable 503 instead.
The ticket is minted for the dashboard's authenticated principal, not the
socket UID: ``authorize_history`` compares the actor subject against the
row's stored owner, so a cold row owned by a dashboard account only takes
the mutation when the forward acts as that account.
"""
+ from fastapi import HTTPException
from hermes_cli.gateway_client import GatewayClientError, connect_gateway
from hermes_cli.gateway_runtime import discover_gateway_endpoint
from hermes_cli.web_server_cron import _cron_profile_home
@@ -222,8 +228,8 @@ async def _mutate_via_gateway_owner(profile, actor, params):
return await client.rpc('session.mutate', **call)
except GatewayClientError:
raise
- except (OSError, TimeoutError):
- return None
+ except (OSError, TimeoutError) as exc:
+ raise HTTPException(status_code=503, detail='owner_unreachable') from exc
async def _mutate_session_request(request, profile, session_id, *, request_id,
diff --git a/package.json b/package.json
index 268a6f9c979..9521bc1ece2 100644
--- a/package.json
+++ b/package.json
@@ -87,6 +87,5 @@
"dependencies": {
"js-yaml": "4.3.2",
"semver": "7.7.4"
- },
- "packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
+ }
}
diff --git a/tests/hermes_cli/test_web_server_session_owner_forward.py b/tests/hermes_cli/test_web_server_session_owner_forward.py
index d7747b5f8a0..bbb9251daa6 100644
--- a/tests/hermes_cli/test_web_server_session_owner_forward.py
+++ b/tests/hermes_cli/test_web_server_session_owner_forward.py
@@ -98,9 +98,11 @@ async def test_standalone_mutation_falls_back_to_offline_without_an_owner(tmp_pa
@pytest.mark.asyncio
-async def test_owner_dial_failure_falls_back_to_the_offline_store(tmp_path, monkeypatch):
- """An owner that dies between discovery and dial is not a refusal: the offline path
- decides (and succeeds when the ownership lock really is free)."""
+async 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
+ dial, not a stale endpoint): the offline reservation would only lose to that same owner and
+ answer with the bare 409 this forward exists to remove, so a retryable 503 is the honest
+ verdict — a later retry rediscovers and takes the offline store once the owner is really gone."""
from hermes_cli import web_server_sessions
request = _standalone_request(monkeypatch, tmp_path)
@@ -108,21 +110,21 @@ async def test_owner_dial_failure_falls_back_to_the_offline_store(tmp_path, monk
@asynccontextmanager
async def dying_connect(endpoint=None, subject=None):
- raise FileNotFoundError('owner control socket vanished')
+ raise TimeoutError('first dial outlived its budget')
yield # pragma: no cover
offline = []
monkeypatch.setattr(web_server_sessions, '_mutate_offline_store',
- lambda profile, actor, params: offline.append(params) or
- {'session_id': 'session-3', 'operation': 'archive', 'revision': 0})
+ lambda profile, actor, params: offline.append(params))
monkeypatch.setattr('hermes_cli.gateway_client.connect_gateway', dying_connect)
- result = await web_server_sessions._mutate_session_request(
- request, None, 'session-3', request_id='req-3', expected_revision=0,
- operation='archive', payload={})
-
- assert result['ok'] is True
- assert len(offline) == 1
+ with pytest.raises(HTTPException) as exc:
+ await web_server_sessions._mutate_session_request(
+ request, None, 'session-3', request_id='req-3', expected_revision=0,
+ operation='archive', payload={})
+ assert exc.value.status_code == 503
+ assert exc.value.detail == 'owner_unreachable'
+ assert offline == []
@pytest.mark.asyncio