Skip to content

[MTP Diagnostic Analysis] IChatClientProvider.IsAvailable is never honored by provider registration or retrieval #8410

@Evangelink

Description

@Evangelink

Summary

IChatClientProvider exposes IsAvailable specifically for providers that are registered but not currently usable, but the platform never checks that property. GetChatClientAsync() always calls CreateChatClientAsync(), so an unavailable provider still fails with an exception instead of behaving as unavailable.

Evidence

  • Q:\src\testfx\src\Platform\Microsoft.Testing.Platform.AI\IChatClientProvider.cs:15-18
    • Gets a value indicating whether the provider is available and can be used.
    • A provider may be registered but not available if required configuration ... is missing.
  • Q:\src\testfx\src\Platform\Microsoft.Testing.Platform\AI\ChatClientManager.cs:28-33
    • if (_chatClientProviderFactory is not null)
    • serviceProvider.AddService(_chatClientProviderFactory(serviceProvider));
  • Q:\src\testfx\src\Platform\Microsoft.Testing.Platform.AI\ChatClientProviderExtensions.cs:37-42
    • var provider = (IChatClientProvider?)serviceProvider.GetService(typeof(IChatClientProvider));
    • : await provider.CreateChatClientAsync(cancellationToken).ConfigureAwait(false);
  • Q:\src\testfx\src\Platform\Microsoft.Testing.Extensions.AzureFoundry\OpenAIChatClientProvider.cs:21-24
    • public bool IsAvailable => ... AZURE_OPENAI_ENDPOINT ... AZURE_OPENAI_DEPLOYMENT_NAME ... AZURE_OPENAI_API_KEY
  • Q:\src\testfx\src\Platform\Microsoft.Testing.Extensions.AzureFoundry\OpenAIChatClientProvider.cs:39-51
    • missing variables cause throw new InvalidOperationException(...)

Why this is a real issue

The API contract says providers can be present but unavailable. In practice, registering such a provider changes GetChatClientAsync() from returning null (no provider) to throwing InvalidOperationException (provider present but unusable). Consumers cannot safely treat IsAvailable as the intended availability gate because the platform ignores it.

Suggested resolution

Respect IsAvailable either during provider registration or inside GetChatClientAsync(). Returning null (or a dedicated unavailable result) would make the abstraction behave as documented, while still allowing callers to inspect provider metadata separately if needed.

Related issues

  • None found

Metadata

Metadata

Labels

area/mtp-extensionsMTP extensions (TrxReport, Retry, HtmlReport, ...).type/automationCreated or maintained by an agentic workflow.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions