The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(gateway): call run.reissue directly in the connection card's retry
yoniebans9f9bd76b3d6b
diff --git a/gateway/local_desktop_ui.py b/gateway/local_desktop_ui.pyindex 2de0264a63a..61d738d4bb6 100644--- a/gateway/local_desktop_ui.py+++ b/gateway/local_desktop_ui.py@@ -272,7 +272,7 @@ def wire(turn, agent):agent.theme_callback = lambda payload: _theme(turn, agent, dict(payload or {}))agent.tour_callback = lambda payload: _tour(turn, agent, dict(payload or {}))agent.setup_beat_callback = lambda payload: _setup_beat(turn, agent, dict(payload or {}))- # Fire-and-forget like main's: the tool thread waits on its own operation, the card answers by op_id.+ # Fire-and-forget: the tool thread waits on its own operation; the card answers by op_id.agent.connection_callback = lambda payload: publish("connection.request", dict(payload)) and Nonereturn key, publishdiff --git a/gateway/session_connections.py b/gateway/session_connections.pyindex 0fbb422f851..efe52b4586e 100644--- a/gateway/session_connections.py+++ b/gateway/session_connections.py@@ -113,6 +113,7 @@ def _respond(operation, answer):def _retry(authority, ref, operation, request):"""The card's Try again, under the session's own context, as the sidecar ran it for its session."""+ from tools.connectors import runfrom tools.connectors.gateway.errors import GatewayAuthErrorif not request.reconnect:raise ConnectorRefusal(4000, 'INVALID_PARAMS', 'Connector parameters are invalid.')@@ -125,7 +126,7 @@ def _retry(authority, ref, operation, request):with _session_context(authority, ref):_require_connectors(authority, ref)try:- reason = _reissue(operation, request.connectors)+ reason = run.reissue(operation, request.connectors)except RuntimeStoreError:raiseexcept GatewayAuthError as exc:@@ -137,11 +138,6 @@ def _retry(authority, ref, operation, request):return _view(operation)-def _reissue(operation, names):- from tools.connectors import run- return run.reissue(operation, names)--def _auth_refusal(exc):if exc.code in {'no_access', 'ORG_ACCESS_DENIED'}:return ConnectorRefusal(4030, 'ORG_ACCESS_DENIED', 'This account cannot manage connectors for this organization.')diff --git a/tests/gateway/fixtures/tui_desktop_routes_peer.py b/tests/gateway/fixtures/tui_desktop_routes_peer.pyindex 8fc922e7f6f..458c427211b 100644--- a/tests/gateway/fixtures/tui_desktop_routes_peer.py+++ b/tests/gateway/fixtures/tui_desktop_routes_peer.py@@ -218,9 +218,8 @@ async def _connection_card(authority, ws, reader, sid, marker, receipt):"""RT-2: the manage_connections card's calls reach the session's own open operation, with the legacy handlers' policy and error shape."""from pathlib import Pathfrom tests.gateway.fixtures.local_recovery_probe import rpc- from gateway import session_connectionsfrom gateway.run import _profile_runtime_scope- from tools.connectors import live+ from tools.connectors import live, runfrom tools.connectors.contract import Actor, TargetStatefrom tools import connectorsfrom tools.connectors.gateway.errors import GatewayAuthError@@ -250,7 +249,7 @@ async def _connection_card(authority, ws, reader, sid, marker, receipt):seen.update(names=names, key=get_session_env('HERMES_SESSION_KEY'), platform=get_session_env('HERMES_SESSION_PLATFORM'))op.transition('linear', TargetState.initiated, Actor.user)- session_connections._reissue = rerun+ run.reissue = rerunretried = await rpc(ws, 'connectors.connect', owner=owner, connectors=['linear'], reconnect=True)assert retried.get('result', {}).get('targets', [{}])[0].get('state') == 'initiated', retriedassert seen == {'names': ['linear'], 'key': authority.sessions[sid].route, 'platform': 'local'}, seen@@ -258,14 +257,14 @@ async def _connection_card(authority, ws, reader, sid, marker, receipt):def auth_failure(op, names):raise GatewayAuthError('expired', code='invalid_token', status=401)- session_connections._reissue = auth_failure+ run.reissue = auth_failurerefused = await rpc(ws, 'connectors.connect', owner=owner, connectors=['linear'], reconnect=True)assert refused['error']['code'] == 4032 and refused['error']['data']['reason'] == 'NEEDS_NOUS_AUTH', refuseddef broken(op, names):raise OSError('transport down')- session_connections._reissue = broken+ run.reissue = brokenfailed = await rpc(ws, 'connectors.connect', owner=owner, connectors=['linear'], reconnect=True)assert failed['error']['code'] == 5034 and failed['error']['data']['reason'] == 'CONNECTOR_REQUEST_FAILED', failedconnectors.connectors_available = lambda *a, **k: False@@ -280,7 +279,7 @@ async def _connection_card(authority, ws, reader, sid, marker, receipt):live.open(foreign)foreign.transition('linear', TargetState.failed, Actor.backend_watcher)seen.clear()- session_connections._reissue = rerun+ run.reissue = rerununtooled = await rpc(ws, 'connectors.connect', owner={'type': 'session', 'session_id': toolless},connectors=['linear'], reconnect=True)assert untooled['error']['code'] == 4031 and seen == {}, untooled