The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(dashboard): forward standalone mutations to the live gateway owner
liuhao10245ee1a9a0d2fb
diff --git a/hermes_cli/web_server_sessions.py b/hermes_cli/web_server_sessions.pyindex 386cbb38322..a8ac92ebe85 100644--- a/hermes_cli/web_server_sessions.py+++ b/hermes_cli/web_server_sessions.py@@ -185,6 +185,42 @@ def _mutate_offline_store(profile, actor, params):return _with_session_maintenance(profile, run)+async def _mutate_via_gateway_owner(profile, params):+ """Forward a standalone dashboard mutation to the live gateway owner.++ While a gateway serves the same home, a separately launched ``hermes+ 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.+ """+ 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+ from hermes_state import _default_db_path++ home = Path(_cron_profile_home(profile)[1]) if profile else Path(_default_db_path()).parent+ # Discovery is read-only and never starts a gateway; the ticket mint in+ # connect_gateway(endpoint=...) dials the endpoint's own control socket,+ # so a served profile reaches its owner, not the launch home's.+ discovery = await asyncio.to_thread(discover_gateway_endpoint, home, timeout=1.5)+ endpoint = getattr(discovery, 'endpoint', None)+ if endpoint is None:+ return None+ call = {key: params[key] for key in+ ('session_id', 'request_id', 'expected_revision', 'operation', 'payload') if key in params}+ if params.get('expected_generation') is not None:+ call['expected_generation'] = params['expected_generation']+ try:+ async with connect_gateway(endpoint=endpoint) as client:+ return await client.rpc('session.mutate', **call)+ except GatewayClientError:+ raise+ except (OSError, TimeoutError):+ return None++async def _mutate_session_request(request, profile, session_id, *, request_id,expected_revision, operation, payload, expected_generation=None):"""Resolve the authenticated principal and owner; never open a second writer."""@@ -192,6 +228,7 @@ async def _mutate_session_request(request, profile, session_id, *, request_id,from fastapi import HTTPExceptionfrom gateway.session_contract import SessionReffrom gateway.session_mutations import mutate_session+ from hermes_cli.gateway_client import GatewayClientErrorfrom hermes_state_mutation_guards import MUTATION_GUARD_REFUSALSfrom hermes_state_runtime import RuntimeStoreError@@ -213,7 +250,11 @@ async def _mutate_session_request(request, profile, session_id, *, request_id,params['expected_generation'] = expected_generationtry:if authority is None:- result = await asyncio.to_thread(_mutate_offline_store, profile, actor, params)+ # A live gateway owner answers first; only an owner-less home takes+ # the offline store (whose reservation loses to that same owner).+ result = await _mutate_via_gateway_owner(profile, params)+ if result is None:+ result = await asyncio.to_thread(_mutate_offline_store, profile, actor, params)else:with _native_history_transport(request, authority, actor):result = await mutate_session(authority, actor, SessionRef(authority.profile_id, session_id), params)@@ -222,6 +263,12 @@ async def _mutate_session_request(request, profile, session_id, *, request_id,status = {'permission_denied': 403, 'profile_mismatch': 403, 'not_found': 404,'invalid_params': 400, 'runtime_draining': 503}.get(exc.reason, 409)raise HTTPException(status_code=status, detail=exc.reason) from exc+ except GatewayClientError as exc:+ # The owner's own refusal verdicts, wire-shaped like RuntimeStoreError's+ # reasons (plus dial-time failures that read as the default 409).+ status = {'permission_denied': 403, 'profile_mismatch': 403, 'not_found': 404,+ 'invalid_params': 400, 'runtime_draining': 503}.get(str(exc), 409)+ raise HTTPException(status_code=status, detail=str(exc)) from excexcept MUTATION_GUARD_REFUSALS as exc:raise HTTPException(status_code=409, detail='session_busy') from excexcept ValueError as exc: