refactor(core): streamline model selector resolution#177
refactor(core): streamline model selector resolution#177SantiagoDePolonia merged 5 commits intomainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughCentralize raw request inputs into a new Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client
participant Router as Router
participant Resolver as RequestModelResolver
participant AliasSvc as AliasService
participant Upstream as UpstreamProvider
Client->>Router: HTTP request with model + providerHint
Router->>Router: build RequestedModelSelector(model, providerHint)
Router->>Resolver: ResolveModel(requested)
alt Resolver delegates to alias service
Resolver->>AliasSvc: resolveRequested(requested)
AliasSvc-->>Resolver: (resolvedSelector, changed, err)
Resolver-->>Router: (resolvedSelector, changed, err)
else Resolver absent or no alias
Resolver-->>Router: (requested.Normalize(), false, nil)
end
Router->>Upstream: forward request with resolved selector (Provider cleared / normalized)
Upstream-->>Router: response
Router-->>Client: response
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
dc7b708 to
d4f9431
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@internal/aliases/batch_preparer.go`:
- Around line 62-72: resolveAliasRequestSelector redundantly reconstructs the
RequestedModelSelector with core.NewRequestedModelSelector even though
resolveAliasModel already performs that reconstruction; remove the duplicate
core.NewRequestedModelSelector(requested.Model, requested.ProviderHint) from
resolveAliasRequestSelector and pass the original requested (or its normalized
form) into resolveAliasModel, then return either the selector (if changed) or
requested.Normalize(); update usages of resolveAliasRequestSelector only if they
relied on the double reconstruction. Ensure references: function
resolveAliasRequestSelector, resolveAliasModel, core.NewRequestedModelSelector,
RequestedModelSelector, and requested.Normalize() are adjusted accordingly.
- Around line 53-60: The function resolveAliasModel redundantly reconstructs the
selector by calling core.NewRequestedModelSelector on an argument that callers
already create; remove the reassignment "requested =
core.NewRequestedModelSelector(...)" from resolveAliasModel and let the function
use the provided core.RequestedModelSelector directly (keep the Normalize call
when service==nil). If you prefer a defensive boundary instead, replace the
reconstruction with a short comment documenting that callers must pass a
properly constructed core.RequestedModelSelector; update resolveAliasModel's
docstring accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: b3846fd0-85bf-40ad-b6df-84528eaee3b3
📒 Files selected for processing (17)
internal/aliases/batch_preparer.gointernal/aliases/provider.gointernal/aliases/provider_test.gointernal/aliases/service.gointernal/auditlog/auditlog_test.gointernal/core/batch_semantic.gointernal/core/request_model_resolution.gointernal/core/request_model_resolution_test.gointernal/core/requested_model_selector.gointernal/core/responses.gointernal/core/types.gointernal/providers/router.gointernal/server/execution_plan_helpers_test.gointernal/server/handlers_test.gointernal/server/model_validation_test.gointernal/server/native_batch_support.gointernal/server/request_model_resolution.go
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@internal/aliases/service.go`:
- Line 125: The code re-normalizes the requested selector by calling
NewRequestedModelSelector on the local variable requested even though callers
(Resolve and resolveRequestModel) already construct a normalized
RequestedModelSelector; remove the redundant call to NewRequestedModelSelector
at the top of the method (where requested =
core.NewRequestedModelSelector(requested.Model, requested.ProviderHint) appears)
so the method trusts its caller-provided RequestedModelSelector, or if you
intend idempotency, document that NewRequestedModelSelector is safe to call
multiple times in the function comment for ResolveModel/Resolve; reference the
requested variable and NewRequestedModelSelector and update
Resolve()/resolveRequestModel() callers or add inline doc accordingly.
In `@internal/server/handlers_test.go`:
- Line 1217: The test currently calls aliases.NewProviderWithOptions(inner,
service, aliases.Options{}) with an empty options struct; replace
aliases.Options{} with an explicit struct literal that lists each option field
and its intended value (matching the default behavior used in this test) so the
intent is self-documenting—update the call to
aliases.NewProviderWithOptions(inner, service,
aliases.Options{<EachOptionField>: <value>, ...}) to show the chosen flags.
🪄 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: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 2960d202-9870-4cbc-bbb3-992cdb3dae8b
📒 Files selected for processing (17)
internal/aliases/batch_preparer.gointernal/aliases/provider.gointernal/aliases/provider_test.gointernal/aliases/service.gointernal/auditlog/auditlog_test.gointernal/core/batch_semantic.gointernal/core/request_model_resolution.gointernal/core/request_model_resolution_test.gointernal/core/requested_model_selector.gointernal/core/responses.gointernal/core/types.gointernal/providers/router.gointernal/server/execution_plan_helpers_test.gointernal/server/handlers_test.gointernal/server/model_validation_test.gointernal/server/native_batch_support.gointernal/server/request_model_resolution.go
| } | ||
|
|
||
| provider := aliases.NewProvider(inner, service) | ||
| provider := aliases.NewProviderWithOptions(inner, service, aliases.Options{}) |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
Make alias-provider options explicit in this test for intent clarity.
Using aliases.Options{} works, but explicit flags make this scenario self-documenting and less ambiguous for future readers.
♻️ Optional clarity diff
-provider := aliases.NewProviderWithOptions(inner, service, aliases.Options{})
+provider := aliases.NewProviderWithOptions(inner, service, aliases.Options{
+ DisableTranslatedRequestProcessing: false,
+ DisableNativeBatchPreparation: false,
+})📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| provider := aliases.NewProviderWithOptions(inner, service, aliases.Options{}) | |
| provider := aliases.NewProviderWithOptions(inner, service, aliases.Options{ | |
| DisableTranslatedRequestProcessing: false, | |
| DisableNativeBatchPreparation: false, | |
| }) |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@internal/server/handlers_test.go` at line 1217, The test currently calls
aliases.NewProviderWithOptions(inner, service, aliases.Options{}) with an empty
options struct; replace aliases.Options{} with an explicit struct literal that
lists each option field and its intended value (matching the default behavior
used in this test) so the intent is self-documenting—update the call to
aliases.NewProviderWithOptions(inner, service,
aliases.Options{<EachOptionField>: <value>, ...}) to show the chosen flags.
Summary
provideris a gateway routing hint that is stripped before upstream executionTesting
Summary by CodeRabbit
Refactor
Documentation
Tests