The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): refuse a bad connection answer as an invalid answer
yoniebansb479cf8774f6
diff --git a/gateway/session_connections.py b/gateway/session_connections.pyindex 196d17ed7e2..0fbb422f851 100644--- a/gateway/session_connections.py+++ b/gateway/session_connections.py@@ -43,12 +43,22 @@ def pending_connection(authority, session_id):def _request(method, params):+ """The validated envelope and, for ``connection.respond``, the answer validated on its own as the legacy handler does: a bad answer is ``INVALID_ANSWER``, not a bad envelope."""from pydantic import ValidationError+ from tui_gateway.contracts.connectors_operation import ConnectionAnswer, ConnectionOperationParamsfrom tui_gateway.contracts.registry import METHODS as CONTRACTS+ respond = method == 'connection.respond'+ contract = ConnectionOperationParams if respond else CONTRACTS[method].paramstry:- return CONTRACTS[method].params.model_validate(params)+ request = contract.model_validate({k: v for k, v in params.items() if not (respond and k == 'result')})except ValidationError as exc:raise ConnectorRefusal(4000, 'INVALID_PARAMS', 'Connector parameters are invalid.') from exc+ if not respond:+ return request, None+ try:+ return request, ConnectionAnswer.model_validate(params.get('result'))+ except ValidationError as exc:+ raise ConnectorRefusal(4002, 'INVALID_ANSWER', 'Connection answer is invalid.') from excdef _view(operation):@@ -61,7 +71,7 @@ async def _handle(connection, method, _ref, params):from gateway.session_busy_controls import authorizefrom gateway.session_contract import SessionReffrom tools.connectors import live- request = _request(method, params)+ request, answer = _request(method, params)authority = connection.authorityref = SessionRef(authority.profile_id, request.owner.session_id)# Capability before existence, as every authority verb: a refused caller learns nothing about the id.@@ -81,7 +91,7 @@ async def _handle(connection, method, _ref, params):operation.wake.set()return {'status': 'ok'}if method == 'connection.respond':- return await asyncio.to_thread(_respond, operation, request.result)+ return await asyncio.to_thread(_respond, operation, answer)return await asyncio.to_thread(_retry, authority, ref, operation, request)