Skip to content

builder.Build() fails to construct GatewayLlmExecutionService during DI validation because it has two public constructors that can both be resolved by the current container#46

Open
geffzhang wants to merge 4 commits intoclawdotnet:mainfrom
geffzhang:main

Conversation

@geffzhang
Copy link
Copy Markdown
Contributor

@geffzhang geffzhang commented Apr 9, 2026

Description

GatewayLlmExecutionService is now registered directly by implementation type, and the container scans all its public constructors. The source code still retains two constructor paths: one using ConfiguredModelProfileRegistry + IModelSelectionPolicy, and the other using LlmProviderRegistry. Currently, both sets of dependencies are registered in IServiceCollection, and PromptCacheCoordinator and PromptCacheWarmRegistry are also registered. As a result, both public constructors meet the resolution criteria, and the ServiceProvider cannot determine which one to choose, so it throws an AmbiguousConstructorException. The root cause is not in Program.cs, but rather that when the old and new construction methods coexist, the old backward-compatible constructor remains exposed to DI. Feasible fix: Make DI see only one constructor. Preferably change the two backward-compatible constructors based on LlmProviderRegistry to private/internal or remove them, keeping only the public constructor based on ConfiguredModelProfileRegistry + IModelSelectionPolicy.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)

Checklist

  • I have read the CONTRIBUTING guidelines
  • My code follows the code style implementation of this project
  • I have added tests that prove my fix is effective or that my feature works
  • All new and existing tests passed locally (dotnet test)
  • I have updated the documentation (README.md, comments) if required
  • I have checked for security implications (input validation, authorization)

Screenshots (if applicable)

[Add screenshots for UI/UX changes]

Benchmarks (if applicable)

[Did this change affect performance? Provide benchmark results.]

GatewayLlmExecutionService is now registered directly by implementation type, and the container scans all its public constructors. The source code still retains two constructor paths: one using ConfiguredModelProfileRegistry + IModelSelectionPolicy, and the other using LlmProviderRegistry. Currently, both sets of dependencies are registered in IServiceCollection, and PromptCacheCoordinator and PromptCacheWarmRegistry are also registered. As a result, both public constructors meet the resolution criteria, and the ServiceProvider cannot determine which one to choose, so it throws an AmbiguousConstructorException.
The root cause is not in Program.cs, but rather that when the old and new construction methods coexist, the old backward-compatible constructor remains exposed to DI.
Feasible fix: Make DI see only one constructor. Preferably change the two backward-compatible constructors based on LlmProviderRegistry to private/internal or remove them, keeping only the public constructor based on ConfiguredModelProfileRegistry + IModelSelectionPolicy.
Changes:

Added an initial handshake frame : connected\n\n uniformly to both SSE endpoints, ensuring the response starts immediately.
Extracted the SSE write logic into a private helper method to reduce duplication.
Catch and ignore OperationCanceledException when ctx.RequestAborted is triggered, preventing normal client disconnections from being treated as unhandled exceptions.
Affected endpoints:
/admin/channels/{channelId}/auth/stream
/admin/channels/whatsapp/auth/stream
@geffzhang
Copy link
Copy Markdown
Contributor Author

fix #47

Update tests to instantiate ConfiguredModelProfileRegistry and DefaultModelSelectionPolicy and pass them into GatewayLlmExecutionService (reflecting the new model-profile-based constructor), plus related using and variable adjustments across GatewayAdminEndpointTests, GatewayWorkersTests, and ModelProfileSelectionTests. Remove the custom removal of Avalonia DataAnnotations validation from App.axaml.cs (clean up/usings and keep normal initialization). Bump Avalonia package versions to 11.3.13 in the Companion project and add Tmds.DBus.Protocol (0.21.3). These changes adapt tests and the app to the updated execution API and dependency updates.
Add overloads to GatewayLlmExecutionService that accept an LlmProviderRegistry (and related simple ctor variants) and route through a new private ctor that accepts CompatibilityServices created via CreateCompatibilityServices. This centralizes compatibility service creation and simplifies DI. Update ModelProfileSelectionTests to construct and register a LlmProviderRegistry and pass it to the service (also add a Models config block), replacing the previous direct use of ConfiguredModelProfileRegistry and DefaultModelSelectionPolicy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant