fix: remove retries on connection verification (#12568)

* Remove retries on connection failures, shorten timeouts

Faster notice to user on credential failures

* set var in place

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Jordan Frazier
2026-04-08 15:59:59 -04:00
committed by GitHub
parent a93e016b42
commit 8eceae1c1f
4 changed files with 46 additions and 15 deletions

View File

@ -128,12 +128,17 @@ def set_request_context_provider_clients(*, provider_id: UUID, user_id: UUID | s
def get_authenticator(instance_url: str, api_key: str) -> IAMAuthenticator | MCSPAuthenticator:
"""Return the appropriate authenticator for the Watsonx Orchestrate API."""
if ".cloud.ibm.com" in instance_url:
return IAMAuthenticator(apikey=api_key, url=WxOAuthURL.IBM_IAM.value)
elif ".ibm.com" in instance_url: # noqa: RET505 - explicitness
return MCSPAuthenticator(apikey=api_key, url=WxOAuthURL.MCSP.value)
authenticator = IAMAuthenticator(apikey=api_key, url=WxOAuthURL.IBM_IAM.value)
elif ".ibm.com" in instance_url:
authenticator = MCSPAuthenticator(apikey=api_key, url=WxOAuthURL.MCSP.value)
else:
msg = f"Could not determine authentication scheme for instance URL: {instance_url}"
raise AuthSchemeError(message=msg)
msg = f"Could not determine authentication scheme for instance URL: {instance_url}"
raise AuthSchemeError(message=msg)
# Use a split (connect, read) timeout so that cold-start TCP/TLS handshakes
# fail fast instead of blocking for the SDK's default 60 s.
authenticator.token_manager.http_config = {"timeout": (10, 30)}
return authenticator
async def resolve_wxo_client_credentials(

View File

@ -4976,6 +4976,20 @@ def test_get_authenticator_unknown_url():
get_authenticator("https://example.com", "test-key")
def test_get_authenticator_sets_http_timeout_on_iam():
from langflow.services.adapters.deployment.watsonx_orchestrate.client import get_authenticator
auth = get_authenticator("https://api.region-foobar.cloud.ibm.com", "test-key")
assert auth.token_manager.http_config == {"timeout": (10, 30)}
def test_get_authenticator_sets_http_timeout_on_mcsp():
from langflow.services.adapters.deployment.watsonx_orchestrate.client import get_authenticator
auth = get_authenticator("https://api.wxo.ibm.com", "test-key")
assert auth.token_manager.http_config == {"timeout": (10, 30)}
def test_get_authenticator_uses_default_iam_urls_when_unset(monkeypatch):
try:
with monkeypatch.context() as context:

View File

@ -12,18 +12,22 @@ jest.mock("@/controllers/API/helpers/constants", () => ({
getURL: jest.fn(() => "/api/v1/deployments/providers"),
}));
const mockMutate = jest.fn(
// biome-ignore lint/suspicious/noExplicitAny: test mock
(_key: any, fn: any, options: any) => ({
// biome-ignore lint/suspicious/noExplicitAny: test mock
mutate: async (payload: any) => {
const result = await fn(payload);
options?.onSuccess?.(result);
options?.onSettled?.(result);
return result;
},
}),
);
jest.mock("@/controllers/API/services/request-processor", () => ({
UseRequestProcessor: jest.fn(() => ({
// biome-ignore lint/suspicious/noExplicitAny: test mock
mutate: jest.fn((_key: any, fn: any, options: any) => ({
// biome-ignore lint/suspicious/noExplicitAny: test mock
mutate: async (payload: any) => {
const result = await fn(payload);
options?.onSuccess?.(result);
options?.onSettled?.(result);
return result;
},
})),
mutate: mockMutate,
queryClient: mockQueryClient,
})),
}));
@ -76,6 +80,13 @@ describe("usePostProviderAccount", () => {
});
});
it("disables automatic retries", () => {
usePostProviderAccount();
const options = mockMutate.mock.calls[0][2];
expect(options.retry).toBe(0);
});
it("returns created provider account", async () => {
const created = {
id: "prov-1",

View File

@ -32,6 +32,7 @@ export const usePostProviderAccount: useMutationFunctionType<
return mutate(["usePostProviderAccount"], fn, {
...options,
retry: 0,
onSuccess: () => {
return queryClient.refetchQueries({
queryKey: ["useGetProviderAccounts"],