Fix built-in AI provider auth config updates#13852
Conversation
📝 WalkthroughWalkthroughThis PR fixes silent configuration discards when updating built-in LLM providers by introducing configuration resolution logic that distinguishes between built-in and custom provider constraints, improving error handling for JSON parsing failures, and ensuring consistent update notifications across all provider modifications. ChangesLLM Provider Updates and Configuration Resolution
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
AI Agent Log Improvement Checklist
- The log-related comments and suggestions in this review were generated by an AI tool to assist with identifying potential improvements. Purpose of reviewing the code for log improvements is to improve the troubleshooting capabilities of our products.
- Please make sure to manually review and validate all suggestions before applying any changes. Not every code suggestion would make sense or add value to our purpose. Therefore, you have the freedom to decide which of the suggestions are helpful.
✅ Before merging this pull request:
- Review all AI-generated comments for accuracy and relevance.
- Complete and verify the table below. We need your feedback to measure the accuracy of these suggestions and the value they add. If you are rejecting a certain code suggestion, please mention the reason briefly in the suggestion for us to capture it.
There was a problem hiding this comment.
Pull request overview
This PR adjusts LLM/AI service provider update behavior so built-in providers can update only their authentication configuration (without overwriting other configuration fields), while also preventing accidental model-list clearing when model fields are omitted from update requests. It also ensures update notifications are sent for built-in provider updates so runtime components can pick up auth changes.
Changes:
- Added a configuration-resolution helper to merge only
authenticationConfigurationfor built-in providers while keeping other stored config fields unchanged. - Preserved existing model lists when
modelProviders/modelListis omitted in update requests. - Ensured update notifications are sent for built-in provider updates, and added unit tests covering auth-only updates and custom provider replacement.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/test/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/mappings/LLMProviderMappingUtilTest.java | Adds unit tests for built-in auth-only merge behavior and custom provider config replacement. |
| components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/mappings/LLMProviderMappingUtil.java | Introduces resolveProviderConfigurations(...) to enforce built-in auth-only config updates. |
| components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/LlmProvidersApiServiceImpl.java | Uses the new resolver and preserves model lists when omitted for LLM provider updates. |
| components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/AiServiceProvidersApiServiceImpl.java | Aligns AI service provider update behavior with auth-only config merge + model list preservation. |
| components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIAdminImpl.java | Sends update notifications for built-in provider updates as well. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add a JsonProcessingException catch before the general IOException in both LlmProvidersApiServiceImpl and AiServiceProvidersApiServiceImpl so that malformed configurations payloads produce an accurate log message instead of the misleading "reading the API definition file" one. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/AiServiceProvidersApiServiceImpl.java`:
- Around line 323-342: For built-in providers (isBuiltIn == true) ensure
apiDefinition and modelList are never taken from the request; always use
retrievedProvider values. In AiServiceProvidersApiServiceImpl change the logic
so provider.setApiDefinition(...) uses retrievedProvider.getApiDefinition() when
isBuiltIn is true (instead of allowing apiDefinition to override), and similarly
force provider.setModelList(...) to use retrievedProvider.getModelList() when
isBuiltIn is true; keep the existing branch for configurations
(LLMProviderMappingUtil.resolveProviderConfigurations) and description handling
so only authentication/configuration changes are applied to built-ins.
In
`@components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/LlmProvidersApiServiceImpl.java`:
- Around line 306-316: The update path allows changing apiDefinition and
modelList for built-in providers; modify LlmProvidersApiServiceImpl so when
isBuiltIn is true it always retains retrievedProvider values for these fields.
Concretely: in the block that calls provider.setApiDefinition(...) and
provider.setModelList(...), guard both assignments by isBuiltIn and use
retrievedProvider.getApiDefinition() and retrievedProvider.getModelList() for
built-ins instead of honoring the incoming apiDefinition or modelList; keep the
existing description handling and
LLMProviderMappingUtil.resolveProviderConfigurations(...) logic as-is.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: ac84b8fc-56a9-465b-92ae-e10a23dc46ae
📒 Files selected for processing (5)
components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIAdminImpl.javacomponents/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/AiServiceProvidersApiServiceImpl.javacomponents/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/LlmProvidersApiServiceImpl.javacomponents/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/mappings/LLMProviderMappingUtil.javacomponents/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/test/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/mappings/LLMProviderMappingUtilTest.java
Purpose
Allow built-in AI service providers to update only their authentication configuration while preserving the rest of the provider configuration.
Fixes: wso2/api-manager#5009
Changes
Testing
Replaces: #13851