[ FIX ] Resolve request models for global routing policies - #3433
Open
Aakashwije wants to merge 1 commit into
Open
Aakashwije wants to merge 1 commit into
Aakashwije wants to merge 1 commit into
Conversation
Aakashwije
requested review from
AnuGayan,
Arshardh,
CrowleyRajapakse,
HeshanSudarshana,
HiranyaKavishani,
Induwara04,
Krishanx92,
PasanT9,
Piumal1999,
RakhithaRR,
Tharsanan1,
Thushani-Jayasekera,
ashera96,
chamilaadhi,
dushaniw,
hisanhunais,
lasanthaS,
malinthaprasan,
pubudu538,
renuka-fernando,
senthuran16,
tgtshanika,
tharikaGitHub,
tharindu1st and
thivindu
as code owners
September 14, 2026 10:25
Contributor
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Globally attached model-routing policies were not receiving the correct
provider-template
requestModelmapping for each API resource.An LLM provider template can define a default model location and override it for
specific resources. For example:
When an API contains only a wildcard operation such as
POST /*, the controllerpreviously created one global policy configuration using the default mapping.
Consequently, requests to
/responsescould incorrectly use$.modelinsteadof the resource-specific
$.request.model.Operation-level policies already worked because the existing operation expansion
logic materialized concrete provider-resource paths and merged the corresponding
provider-template parameters into each operation. Global policies did not have
equivalent route-specific resolution.
This affects the following globally attached policies:
cost-based-model-routingtime-based-model-routingsemantic-model-routingThe issue applies to both
LlmProviderandLlmProxyconfigurations.Resolves: N/A — no related issue link was provided.
Goals
policies.
requestModelfor every concrete route.requestModeloverrides.parameters.
requestModel.Approach
The implementation introduces two related transformation steps.
1. Materialize routes that require different model mappings
During the transformation of an
LlmProviderorLlmProxy,expandGlobalModelRoutingOperationschecks whether one of the supported policiesis globally attached.
For every existing operation, it examines the matching provider-template
resource mappings. A concrete operation is created only when that resource has a
different
requestModelfrom the operation that currently covers it.For example:
The original wildcard operation is retained. Therefore, resources without an
override continue to follow the existing route.
Existing operations are not replaced or duplicated. When a concrete operation
already exists, the expansion logic leaves it unchanged. Cloned operations also
retain their existing policies, access-control behavior, resilience
configuration, and other operation state.
Expansion is intentionally limited to:
cost-based-model-routingtime-based-model-routingsemantic-model-routingThis matches the policy-side changes in Gateway Controllers PR #303 and avoids
changing route topology for unrelated policies.
2. Resolve global policy parameters for each route
After
RestAPITransformercreates the runtime routes and policy chains,ResolveGlobalRequestModelsobtains the relevant provider template:LlmProvider, it uses the provider's configured template.LlmProxy, it resolves the referenced provider and uses thatprovider's template.
The controller then calls the existing provider-template mapping selection logic
for every concrete route. The selected
requestModelis merged into eachsupported API-level policy instance.
For example:
Only policies marked as API-level attachments are updated. Operation-level
policies are intentionally skipped because they already receive their
operation-specific provider-template parameters during the earlier
transformation stage.
The merge creates a new parameter map instead of modifying the original map in
place. API-level policy parameters are initially shared by multiple route
chains; copying them prevents the mapping selected for one route from
overwriting the mapping used by another route.
The implementation also validates that:
requestModelmapping exists for affected routes.semantic-model-routingreceives a payload-based mapping, which is the onlylocation currently supported by that policy.
Policy order, execution conditions, versions, global scope, and unrelated
parameters remain unchanged.
This change does not affect the UI.
User stories
model location defined by the selected provider template.
globally attached policies.
the correct route-specific model mapping.
between providers and proxies.
policy order, and parameters to remain unchanged.
required provider-template model mapping is missing or unsupported.
Documentation
N/A — the API Platform changes are internal gateway-controller transformation
changes and do not introduce a new user-facing configuration format.
The corresponding policy definitions and user-facing policy documentation are
updated in:
Automation tests
Unit tests
Added focused coverage in
llm_global_model_routing_test.gofor:requestModeldiffers.requestModelmappings.semantic-model-routing.The
pkg/utilsandpkg/transformtest suites passed.go vetand formatting checks passed.No standalone coverage percentage was collected for this change.
Integration tests
Added and executed end-to-end coverage for all three supported policies:
Results:
The tests verify both operation-level compatibility and global route-specific
requestModelresolution through providers and proxies.Security checks
[WSO2 Secure Engineering Guidelines](http://wso2.com/technical-reports/wso2-secure-engineering-guidelines)?
Yes
N/A — this is a Go gateway-controller change; FindSecurityBugs is not applicable
or other secrets?
Yes
Samples
N/A — no new sample format is introduced.
The integration tests contain representative provider and proxy configurations
covering operation-level and global policy attachment with default and
resource-specific provider-template mappings.
Related PRs
requestModelas a policy parameter for Cost/Time/Semantic Model RoutingThe Gateway Controllers policy changes and this API Platform controller change
must be released together. PR #303 allows the policies to receive
requestModelas a runtime policy parameter, while this PR resolves and injectsthe correct value for each route.
Test environment
go1.26.5 darwin/amd6415.7.9(24G830)29.5.3-rd29.1.3v3.23x86_64provided by the containerized test environment