The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(connectors): execute logs its checked outcome with the gateway request id
Siddharth Balyan62c37f2a037f
diff --git a/tests/tools/test_connector_wire_identity.py b/tests/tools/test_connector_wire_identity.pyindex 1d34a814bf2..65251921a2b 100644--- a/tests/tools/test_connector_wire_identity.py+++ b/tests/tools/test_connector_wire_identity.py@@ -186,19 +186,30 @@ def test_a_200_whose_body_failed_is_a_warning_with_the_request_id(caplog):from tools.connectors.gateway.errors import ToolGatewayErrorfrom tools.connectors.gateway.merge import PlannedCall+ from tools.connectors.gateway import client as client_module+failed_call = {"results": [{"error": {"code": "CONNECTION_REQUIRED", "message": "connect gmail"}}]}transport = _Transport(_Response(200, failed_call, request_id="exec-id"),- _Response(200, ValueError("not json"), request_id="junk-id"))+ _Response(200, ValueError("not json"), request_id="junk-id"),+ _Response(200, {"unexpected": True}, request_id="one-id"))client = _client(transport, call=CallRef(tool_call_id="call-3"))plan = PlannedCall(position=0, name="gmail_send_email", connector="gmail", tool="GMAIL_SEND_EMAIL", arguments={})with caplog.at_level(logging.DEBUG, logger="tools.managed_gateway_identity"):- assert client.execute([plan])[0]["error"]["code"] == "CONNECTION_REQUIRED"+ # An older gateway answers the array form: a 200 envelope with the call's failure inside.+ client_module._LEGACY_EXECUTE_ORIGINS.add("https://gw.test")+ try:+ assert client.execute([plan])[0]["error"]["code"] == "CONNECTION_REQUIRED"+ finally:+ client_module._LEGACY_EXECUTE_ORIGINS.discard("https://gw.test")with pytest.raises(ToolGatewayError) as raised:client.schemas(["X"])+ with pytest.raises(ToolGatewayError):+ client.execute([plan])assert raised.value.request_id == "junk-id" and raised.value.code == "INVALID_RESPONSE"assert _outcomes(caplog) == [(logging.WARNING, "connector connectors.execute 200 CONNECTION_REQUIRED request_id=exec-id dispatch=call-3"),(logging.WARNING, "connector connectors.schemas 200 INVALID_RESPONSE request_id=junk-id dispatch=call-3"),+ (logging.WARNING, "connector connectors.execute 200 INVALID_RESPONSE request_id=one-id dispatch=call-3"),]diff --git a/tests/tools/test_connectors_execute_status.py b/tests/tools/test_connectors_execute_status.pyindex 5fa74e91e8d..4ed6801a4de 100644--- a/tests/tools/test_connectors_execute_status.py+++ b/tests/tools/test_connectors_execute_status.py@@ -236,6 +236,15 @@ def test_an_older_gateway_gets_the_array_form_once_and_is_remembered():assert second == [{"data": "c", "error": None}]++def test_an_array_form_call_failure_logs_the_gateways_request_id(caplog):+ caplog.set_level(logging.DEBUG)+ blocked = envelope({"error": {"code": "TOOL_NOT_ALLOWED", "message": "blocked"}})+ blocked.headers = {"x-request-id": "arr_7"}+ make_client(FakeTransport(OLD_GATEWAY_400, blocked)).execute(planned())+ lines = [(r.levelno, r.getMessage()) for r in caplog.records if r.getMessage().startswith("connector connectors.execute 200")]+ assert lines == [(logging.WARNING, "connector connectors.execute 200 TOOL_NOT_ALLOWED request_id=arr_7 dispatch=-")]+def test_a_new_gateways_own_validation_error_is_not_mistaken_for_an_old_gateway():body = {"code": "VALIDATION_ERROR", "message": "call.arguments must be an object"}transport = FakeTransport(FakeResponse(400, body))diff --git a/tools/connectors/gateway/client.py b/tools/connectors/gateway/client.pyindex 09ae551f894..60b39da87db 100644--- a/tools/connectors/gateway/client.py+++ b/tools/connectors/gateway/client.py@@ -246,8 +246,8 @@ class ConnectorClient:payload = _safe_json(response)request_id = response_request_id(response)if 200 <= status < 300:- log_connector_outcome(_EXECUTE_ROUTE, status, request_id=request_id, call=self._call)- parsed = self._parse(wire.ConnectorExecuteSingleResponse, payload, "connector execute result")+ reply = _Reply(payload, status, request_id, _EXECUTE_ROUTE)+ parsed = self._checked(wire.ConnectorExecuteSingleResponse, reply, "connector execute result")entry = {"data": parsed.result.data, "error": None}if parsed.result.account:entry["account"] = parsed.result.account